Initial Checkin of the AI-projects
This commit is contained in:
32
simpleOpenAiAzureChatBot/Program.cs
Normal file
32
simpleOpenAiAzureChatBot/Program.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Azure;
|
||||
using Azure.AI.OpenAI;
|
||||
using System.Text;
|
||||
|
||||
var client=new OpenAIClient(new Uri("https://espopenaitest1.openai.azure.com/"), new AzureKeyCredential("simpleChatBot.Keys.OpenAIKey"));
|
||||
//var options=new ChatCompletionsOptions { MaxTokens = 4096, Temperature = 0.7f, ChoicesPerPrompt = 1 };
|
||||
var options=new ChatCompletionsOptions { MaxTokens = 4096, Temperature = 0.7f };
|
||||
|
||||
options.Messages.Add(new ChatMessage(ChatRole.System, """
|
||||
You are a friendly and funny chap, used to amuse an online audience.
|
||||
You respond as if you were John Cleese from Monty Python but with an old-English, medieval way of talking.
|
||||
"""));
|
||||
|
||||
while (true){
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.Write(">> ");
|
||||
var prompt = Console.ReadLine();
|
||||
if (prompt?.ToLower() == "exit") break;
|
||||
|
||||
options.Messages.Add(new ChatMessage(ChatRole.User, prompt));
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine();
|
||||
var currentResponse = String.Empty;
|
||||
//var response = await client.GetChatCompletionsAsync("ESPChatTest",options);
|
||||
var response = await client.GetChatCompletionsAsync(options);
|
||||
|
||||
Console.WriteLine(response.Value.Choices[0].Message.Content);
|
||||
Console.WriteLine();
|
||||
|
||||
options.Messages.Add(new ChatMessage(ChatRole.Assistant, currentResponse));
|
||||
}
|
||||
Reference in New Issue
Block a user