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

fix, FilePart, and _parsePart; #215

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions pkgs/google_generative_ai/lib/src/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'}
};
}

Expand Down