[F/OS] 🧠 Artificial Intelligence and OpenAI!

The Text Generation is not working for me...nothing is generated. My internet is turned on and I checked the API Key and everything is right but it generates nothing.
Can you pls tell me a solution ASAP as I am doing it as my final project.
Thanks

Send your AIA in PM.

Yes. I sent it. Please check.
Thanks and Regards,
Sam

This issue is resolved in PM. The user tried to input instructions with line-breakers (\n), which is currently not supported. This may be fixed in the next release, but I have schoolwork and I'm working on a contact extension.

1 Like

@Gordon_Lu Thank you sooooooo much for this!! Is there any way to download the pictures generated?

Try this extension to download the image to the ASD after the URL is returned?

1 Like

I've seen videos on YT of ChatGPT programming an iOS app with Swift in 10 minutes - really mind-blowing. I will definitely give it a try...

However, you will need some basic knowledge (Xcode / Swift).

2 Likes

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?

2 Likes

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

2 Likes

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.

2 Likes

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

PythagoreanTheoremExtension.java
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.*;
*/

@DesignerComponent(
        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) {
        super(container.$form());
    }

    @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);
    }
}
2 Likes

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

@Teddy

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();
    httpPost.setEntity(entity);

    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 {
        response.close();
    }
}

  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.setUseCaches(false);
    httpConn.setDoOutput(true); // indicates POST method
    httpConn.setDoInput(true);
    httpConn.setRequestMethod("POST");
    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");
    httpConn.setRequestProperty("Content-Disposition",
        "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);
      }
      httpConn.getOutputStream().flush();
    }
  }

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

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