microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.16k stars 3.1k forks source link

Bug: iOS - Content is null - 400 error #7221

Open jerry2007 opened 1 month ago

jerry2007 commented 1 month ago

Describe the bug When I call one of method InvokePromptAsync/GetChatMessageContentsAsync/GetStreamingChatMessageContentsAsync on iOS. The error is raised.

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: 7f2d2543-dde4-45fc-87c3-934a33753cee x-ratelimit-remaining-tokens: REDACTED Date: Fri, 12 Jul 2024 07:42:46 GMT Content-Length: 187 Content-Type: application/json

To Reproduce Steps to reproduce the behavior:

  1. In Maui iOS call InvokePromptAsync/GetChatMessageContentsAsync/GetStreamingChatMessageContentsAsync
  2. See error

Expected behavior Can call these methods with no error

Platform

alliscode commented 1 month ago

Hi @jerry2007 and thanks for filing this issue. Would you be able to share a snippet of the code that replicates this issue for us?

jerry2007 commented 1 month ago

` _history.AddUserMessage(question); OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new() { ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions, Temperature = 0.2 };

var answer = ""; await foreach (var result in _chatCompletionService.GetStreamingChatMessageContentsAsync( _history, executionSettings: openAIPromptExecutionSettings, kernel: _kernel, CancellationToken.None)) { answer += result?.Content; yield return result?.Content; }`

this code crash on line with foreach....

jerry2007 commented 1 month ago

this is related:

6993

jerry2007 commented 3 weeks ago

I found out that downgrade nuget Azure.AI.OpneAI to version 1.0.0-beta.15 in semnatic kernel project Connectors.OpenAI works correctly.

https://github.com/Azure/azure-sdk-for-net/issues/44174