From 0b7aa2edea36a0816de104ca8f3f46b435dc38d9 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Fri, 10 May 2024 21:09:08 +0000 Subject: [PATCH] Unseal the Part class The vertex AI SDK will need new subtypes for parts which are not used on the Google AI API. For instance in vertex referring to uploaded files includes both the Uri and a mimetype, while on Google AI an uploaded file stores it's own mime type and the Part only includes the Uri. Prepare to publish to keep vertex unblocked. --- pkgs/google_generative_ai/CHANGELOG.md | 4 +++- pkgs/google_generative_ai/lib/src/content.dart | 2 +- pkgs/google_generative_ai/lib/src/version.dart | 2 +- pkgs/google_generative_ai/pubspec.yaml | 2 +- pkgs/google_generative_ai/test/utils/matchers.dart | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkgs/google_generative_ai/CHANGELOG.md b/pkgs/google_generative_ai/CHANGELOG.md index 86d834f..46dcf67 100644 --- a/pkgs/google_generative_ai/CHANGELOG.md +++ b/pkgs/google_generative_ai/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.3.4-wip +## 0.4.0 - Add support for parsing Vertex AI specific fields in `CountTokensResponse`. - Add named constructors on `Schema` for each value type. @@ -6,6 +6,8 @@ `'application/json'` to force the model to reply with JSON parseable output. - Add `outputDimensionality` argument support for `embedContent` and `batchEmbedContent`. +- **Breaking** The `Part` class is no longer `sealed`. Exhaustive switches over + a `Part` instance will need to add a wildcard case. ## 0.3.3 diff --git a/pkgs/google_generative_ai/lib/src/content.dart b/pkgs/google_generative_ai/lib/src/content.dart index f7b968b..f63af6b 100644 --- a/pkgs/google_generative_ai/lib/src/content.dart +++ b/pkgs/google_generative_ai/lib/src/content.dart @@ -80,7 +80,7 @@ Part _parsePart(Object? jsonObject) { } /// A datatype containing media that is part of a multi-part [Content] message. -sealed class Part { +abstract interface class Part { Object toJson(); } diff --git a/pkgs/google_generative_ai/lib/src/version.dart b/pkgs/google_generative_ai/lib/src/version.dart index 6b556d8..fd2a23d 100644 --- a/pkgs/google_generative_ai/lib/src/version.dart +++ b/pkgs/google_generative_ai/lib/src/version.dart @@ -12,4 +12,4 @@ // See the License for the specific language governing permissions and // limitations under the License. -const packageVersion = '0.3.4-wip'; +const packageVersion = '0.4.0-wip'; diff --git a/pkgs/google_generative_ai/pubspec.yaml b/pkgs/google_generative_ai/pubspec.yaml index d5c862b..bfc9dff 100644 --- a/pkgs/google_generative_ai/pubspec.yaml +++ b/pkgs/google_generative_ai/pubspec.yaml @@ -1,6 +1,6 @@ name: google_generative_ai # Update `lib/version.dart` when changing version. -version: 0.3.4-wip +version: 0.4.0 description: >- The Google AI Dart SDK enables developers to use Google's state-of-the-art generative AI models (like Gemini). diff --git a/pkgs/google_generative_ai/test/utils/matchers.dart b/pkgs/google_generative_ai/test/utils/matchers.dart index 0db7f97..416d68e 100644 --- a/pkgs/google_generative_ai/test/utils/matchers.dart +++ b/pkgs/google_generative_ai/test/utils/matchers.dart @@ -41,6 +41,7 @@ Matcher matchesPart(Part part) => switch (part) { // TODO: When updating min SDK remove ignore. // ignore: unused_result, implementation bug .having((p) => p.response, 'args', response), + _ => throw StateError('Unhandled Part type.'), }; Matcher matchesContent(Content content) => isA()