Files
ArtificialIntelligence/simpleOpenAiAzureChatBot/Program.cs
2023-11-23 13:04:37 -06:00

33 lines
1.3 KiB
C#

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));
}