Вот часть моего кода. Я использовал ряд операций, связанных с завитком, для создания HTTP-запроса POST.
char *auth_header = "Authorization: Bearer " KIMI_API;
char *content_header = "Content-Type: application/json";
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, auth_header);
headers = curl_slist_append(headers, content_header);
char *data = NULL;
asprintf(&data,
"{\n"
" \"model\": \"Baichuan4\",\n"
" \"messages\": [\n"
" {\n"
" \"content\": \"巴黎奥运会中国体育代表团共获多少金牌?\",\n"
" \"role\": \"user\"\n"
" }\n"
" ],\n"
"}");
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
printf("%s \n", data);
if (curl)
{
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
res = curl_easy_perform(curl);
}
обнаружена проблема с неправильным анализом JSON, произошла ошибка.
Response:
{"error":{"code":"request_parameters_error","param":null,"type":"invalid_request_error","message":"We could not parse the JSON body of your request, expects a JSON payload, but what was sent was not valid JSON"}}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -model-api