From 7b9cf223e42eae8496f864ad7ef2f8d0dca45678 Mon Sep 17 00:00:00 2001 From: David Miguel Lozano Date: Sat, 25 May 2024 16:04:35 +0200 Subject: [PATCH] fix: Fix deserialization of sealed classes (#435) --- melos.yaml | 2 +- packages/chromadb/pubspec.yaml | 2 +- packages/googleai_dart/pubspec.yaml | 2 +- packages/mistralai_dart/pubspec.yaml | 2 +- packages/ollama_dart/pubspec.yaml | 2 +- .../lib/src/generated/schema/chat_completion_message.dart | 8 +++++--- .../src/generated/schema/create_completion_request.dart | 2 +- .../src/generated/schema/create_embedding_request.dart | 2 +- .../lib/src/generated/schema/create_message_request.dart | 6 ++++-- packages/openai_dart/pubspec.yaml | 2 +- 10 files changed, 17 insertions(+), 13 deletions(-) diff --git a/melos.yaml b/melos.yaml index 51805716..d4792fff 100644 --- a/melos.yaml +++ b/melos.yaml @@ -62,7 +62,7 @@ command: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2 scripts: diff --git a/packages/chromadb/pubspec.yaml b/packages/chromadb/pubspec.yaml index d992b91c..40252b6b 100644 --- a/packages/chromadb/pubspec.yaml +++ b/packages/chromadb/pubspec.yaml @@ -27,5 +27,5 @@ dev_dependencies: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2 diff --git a/packages/googleai_dart/pubspec.yaml b/packages/googleai_dart/pubspec.yaml index 7ccb5df6..2ed4d004 100644 --- a/packages/googleai_dart/pubspec.yaml +++ b/packages/googleai_dart/pubspec.yaml @@ -31,5 +31,5 @@ dev_dependencies: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2 diff --git a/packages/mistralai_dart/pubspec.yaml b/packages/mistralai_dart/pubspec.yaml index d4af6eaa..27b81ed4 100644 --- a/packages/mistralai_dart/pubspec.yaml +++ b/packages/mistralai_dart/pubspec.yaml @@ -30,5 +30,5 @@ dev_dependencies: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2 diff --git a/packages/ollama_dart/pubspec.yaml b/packages/ollama_dart/pubspec.yaml index c9dd9706..ab538c0d 100644 --- a/packages/ollama_dart/pubspec.yaml +++ b/packages/ollama_dart/pubspec.yaml @@ -30,5 +30,5 @@ dev_dependencies: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2 diff --git a/packages/openai_dart/lib/src/generated/schema/chat_completion_message.dart b/packages/openai_dart/lib/src/generated/schema/chat_completion_message.dart index ae4d6e9c..65e9b1d8 100644 --- a/packages/openai_dart/lib/src/generated/schema/chat_completion_message.dart +++ b/packages/openai_dart/lib/src/generated/schema/chat_completion_message.dart @@ -158,9 +158,11 @@ class _ChatCompletionUserMessageContentConverter @override ChatCompletionUserMessageContent fromJson(Object? data) { - if (data is List && - data.every((item) => item is ChatCompletionMessageContentPart)) { - return ChatCompletionMessageContentParts(data.cast()); + if (data is List && data.every((item) => item is Map)) { + return ChatCompletionMessageContentParts(data + .map((i) => ChatCompletionMessageContentPart.fromJson( + i as Map)) + .toList(growable: false)); } if (data is String) { return ChatCompletionUserMessageContentString(data); diff --git a/packages/openai_dart/lib/src/generated/schema/create_completion_request.dart b/packages/openai_dart/lib/src/generated/schema/create_completion_request.dart index 31bb714a..ff66b86c 100644 --- a/packages/openai_dart/lib/src/generated/schema/create_completion_request.dart +++ b/packages/openai_dart/lib/src/generated/schema/create_completion_request.dart @@ -347,7 +347,7 @@ class _CompletionPromptConverter @override CompletionPrompt fromJson(Object? data) { - if (data is List && data.every((item) => item is List)) { + if (data is List && data.every((item) => item is List)) { return CompletionPromptListListInt(data.cast()); } if (data is List && data.every((item) => item is int)) { diff --git a/packages/openai_dart/lib/src/generated/schema/create_embedding_request.dart b/packages/openai_dart/lib/src/generated/schema/create_embedding_request.dart index fec9f621..10c24925 100644 --- a/packages/openai_dart/lib/src/generated/schema/create_embedding_request.dart +++ b/packages/openai_dart/lib/src/generated/schema/create_embedding_request.dart @@ -179,7 +179,7 @@ class _EmbeddingInputConverter @override EmbeddingInput fromJson(Object? data) { - if (data is List && data.every((item) => item is List)) { + if (data is List && data.every((item) => item is List)) { return EmbeddingInputListListInt(data.cast()); } if (data is List && data.every((item) => item is int)) { diff --git a/packages/openai_dart/lib/src/generated/schema/create_message_request.dart b/packages/openai_dart/lib/src/generated/schema/create_message_request.dart index bad29bc1..7837049f 100644 --- a/packages/openai_dart/lib/src/generated/schema/create_message_request.dart +++ b/packages/openai_dart/lib/src/generated/schema/create_message_request.dart @@ -88,8 +88,10 @@ class _CreateMessageRequestContentConverter @override CreateMessageRequestContent fromJson(Object? data) { - if (data is List && data.every((item) => item is MessageContent)) { - return CreateMessageRequestContentListMessageContent(data.cast()); + if (data is List && data.every((item) => item is Map)) { + return CreateMessageRequestContentListMessageContent(data + .map((i) => MessageContent.fromJson(i as Map)) + .toList(growable: false)); } if (data is String) { return CreateMessageRequestContentString(data); diff --git a/packages/openai_dart/pubspec.yaml b/packages/openai_dart/pubspec.yaml index fe366c39..e34a047d 100644 --- a/packages/openai_dart/pubspec.yaml +++ b/packages/openai_dart/pubspec.yaml @@ -30,5 +30,5 @@ dev_dependencies: openapi_spec: git: url: https://github.com/davidmigloz/openapi_spec.git - ref: e14c0adaac69e9482e9b57f68fc7964032cdd44c + ref: 280ae0d41806eda25e923203d67bd6f4992a81e9 test: ^1.25.2