Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Bug: Not able to get AzureOpenAIChat to work on Android using MAUI #6993

Open
cwbrandsdal opened this issue Jun 27, 2024 · 0 comments
Open
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@cwbrandsdal
Copy link

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.

Platform

  • OS: Windows
  • IDE: Visual Studio
  • Language: C#
  • Source: NuGet package Microsoft.SemanticKernel 1.15.0
@cwbrandsdal cwbrandsdal added the bug Something isn't working label Jun 27, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Jun 27, 2024
@github-actions github-actions bot changed the title Bug: Not able to get AzureOpenAIChat to work on Android using MAUI .Net: Bug: Not able to get AzureOpenAIChat to work on Android using MAUI Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: No status
Development

No branches or pull requests

3 participants