Сам код:
using System;
using RestSharp;
class Program
{
static void Main(string[] args)
{
// Установка параметров запроса
string prompt = "Hello, how are you today?";
string model = "text-davinci-002";
int maxTokens = 50;
// Установка заголовков запроса с API-ключом
string apiKey = "API-KEY"; //Вместо API-KEY стоит мой api ключ
string authHeader = $"Bearer {apiKey}";
// Создание HTTP-клиента и запроса к API
var client = new RestClient("https://api.openai.com/v1");
var request = new RestRequest("completions", RestSharp.Method.Post);
// Установка параметров запроса
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", authHeader);
request.AddParameter("model", model);
request.AddParameter("prompt", prompt);
request.AddParameter("max_tokens", maxTokens);
// Выполнение запроса и получение ответа
var response = client.Execute(request);
var content = response.Content;
// Вывод ответа на консоль
Console.WriteLine(content);
}
}
Ошибка:
{
"error": {
"message": "We could not parse the JSON body of your request. (HINT: This likely means you aren't using your HTTP library correctly. The OpenAI API expects a JSON payload, but what was sent was not valid JSON. If you have trouble figuring out how to fix this, please send an email to support@openai.com and include any relevant code you'd like help with.)",
"type": "invalid_request_error",
"param": null,
"code": null
}
}
Как можно решить эту ошибку?