Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.24k stars 4.58k forks source link

[BUG]Azure OpenAI library is failed in MAUI #44174

Open vovanb opened 3 months ago

vovanb commented 3 months ago

Library name and version

Azure.AI.OpenAI 1.0.0-beta.17

Describe the bug

same code working fine in .net core console v8 and failed in MAUI application on Android

Expected behavior

should work same

Actual behavior

received exception

1.0.0-beta.17{Azure.RequestFailedException: 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:
Access-Control-Allow-Origin: REDACTED
apim-request-id: REDACTED
x-ratelimit-remaining-requests: REDACTED
Strict-Transport-Security: REDACTED
x-ratelimit-remaining-tokens: REDACTED
x-ms-rai-invoked: REDACTED
X-Request-ID: REDACTED
ms-azureml-model-error-reason: REDACTED
ms-azureml-model-error-statuscode: REDACTED
x-ms-client-request-id: 96c069a5-1230-4c5e-a3fd-f80e925e59d0
X-Content-Type-Options: REDACTED
azureml-model-session: REDACTED
x-ms-region: REDACTED
Date: Tue, 21 May 2024 16:13:58 GMT
Content-Length: 188
Content-Type: application/json

   at Azure.Core.HttpPipelineExtensions.ProcessMessageAsync(HttpPipeline pipeline, HttpMessage message, RequestContext requestContext, CancellationToken cancellationToken)
   at Azure.AI.OpenAI.OpenAIClient.GetChatCompletionsAsync(ChatCompletionsOptions chatCompletionsOptions, CancellationToken cancellationToken)
   at MauiAppTestOpenAI.MainPage.GetCompletionAsync() in 

Reproduction Steps

Same code in console application working fine and in MAUI Android is failing with exeption:

using Azure;
using Azure.AI.OpenAI;
using System.Text;
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("Staring chatGPT");

 string openAIKey = "REPLACE WITH YOUR OWN";
OpenAIClient client = new OpenAIClient(
  new Uri("https://openaiuksouthgpt4.openai.azure.com/"),
  new AzureKeyCredential(openAIKey));

Response<ChatCompletions> responseWithoutStream = await client.GetChatCompletionsAsync(

new ChatCompletionsOptions()
{
    DeploymentName = "GPT4",
    Messages =
  {

          new ChatRequestSystemMessage( @"Don't ask questions, answer very short with exact data"),
      new ChatRequestUserMessage( @"What is date today?") ,
  },
    Temperature = 1,
    MaxTokens = 250,

    NucleusSamplingFactor = 1,
    FrequencyPenalty = 0,
    PresencePenalty = 0,
});

ChatCompletions response = responseWithoutStream.Value;
string strResult = response.Choices[0].Message.Content;

Console.WriteLine("OpenAI response " + @strResult);

Environment

On Windows in Console app it is working, in MAUI Android is failing

github-actions[bot] commented 3 months ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @trrwilson.

vovanb commented 3 months ago

note same code with 1.0.0-beta.8 is working fine

DavidWynnII commented 3 months ago

I'm experience the same issue on 1.0.0-beta.17. Works for window desktop but not android. Screenshot 2024-05-28 103922

** i'm using Maui Blazor .net Core 8 with a Razor Class Library

EPinci commented 3 months ago

Having the same issue. Same exact code, calling the same deployed model: Blazor in MAUI on Android throws the above exception, Blazor in asp.net works fine. Last know good version is 1.0.0-beta.15.

await foreach (StreamingChatCompletionsUpdate chatUpdate in client.GetChatCompletionsStreaming(chatCompletionsOptions)) {
    if (chatUpdate.Role.HasValue) {
        conversation += "Assistant: ";
    }
    if (!string.IsNullOrEmpty(chatUpdate.ContentUpdate)) {
        answer += chatUpdate.ContentUpdate;
        conversation += chatUpdate.ContentUpdate;
    }
    StateHasChanged();
}
vemotion76 commented 2 months ago

Version 2.0.0-beta.1 also does not work (Android); when attempting to call CompleteChat(messages), it returns "Operation is not supported on this platform." (it works on Windows.)

vikramrajsivaram commented 2 months ago

Facing the same issue here, working in Windows, broken in Android. And I cannot go back to 1.0.0-beta.15 because it does not support me sending binary data to the sdk. image