I am trying to use GPT-3 with an esp32 module.
I am using the HTTPClient.h library, and managed to successfully authenticate, but i can’t figure out how to add the model parameter to the request.
any help would be appreciated!
here is the error i am getting:
{
“error”: {
“message”: “you must provide a model parameter”,
“type”: “invalid_request_error”,
“param”: null,
“code”: null
}
}
Here is the code i am using:
#include “WiFi.h”
#include “HTTPClient.h”
#include “base64.h”
const char* ssid = “MYSSID”;
const char* password = “MYPASSWORD”;
String authUsername = “”;
String authPassword = “MY_API_KEY”;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to WiFi”);
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("https://api.openai.com/v1/completions");
String auth = base64::encode(authUsername + ":" + authPassword);
http.addHeader("Authorization", "Basic " + auth);
http.addHeader("Content-Type", "application/json");
int httpCode = http.GET();
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end();
}
delay(10000);
}