Describe the bug
I have been trying to get the semantic kernel azure openai to work in a .net MAUI project running on android without luck. The code runs just fine when running the windows app, but it always fails on Android both in emulator and on device.
To Reproduce
Steps to reproduce the behavior:
I have set up a boilerplate .net 8 MAUI project using xaml. The only thing I have done is added the semantic kernel NuGet and pasted the following code in the MainPage.xaml.cs:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private async Task<string> SendStringToAI()
{
string openAIKey = "REDACTED";
string openAIEndpoint = "https://REDACTED.openai.azure.com/";
string engine = "gpt-4o";
try
{
AzureOpenAIChatCompletionService chatCompletionService = new (engine,openAIEndpoint, openAIKey);
var res = await chatCompletionService.GetChatMessageContentsAsync("This is just a test.");
return res.ToString();
}
catch (Exception ex)
{
string err = ex.Message;
}
return "No response";
}
private async void OnSendClicked(object sender, EventArgs e)
{
var response = await SendStringToAI();
ResponseLabel.Text = response;
}
}
This works fine on Windows, but on android I always get the following error on the call to GetChatMessageContentsAsync:
{Microsoft.SemanticKernel.HttpOperationException: Invalid value for 'content': expected a string, got null.
Status: 400 (model_error)
Content:
{
"error": {
"message": "Invalid value for 'content': expected a string, got null.",
"type": "invalid_request_error",
"param": "messages.[0].content",
"code": null
}
}
Headers:
x-ms-region: REDACTED
apim-request-id: REDACTED
x-ratelimit-remaining-requests: REDACTED
x-ms-rai-invoked: REDACTED
X-Request-ID: REDACTED
ms-azureml-model-error-reason: REDACTED
ms-azureml-model-error-statuscode: REDACTED
Strict-Transport-Security: REDACTED
azureml-model-session: REDACTED
X-Content-Type-Options: REDACTED
x-envoy-upstream-service-time: REDACTED
x-ms-client-request-id: 4359a357-f2f7-469f-911d-7e7cc3d95efc
x-ratelimit-remaining-tokens: REDACTED
Date: Thu, 27 Jun 2024 19:44:02 GMT
Content-Length: 187
Content-Type: application/json
---> Azure.RequestFailedException: Invalid value for 'content': expected a string, got null.
Status: 400 (model_error)
at Azure.Core.HttpPipelineExtensions.ProcessMessageAsync(HttpPipeline pipeline, HttpMessage message, RequestContext requestContext, CancellationToken cancellationToken)
at Azure.AI.OpenAI.OpenAIClient.GetChatCompletionsAsync(ChatCompletionsOptions chatCompletionsOptions, CancellationToken cancellationToken)
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.<RunRequestAsync>d__55`1[[Azure.Response`1[[Azure.AI.OpenAI.ChatCompletions, Azure.AI.OpenAI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8]], Azure.Core, Version=1.39.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8]].MoveNext()
--- End of inner exception stack trace ---
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.<RunRequestAsync>d__55`1[[Azure.Response`1[[Azure.AI.OpenAI.ChatCompletions, Azure.AI.OpenAI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8]], Azure.Core, Version=1.39.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8]].MoveNext()
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetChatMessageContentsAsync(ChatHistory chat, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)
at Test.MainPage.SendStringToAI() in D:\Temp\Test\MainPage.xaml.cs:line 29}
{
"error": {
"message": "Invalid value for 'content': expected a string, got null.",
"type": "invalid_request_error",
"param": "messages.[0].content",
"code": null
}
}
I have tried to set it up with DI and Kernel, but exactly the same result. Works on Windows, not on Android.
Expected behavior
I expect it to just give a simple return string.
Describe the bug I have been trying to get the semantic kernel azure openai to work in a .net MAUI project running on android without luck. The code runs just fine when running the windows app, but it always fails on Android both in emulator and on device.
To Reproduce Steps to reproduce the behavior: I have set up a boilerplate .net 8 MAUI project using xaml. The only thing I have done is added the semantic kernel NuGet and pasted the following code in the MainPage.xaml.cs:
This works fine on Windows, but on android I always get the following error on the call to GetChatMessageContentsAsync:
I have tried to set it up with DI and Kernel, but exactly the same result. Works on Windows, not on Android.
Expected behavior I expect it to just give a simple return string.
Platform