Azure OpenAI API Ошибка: «Отсутствует необходимый параметр:« Контент »при отправке сообщения с вложением файлаC#

Место общения программистов C#
Anonymous
 Azure OpenAI API Ошибка: «Отсутствует необходимый параметр:« Контент »при отправке сообщения с вложением файла

Сообщение Anonymous »

Я работаю с API Azure OpenAI, чтобы загрузить файл PDF, создать поток и отправлять сообщение, содержащее загруженный файл для обобщения. Однако, когда я пытаюсь отправить сообщение, я получаю следующую ошибку: < /p>
{
"error": {
"message": "Missing required parameter: 'content'.",
"type": "invalid_request_error",
"param": "content",
"code": "missing_required_parameter"
}
}

< /code>
var messageBody = new
{
role = "user",
content = "Summarize the attached file.", // ✅ This should fulfill the 'content' requirement
attachments = new[]
{
new
{
file_id = fileId, // The uploaded file's ID from Azure OpenAI
tools = new[] { new { type = "file_search" } } // Also tried "code_interpreter"
}
}
};

// Serialize message body
var jsonMessageBody = JsonSerializer.Serialize(messageBody, new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
});

Console.WriteLine($"JSON Payload: {jsonMessageBody}");

// Prepare HTTP content
var messageContent = new StringContent(jsonMessageBody, Encoding.UTF8, "application/json");

// Send POST request to Azure OpenAI API
var response = await client.PostAsync(
$"{AzureEndpoint}/openai/threads/{threadId}/messages?api-version=2024-08-01-preview",
messageContent
);

// Read response
var messageJson = await response.Content.ReadAsStringAsync();
Console.WriteLine($"API Response: {messageJson}");

if (!response.IsSuccessStatusCode)
{
throw new Exception($"Error sending message: {response.StatusCode} - {messageJson}");
}
< /code>
Why is the API still returning "Missing required parameter: 'content'" despite the field being present in the JSON?

Подробнее здесь: https://stackoverflow.com/questions/794 ... ending-mes

Вернуться в «C#»