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

[BUG] Cannot convert from json (or deserialie) ChatRequestUserMessage object with MultimodalContentItems #42503

Open
ayuina opened this issue Mar 7, 2024 · 2 comments
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.

Comments

@ayuina
Copy link

ayuina commented Mar 7, 2024

Library name and version

Azure.AI.OpenAI 1.0.0-beta.14

Describe the bug

ModelReaderWriter.Read(string) method throw the Exception. The string parameter is generated by ModelReaderWriter.Write(ChatCompletionsOptions) method, and the ChatCompletionsOptions has user message which has multi modal content.

Exception:
System.InvalidOperationException: The requested operation requires an element of type 'String', but the target element has type 'Array'.
at System.Text.Json.ThrowHelper.ThrowJsonElementWrongTypeException(JsonTokenType expectedType, JsonTokenType actualType)
at System.Text.Json.JsonDocument.GetString(Int32 index, JsonTokenType expectedType)
at Azure.AI.OpenAI.ChatRequestUserMessage.DeserializeChatRequestUserMessage(JsonElement element, ModelReaderWriterOptions options)
at Azure.AI.OpenAI.ChatRequestMessage.DeserializeChatRequestMessage(JsonElement element, ModelReaderWriterOptions options)
at Azure.AI.OpenAI.ChatCompletionsOptions.DeserializeChatCompletionsOptions(JsonElement element, ModelReaderWriterOptions options)
at Azure.AI.OpenAI.ChatCompletionsOptions.System.ClientModel.Primitives.IPersistableModel<Azure.AI.OpenAI.ChatCompletionsOptions>.Create(BinaryData data, ModelReaderWriterOptions options)
at System.ClientModel.Primitives.ModelReaderWriter.Read[T](BinaryData data, ModelReaderWriterOptions options)
at MyAoaiPlayground.BlazorServer1.Components.Pages.SendCompletion.SaveHistory() in C:\Users\ainaba\source\repos\my-aoai-playground\src\MyAoaiPlayground.BlazorServer1\Components\Pages\SendCompletion.razor:line 162

Expected behavior

I want to serialize and deserialize ChatCompletionOptions object with all parameters and messages to persistent history.

Actual behavior

ChatRequestUserMessage instance cannot deserialize from json which user role message content property as Array, which generated by MultiModalContentItems. This case occurs when using GPT4 with Vision, and ChatRequestUserMessage is constructed by IEnumerable parameter.
If content property is single String type, which generated by a constructor with single string, it can be deserialized.

Reproduction Steps

// create object
var request = new ChatCompletionOptions();
var multiModalMessage = new ChatMessageContentItem[]{
    new ChatMessageTextContentItem("user message goes here")
};
request.MessagesAdd(multiModalMessage);

//serializing object to string
var persistSring = ModelReaderWriter.Write(request).ToString();

//deserializing object from string
var loadedData = BinaryData.FromString(persistString) ;
// Exception
var obj = ModelReaderWriter.Read<ChatCompletionOptions>(loadedData);


### Environment

# Hosting platform

OS == Windows 11

dotnet --info
.NET SDK:
 Version:           8.0.200
 Commit:            438cab6a9d
 Workload version:  8.0.200-manifests.5638171e

ランタイム環境:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.200\

インストール済みの .NET ワークロード:
 [maui-windows]
   インストール ソース: VS 17.10.34607.79
   マニフェストのバージョン:    8.0.6/8.0.100
   マニフェスト パス:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.6\WorkloadManifest.json
   インストールの種類:              Msi

 [maccatalyst]
   インストール ソース: VS 17.10.34607.79
   マニフェストのバージョン:    17.2.8022/8.0.100
   マニフェスト パス:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8022\WorkloadManifest.json
   インストールの種類:              Msi

 [aspire]
   インストール ソース: VS 17.10.34607.79
   マニフェストのバージョン:    8.0.0-preview.3.24105.21/8.0.100
   マニフェスト パス:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0-preview.3.24105.21\WorkloadManifest.json
   インストールの種類:              Msi

 [android]
   インストール ソース: VS 17.10.34607.79
   マニフェストのバージョン:    34.0.79/8.0.100
   マニフェスト パス:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.79\WorkloadManifest.json
   インストールの種類:              Msi

 [ios]
   インストール ソース: VS 17.10.34607.79
   マニフェストのバージョン:    17.2.8022/8.0.100
   マニフェスト パス:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8022\WorkloadManifest.json
   インストールの種類:              Msi


Host:
  Version:      8.0.2
  Architecture: x64
  Commit:       1381d5ebd2

.NET SDKs installed:
  6.0.419 [C:\Program Files\dotnet\sdk]
  8.0.102 [C:\Program Files\dotnet\sdk]
  8.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

# IDE and version
Microsoft Visual Studio Enterprise 2022 (64 bit) - Preview
Version 17.10.0 Preview 1.0
@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-triage This issue needs the team to triage. OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 7, 2024
@ayuina
Copy link
Author

ayuina commented Mar 7, 2024

When serialize and deserialize using JsonSerializer class, it losts messages (reported #41969 ), so I am using ModelReaderWriter class. It seems succcessfully serialize all parameter like this. (but cannot deserialize)
I want to know right method to serialize/deserialize ChatCompletionsOptions object in Json format, if there are.

{
  "messages": [
    {
      "content": "あなたは Web アプリケーションのプログラマーです。\r\nユーザーから与えられた画像を読み取って、その画面を表示するための HTML と CSS を生成してください。",
      "role": "system"
    },
    {
      "content": [
        {
          "text": "aaa",
          "type": "text"
        }
      ],
      "role": "user"
    },
    {
      "content": "申し訳ありませんが、テキスト「aaa」から画像を読み取ることはできません。画像ファイルを提供していただければ、その画像を表示するための HTML と CSS コードを生成することができます。画像ファイルをアップロードしていただけますか?",
      "role": "assistant"
    }
  ],
  "max_tokens": 1000,
  "temperature": 0,
  "top_p": 0,
  "n": 1,
  "model": "gpt4v-prev"
}

@jsquire jsquire added Service Attention This issue is responsible by Azure service team. needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-team-triage This issue needs the team to triage. labels Mar 7, 2024
Copy link

github-actions bot commented Mar 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention This issue needs attention from Azure service team or SDK team OpenAI question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention This issue is responsible by Azure service team.
Projects
None yet
Development

No branches or pull requests

2 participants