ESP32 post请求 gpt
【代码】ESP32 post请求 gpt。
·
//GPT请求
String result = "";
void CHATGPT()
{
WiFiClientSecure httpsClient;
HTTPClient http;
String message = "{\"model\": \"gpt-4-0613\", \"messages\": [{\"role\": \"user\", \"content\": \"" + result + "\"}]}";
httpsClient.setInsecure();
http.begin(httpsClient,"https://newapi02.sharkchat.cn/v1/chat/completions");
http.addHeader("Content-Type", "application/json");
http.addHeader("Accept", "application/json");
http.addHeader("Authorization", "sk-VRmlEr8n5eBdEHvCA05627B27cB84b3b8a72B9C7C20d051f");
int httpResponseCode = http.POST(message);
if (httpResponseCode>0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
}
else {
Serial.print("Error on sending POST: ");
Serial.println(httpResponseCode);
}
http.end();
}
更多推荐
所有评论(0)