Describe the bug
I'm getting a "MethodNotFound" Exception when executing IChatCompletion.GetChatCompletionsAsync(). The Error:
Method not found: 'System.Threading.Tasks.Task1<Azure.Response1> Azure.AI.OpenAI.OpenAIClient.GetChatCompletionsAsync(System.String, Azure.AI.OpenAI.ChatCompletionsOptions, System.Threading.CancellationToken)'.
To Reproduce
Steps to reproduce the behavior: Starting a Blazor Project with the following setup. I put a test for AzureOpenAI chat access in (which works without issues) and below I'm trying the same with the semantic kernel approach. I just put them in the Program.cs file to keep the example short.
using GaGSemanticMap.Components;
using DotNetEnv;
using Azure.AI.OpenAI;
using Azure;
using GaGSemanticMap.Services;
using GaGSemanticMap.Skills;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AI.ChatCompletion;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
var builder = WebApplication.CreateBuilder(args);
Env.Load();
string key = Environment.GetEnvironmentVariable("KEY");
string endPoint = Environment.GetEnvironmentVariable("ENDPOINT");
string model = Environment.GetEnvironmentVariable("MODEL");
string embeddingModel = Environment.GetEnvironmentVariable("EMBEDDING");
//todo: implement a logger
//add configs
/*builder.Configuration.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", true, true)
.AddEnvironmentVariables()
.AddUserSecrets<Program>(); */
// register services
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddLogging();
builder.Logging.SetMinimumLevel(LogLevel.Warning);
//test for azure openai client
var client = new OpenAIClient(new Uri(endPoint!), new AzureKeyCredential(key));
var chatCompletionsOptions = new ChatCompletionsOptions()
{
Messages =
{
//new ChatMessage(ChatRole.System, "You are an unhelpful assistant, getting sassy when you have to answer a question"),
new Azure.AI.OpenAI.ChatMessage(ChatRole.System, "You speak like Yoda and give wise advice"),
new Azure.AI.OpenAI.ChatMessage(ChatRole.User, "this is the way!")
},
MaxTokens = 400,
DeploymentName = model
};
Response<ChatCompletions> response = await client.GetChatCompletionsAsync(chatCompletionsOptions);
var botResponse = response.Value.Choices.First().Message.Content;
//initiate kernel
var kernelBuilder = new KernelBuilder();
kernelBuilder.WithAzureOpenAIChatCompletionService(model, client);
//kernelBuilder.WithAzureOpenAITextEmbeddingGenerationService(embeddingModel, endPoint!, key);
IKernel kernel = kernelBuilder.Build();
builder.Services.AddSingleton(kernel);
//testing the kernel
var chatRequestSettings = new OpenAIRequestSettings()
{
MaxTokens = 500,
Temperature = 0.0f,
FrequencyPenalty = 0.0f,
PresencePenalty = 0.0f,
TopP = 0.0f
};
var chatCompletion = kernel.GetService<IChatCompletion>();
var prompt = "You are a helpful AI";
var chatHistory = chatCompletion.CreateNewChat(prompt);
chatHistory.AddUserMessage("Hey how are you?");
//this line throws the error
var result = chatCompletion.GetChatCompletionsAsync(chatHistory, chatRequestSettings).GetAwaiter().GetResult();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
Expected behavior
Return of the message of the configured chat.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Describe the bug I'm getting a "MethodNotFound" Exception when executing IChatCompletion.GetChatCompletionsAsync(). The Error: Method not found: 'System.Threading.Tasks.Task> Azure.AI.OpenAI.OpenAIClient.GetChatCompletionsAsync(System.String, Azure.AI.OpenAI.ChatCompletionsOptions, System.Threading.CancellationToken)'.
1<Azure.Response
1To Reproduce Steps to reproduce the behavior: Starting a Blazor Project with the following setup. I put a test for AzureOpenAI chat access in (which works without issues) and below I'm trying the same with the semantic kernel approach. I just put them in the Program.cs file to keep the example short.
Expected behavior Return of the message of the configured chat.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
ProjectInfo