[F/OS] 🧠 Artificial Intelligence and OpenAI!

Can i use VPN and use this aia in Hong Kong? Thank you!


很抱歉,我自己也是香港人。我發現如果要用 OpenAI 的服務,就要用外國的電話號碼和VPN(OpenAI並沒有允許內地和香港用 OpenAI 的服務),是一位好心人讓我借用 API 密碼。 你可以找人幫你註冊,但我相信成功率不大。


Hi, Gordon, actually, I used VPN app and sms activiate to creat the account successfully, I have the API key, but when i insert this aia file into app inventor, it says" Error, the server had an error while processing your request. Sorry about that !." May i ask how to I solve this problem. (I have tried the web chatgpt via VPN in HK successfully)

You can try refreshing the website, particularly hard-reload it using Ctrl + Shift + R?


I asked to write a small iOS music app with Swift 5.
I got perfect code. :clap:


Hmm ...
(maybe PUs are still needed after all :wink:)

1 Like

Thank you!!!

Interesting video. You can make similar mistakes in ChatGPT quite easily, as I found out, but somehow Microsoft stock stays put for the time being.


We can also request that it show extensions code...

package io.makeroid.example;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.*;

import io.makeroid.api.extension.annotation.*;
import io.makeroid.api.extension.component.*;
import io.makeroid.api.extension.util.*;

        version = 1,
        description = "An extension that solves the Pythagorean theorem.",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "images/extension.png")
@SimpleObject(external = true)
public class PythagoreanTheoremExtension extends AndroidNonvisibleComponent implements Component {

    public PythagoreanTheoremExtension(ComponentContainer container) {

    @SimpleFunction(description = "Solves the Pythagorean theorem given the length of two sides.")
    public double SolvePythagoreanTheorem(double a, double b) {
        return Math.sqrt(a*a + b*b);

Is it possible to add support for Dall-e picture 'edit' to this extension?


What is needed is a generic extension that will handle a multipart upload....

Perhaps ChatGPT can write one :wink:

I had a go (from chatGPT):

  1. Create a new Java class for your extension. You can name it anything you like, but it's best to choose a name that describes what the extension does.
  2. Define the required dependencies for your extension. You'll need to include the following libraries in your classpath:
  • Apache HttpComponents (for handling HTTP requests and responses)
  • Apache Commons IO (for reading and writing files)
  1. Define the properties and methods for your extension. In this case, you'll need a method to handle the file upload request. You can define this method as follows:
public void uploadFile(String url, String filePath) throws IOException {
    CloseableHttpClient client = HttpClients.createDefault();

    HttpPost httpPost = new HttpPost(url);
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();

    // Add the file to the request
    File file = new File(filePath);
    FileBody fileBody = new FileBody(file);
    builder.addPart("file", fileBody);

    HttpEntity entity = builder.build();

    CloseableHttpResponse response = client.execute(httpPost);
    try {
        // Handle the response
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode >= 200 && statusCode < 300) {
            // Upload successful
        } else {
            // Upload failed
    } finally {

  1. This method takes two arguments: the URL of the server endpoint that handles the file upload, and the path of the file that you want to upload. It creates a new HTTP client and sets up an HTTP POST request with a multipart body that contains the file. It then sends the request to the server and handles the response.
  2. Compile your Java class into a JAR file. You'll need to include this JAR file in your AppInventor project to use the extension.
  3. Create a new AppInventor project and import your Java extension. To do this, go to the "Projects" menu and select "Import Extension". Choose the JAR file that you created in step 4.
  4. Use your extension in your AppInventor project. You can now call the uploadFile method from your AppInventor blocks to upload a file to the server.

I then asked it to include headers:

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

public class MultipartUploader {
  private static final String LINE_FEED = "\r\n";
  private final String boundary;
  private HttpURLConnection httpConn;
  private final String charset;

  public MultipartUploader(String requestURL, String charset, Map<String, String> headers) throws IOException {
    this.charset = charset;
    boundary = "===" + System.currentTimeMillis() + "===";
    URL url = new URL(requestURL);
    httpConn = (HttpURLConnection) url.openConnection();
    httpConn.setDoOutput(true); // indicates POST method
    for (Map.Entry<String, String> entry : headers.entrySet()) {
      httpConn.setRequestProperty(entry.getKey(), entry.getValue());
    httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);

  public void addFilePart(String fieldName, File uploadFile) throws IOException {
    String fileName = uploadFile.getName();
    httpConn.setRequestProperty("Content-Type", "application/octet-stream");
        "form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"");
    try (FileInputStream inputStream = new FileInputStream(uploadFile)) {
      byte[] buffer = new byte[4096];
      int bytesRead;
      while ((bytesRead = inputStream.read(buffer)) != -1) {
        httpConn.getOutputStream().write(buffer, 0, bytesRead);

  public void addFormField(String name, String value) throws IOException {
    httpConn.setRequestProperty("Content-Type", "text/plain; charset=" + charset);
        ("--" + boundary + LINE_FEED + "Content-Disposition: form-data; name=\"" + name + "\"" + LINE_FEED
            + "Content-Type: text/plain; charset=" + charset + LINE_FEED + LINE_FEED + value + LINE_FEED)

  public int finish() throws IOException {
    httpConn.getOutputStream().write(("--" + boundary + "--" + LINE_FEED).getBytes(charset));
    int responseCode = httpConn.getResponseCode();
    return responseCode;

Answer from ChatGPT:

"Please note that using the OpenAI API is a paid service and you will need to subscribe to the appropriate plans to use the API. For more information, please visit the OpenAI website."

Is that correct?

Yes and no. When you first register, you should have a balance of $18 that you can use to test the API key for your first twelve months. If your balance runs out in this time frame, or if this time frame is over, you will have to subscribe.

1 Like

Without paying: :rofl:

Almost the same when I ask in German.

I used your test aia.


Keep in mind that I used the model Ada for this. If you want a more clever answer, switch to DaVinci, but prices increase. Check the Pricing section for more info.

1 Like

It looks nice!
If I just could turn that into working in App Inventor and make a Dall-e edit call :sweat_smile:
But my coding experience in Java and extensions are nearly not existing :innocent:

1 Like

I used Gordon Lu's extension to create an App using ChatGPT API which seems to work okay. Called "Write Like Jane Austin" available on Google Play.



Thank you for your post, but did you kind of miss the whole point of the effort to integrate the ChatGPT API into an MIT app?


Yes indeed. I overlooked the Play Store link and didn't suspect that you were advertising an app here. :upside_down_face: