Closed ESPboy-edu closed 1 year ago
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecureBearSSL.h>
#include <ChatGPT.hpp>
static const char *ssid = "SSID";
static const char *password = "PASS";
BearSSL::WiFiClientSecure client;
ChatGPT<BearSSL::WiFiClientSecure> chat_gpt(&client, "v1", "KEY");
void setup() {
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to WiFi network: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
// Ignore SSL certificate validation
client.setInsecure();
Serial.println();
}
String rslt;
String inpt;
void loop() {
Serial.println();
Serial.println();
Serial.println("Enter your question");
while (!Serial.available()) delay(300);
inpt=Serial.readString();
inpt.trim();
Serial.println(inpt);
if (chat_gpt.simple_message("gpt-3.5-turbo-0301", "user", inpt, rslt)) {
Serial.println("===OK===");
Serial.println(rslt);
} else {
Serial.println("===ERROR===");
Serial.println(rslt);
}
delay(1000);
}
@ESPboy-edu It seems that heap memory is running out when parsing with ArduinoJSON on ESP8266. It looks like you have to get the content string directly from the JSON string returned from the server without using ArduinoJSON. You can get the original string by using chat_gpt.full_message() instead of chat_gpt.simple_message(). Let me try a new way to save memory.
I'm also having this problem. When replaced with full.message I no longer get an error, but I still don't get any reply from ChatGPT
@ericTspel Which device are you using?
I'm using an adafruit feather huzzah
On Tue, Apr 25, 2023 at 5:53 PM Eric @.***> wrote:
@ericTspel https://github.com/ericTspel Which device are you using?
— Reply to this email directly, view it on GitHub https://github.com/0015/ChatGPT_Client_For_Arduino/issues/3#issuecomment-1522468110, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALDUFHH6NMAYIROPQQ244YTXDBBWLANCNFSM6AAAAAAWWY7DGA . You are receiving this because you were mentioned.Message ID: @.***>
the same problem on ESP8266
@ESPboy-edu adafruit feather huzzah is based on ESP8266. This is a problem with ESP8266.
probably not enough memory for processing Json
Using ESP8266
the most of requests are return error: "[ERR] deserializeJson() failed: InvalidInput"
Interestingly, requests of the format: "trip for N days Somewhere" is always processed without errors :)