From fd41eb4c30d5d369d92aa0c41499c8908b372dee Mon Sep 17 00:00:00 2001
From: "crown.hg" <crown.hg@gmail.com>
Date: Tue, 24 Sep 2024 00:30:37 +0800
Subject: [PATCH] fix, FilePart, and _parsePart; FilePart Api ref:
 https://ai.google.dev/api/caching#FileData

---
 .../google_generative_ai/lib/src/content.dart | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/pkgs/google_generative_ai/lib/src/content.dart b/pkgs/google_generative_ai/lib/src/content.dart
index cf3ca16..866728c 100644
--- a/pkgs/google_generative_ai/lib/src/content.dart
+++ b/pkgs/google_generative_ai/lib/src/content.dart
@@ -77,8 +77,20 @@ Part _parsePart(Object? jsonObject) {
       'functionResponse': {'name': String _, 'response': Map<String, Object?> _}
     } =>
       throw UnimplementedError('FunctionResponse part not yet supported'),
-    {'inlineData': {'mimeType': String _, 'data': String _}} =>
-      throw UnimplementedError('inlineData content part not yet supported'),
+    {
+      'inlineData': {
+        'mimeType': final String mimeType,
+        'data': final String data
+      }
+    } =>
+      DataPart(mimeType, base64Decode(data)),
+    {
+      'fileData': {
+        'mimeType': final String mimeType,
+        'fileUri': final String fileUri
+      }
+    } =>
+      FilePart(mimeType, Uri.parse(fileUri)),
     {
       'executableCode': {
         'language': final String language,
@@ -124,11 +136,12 @@ final class DataPart implements Part {
 ///
 /// The [uri] should refer to a file uploaded to the Google AI File Service API.
 final class FilePart implements Part {
+  final String mimeType;
   final Uri uri;
-  FilePart(this.uri);
+  FilePart(this.mimeType, this.uri);
   @override
   Object toJson() => {
-        'file_data': {'file_uri': '$uri'}
+        'fileData': {'mimeType': mimeType, 'fileUri': '$uri'}
       };
 }