Skip to content

Commit

Permalink
fix: Fix deserialization of sealed classes (davidmigloz#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz authored and KennethKnudsen97 committed Oct 1, 2024
1 parent d4009e8 commit 1994c64
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/chromadb/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/googleai_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/mistralai_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/ollama_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>))
.toList(growable: false));
}
if (data is String) {
return ChatCompletionUserMessageContentString(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class _CompletionPromptConverter

@override
CompletionPrompt fromJson(Object? data) {
if (data is List && data.every((item) => item is List<int>)) {
if (data is List && data.every((item) => item is List)) {
return CompletionPromptListListInt(data.cast());
}
if (data is List && data.every((item) => item is int)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class _EmbeddingInputConverter

@override
EmbeddingInput fromJson(Object? data) {
if (data is List && data.every((item) => item is List<int>)) {
if (data is List && data.every((item) => item is List)) {
return EmbeddingInputListListInt(data.cast());
}
if (data is List && data.every((item) => item is int)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, dynamic>))
.toList(growable: false));
}
if (data is String) {
return CreateMessageRequestContentString(data);
Expand Down
2 changes: 1 addition & 1 deletion packages/openai_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1994c64

Please sign in to comment.