#include <WiFi.
h>
#include <HTTPClient.h>
const char* ssid = "nandhu yadav";
const char* password = "nandhu56";
const char* chatgpt_token = "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";
const char* chatgpt_Q = "\"Who are you\"";
void setup() {
[Link](9600);
[Link](WIFI_STA);
[Link]();
while(!Serial);
// Wait for WiFi connection
[Link](ssid, password);
[Link]("Connecting to ");
[Link](ssid);
while ([Link]() != WL_CONNECTED) {
delay(1000);
[Link](".");
}
[Link]("connected");
[Link]("IP address: ");
[Link]([Link]());
}
void loop() {
HTTPClient https;
[Link]("[HTTPS] begin...\n");
if ([Link]("[Link] { // HTTPS
[Link]("Content-Type", "application/json");
String token_key = String("Bearer ") + chatgpt_token;
[Link]("Authorization", token_key);
String payload = String("{\"model\": \"gpt-3.5-turbo-instruct\", \"prompt\": ")
+ chatgpt_Q + String(", \"temperature\": 0, \"max_tokens\": 7}"); // JSON Payload
[Link]("[HTTPS] POST...\n");
// Start connection and send HTTP header
int httpCode = [Link](payload);
// httpCode will be negative on error
// File found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String response = [Link]();
[Link](response);
} else {
[Link]("[HTTPS] POST... failed, error: %s\n",
[Link](httpCode).c_str());
}
[Link]();
} else {
[Link]("[HTTPS] Unable to connect\n");
}
[Link]("Wait 10s before next round...");
delay(10000);