Unten ist mein Code.
Code: Select all
var payload = new
{
dataSources = new[]
{
new
{
type = "AzureCognitiveSearch",
parameters = new
{
endpoint = azureSearchEndpoint,
key = azureSearchKey,
indexName = azureSearchIndex,
top = 20,
filter = filter
}
}
},
messages = new[]
{
new
{
role = "user",
content = userMessage
}
},
max_tokens = 2980
};
// Create an HttpClient instance
using (HttpClient client = new HttpClient())
{
// Set the request headers
client.DefaultRequestHeaders.Add("api-key", oaiKey);
// Serialize the payload
string serializedPayload = JsonConvert.SerializeObject(payload);
// Create the request content
StringContent cont = new StringContent(serializedPayload, System.Text.Encoding.UTF8, "application/json");
await Task.Delay(10000);
// Make the POST request
HttpResponseMessage response = await client.PostAsync($"{oaiEndpoint}/openai/deployments/{oaiDeploymentName}/extensions/chat/completions?api-version=2023-06-01-preview", cont);
// Read the response content
string responseContent = await response.Content.ReadAsStringAsync();
JObject parsedJson = JObject.Parse(responseContent);
resContent = (string)parsedJson["choices"]?[0]?["messages"]?[1]?["content"];