Azure OpenAI client library for .NET

发布时间 2023-07-27 13:59:38作者: Mirre
using Azure;
using Azure.AI.OpenAI;

OpenAIClient client = new OpenAIClient(
	new Uri("AZURE_OPENAI_ENDPOINT"),
	new AzureKeyCredential("AZURE_OPENAI_API_KEY"));

Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync(
	"AZURE_OPENAI_ENGINE",
	new ChatCompletionsOptions()
	{
		Messages =
		{
			new ChatMessage(ChatRole.System, @""),
		},
		Temperature = (float)0.7,
		MaxTokens = 800,
		NucleusSamplingFactor = (float)0.95,
		FrequencyPenalty = 0,
		PresencePenalty = 0,
	});
ChatCompletions completions = responseWithoutStream.Value;
Console.WriteLine(completions.Choices?.FirstOrDefault()?.Message.Content);