Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the most of requests are err #3

Closed
ESPboy-edu opened this issue Apr 7, 2023 · 8 comments
Closed

the most of requests are err #3

ESPboy-edu opened this issue Apr 7, 2023 · 8 comments

Comments

@ESPboy-edu
Copy link

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 :)

@ESPboy-edu
Copy link
Author

ESPboy-edu commented Apr 7, 2023

#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);
  
}

@0015
Copy link
Owner

0015 commented Apr 12, 2023

@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.

@0015 0015 closed this as completed Apr 16, 2023
@ericTspel
Copy link

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

@0015
Copy link
Owner

0015 commented Apr 25, 2023

@ericTspel Which device are you using?

@ericTspel
Copy link

ericTspel commented Apr 25, 2023 via email

@ESPboy-edu
Copy link
Author

the same problem on ESP8266

@0015
Copy link
Owner

0015 commented Apr 26, 2023

@ESPboy-edu adafruit feather huzzah is based on ESP8266. This is a problem with ESP8266.

@ESPboy-edu
Copy link
Author

ESPboy-edu commented May 1, 2023

probably not enough memory for processing Json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants