Azure OpenAI Chat in C#:
// Install the .NET library via NuGet: dotnet add package
Azure.AI.OpenAI --version 1.0.0-beta.5
using System;
using System.Threading.Tasks;
using Azure;
using Azure.AI.OpenAI;
namespace ConsoleApp
{
internal class Program
{
static async Task Main(string[] args)
{
OpenAIClient client = new OpenAIClient(new Uri("https://xxx-xxxxxxxxx.openai.azure.com/"),
new
AzureKeyCredential("123456895a5bcef0hijklmnopqrstuvwx"));
Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync("model_deployment_name",
new
ChatCompletionsOptions()
{
Messages = {
new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information."),
new
ChatMessage(ChatRole.User, @"Summarize:
Full-stack developer with Azure Development")
},
Temperature = (float)0.7,
MaxTokens = 800,
NucleusSamplingFactor = (float)0.95,
FrequencyPenalty = 0,
PresencePenalty = 0,
});
ChatCompletions response = responseWithoutStream.Value;
Console.WriteLine(response.Choices[0].Message.Content);
Console.ReadKey();
}
}
}
internal class Program
{
static async Task Main(string[] args)
OpenAIClient client = new OpenAIClient(new Uri("https://xxx-xxxxxxxxx.openai.azure.com/"),
Messages = {
new ChatMessage(ChatRole.System, @"You are an AI assistant that helps people find information."),
Temperature = (float)0.7,
NucleusSamplingFactor = (float)0.95,
PresencePenalty = 0,
});
ChatCompletions response = responseWithoutStream.Value;
Console.WriteLine(response.Choices[0].Message.Content);
Console.ReadKey();
}
}
}
Azure OpenAI Chat in Python:
from openai import AzureOpenAI
client = AzureOpenAI(
azure_endpoint = "https://xxx-xxxxxxxxx.openai.azure.com/",
api_key = "123456895a5bcef0hijklmnopqrstuvwx",
api_version="2024-02-15-preview"
)
message_text = [
{"role":"system",
"content":"You are an AI assistant that helps people find information."},
{"role":"user","content":"Summary
\nFull-stack developer with Azure Development"}
]
completion = client.chat.completions.create(
model="model_deployment_name",
messages = message_text,
temperature=0.7,
max_tokens=800,
top_p=0.95,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
print(completion.choices[0].message.content)