-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e79b662
commit f5c58a0
Showing
18 changed files
with
319 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
export 'auth_flutter.dart'; | ||
export 'src/auth_flutter_api.dart' | ||
show AuthFlutter, AuthServiceFlutter, AuthSignInOptionsWeb; | ||
show | ||
AuthFlutter, | ||
AuthServiceFlutter, | ||
AuthSignInOptionsWeb, | ||
FirebaseAuthServiceFlutter, | ||
FirebaseAuthFlutter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Miscellaneous | ||
*.class | ||
*.log | ||
*.pyc | ||
*.swp | ||
.DS_Store | ||
.atom/ | ||
.buildlog/ | ||
.history | ||
.svn/ | ||
migrate_working_dir/ | ||
|
||
# IntelliJ related | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea/ | ||
|
||
# The .vscode folder contains launch configuration and tasks you configure in | ||
# VS Code which you may wish to be included in version control, so this line | ||
# is commented out by default. | ||
#.vscode/ | ||
|
||
# Flutter/Dart/Pub related | ||
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
/pubspec.lock | ||
**/doc/api/ | ||
.dart_tool/ | ||
build/ | ||
.metadata | ||
.flutter-plugins | ||
.flutter-plugins-dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# firebase_vertex_ai_flutter | ||
|
||
Flutter vertex ai | ||
|
||
## Setup | ||
|
||
In `pubspec.yaml`: | ||
```yaml | ||
tekartik_firebase_vertex_ai_flutter: | ||
git: | ||
url: https://github.com/tekartik/firebase_flutter | ||
path: vertex_ai_flutter | ||
ref: dart3a | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include: package:tekartik_lints_flutter/package.yaml | ||
|
||
# Additional information about this file can be found at | ||
# https://dart.dev/guides/language/analysis-options |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import 'package:firebase_vertexai/firebase_vertexai.dart' as fb; | ||
import 'package:tekartik_firebase_vertex_ai/vertex_ai.dart'; | ||
|
||
/// Response flutter | ||
class VaiGenerateContentResponseFlutter implements VaiGenerateContentResponse { | ||
/// Native response | ||
final fb.GenerateContentResponse nativeResponse; | ||
|
||
/// Constructor | ||
VaiGenerateContentResponseFlutter(this.nativeResponse); | ||
|
||
@override | ||
String? get text => nativeResponse.text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// See https://cloud.google.com/vertex-ai/docs/general/locations#europe | ||
|
||
/// Paris | ||
const vertexAiLocationParis = 'europe-west9'; | ||
|
||
// See https://firebase.google.com/docs/vertex-ai/gemini-models#available-model-names | ||
|
||
/// Gemini 1.5 flash | ||
const vertexAiModelGemini1dot5Flash = 'gemini-1.5-flash'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:firebase_vertexai/firebase_vertexai.dart' as fb; | ||
import 'package:tekartik_firebase/firebase_mixin.dart'; | ||
import 'package:tekartik_firebase_auth_flutter/auth_flutter.dart'; | ||
import 'package:tekartik_firebase_flutter/firebase_flutter.dart'; | ||
import 'package:tekartik_firebase_vertex_ai/vertex_ai.dart'; | ||
import 'package:tekartik_firebase_vertex_ai_flutter/src/vertex_ai_model_flutter.dart'; | ||
|
||
/// Flutter service | ||
final FirebaseVertexAiServiceFlutter firebaseVertexAiServiceFlutter = | ||
_FirebaseVertexAiServiceFlutter(); | ||
|
||
/// Flutter service interface | ||
abstract class FirebaseVertexAiServiceFlutter | ||
implements FirebaseVertexAiService { | ||
/// Optionnal auth service | ||
/// | ||
factory FirebaseVertexAiServiceFlutter( | ||
{FirebaseAuthService? authService, String? location}) { | ||
assert(authService is FirebaseAuthServiceFlutter?, | ||
'authService should be a FirebaseAuthServiceFlutter'); | ||
return _FirebaseVertexAiServiceFlutter( | ||
authServiceFlutter: authService, location: location); | ||
} | ||
} | ||
|
||
class _FirebaseVertexAiServiceFlutter | ||
with FirebaseProductServiceMixin<FirebaseVertexAi> | ||
implements FirebaseVertexAiServiceFlutter { | ||
final String? location; | ||
final FirebaseAuthService? authServiceFlutter; | ||
|
||
_FirebaseVertexAiServiceFlutter({this.authServiceFlutter, this.location}); | ||
@override | ||
FirebaseVertexAiFlutter vertexAi(App app) { | ||
return getInstance(app, () { | ||
var appFlutter = app as FirebaseAppFlutter; | ||
var nativeAuth = authServiceFlutter?.auth(app).nativeInstance; | ||
var fbVertexAi = fb.FirebaseVertexAI.instanceFor( | ||
app: appFlutter.nativeInstance!, | ||
auth: nativeAuth, | ||
location: location); | ||
return _FirebaseVertexAiFlutter(this, appFlutter, fbVertexAi); | ||
}); | ||
} | ||
} | ||
|
||
class _FirebaseVertexAiFlutter | ||
with FirebaseAppProductMixin<FirebaseVertexAi> | ||
implements FirebaseVertexAiFlutter { | ||
final FirebaseVertexAiServiceFlutter serviceFlutter; | ||
final FirebaseAppFlutter appFlutter; | ||
final fb.FirebaseVertexAI fbVertexAi; | ||
|
||
_FirebaseVertexAiFlutter( | ||
this.serviceFlutter, this.appFlutter, this.fbVertexAi); | ||
|
||
@override | ||
FirebaseApp get app => appFlutter; | ||
|
||
@override | ||
VaiGenerativeModel generativeModel({required String model}) { | ||
var nativeModel = fbVertexAi.generativeModel(model: model); | ||
return VaiGenerativeModelFlutter(this, nativeModel); | ||
} | ||
} | ||
|
||
/// Flutter service | ||
abstract class FirebaseVertexAiFlutter implements FirebaseVertexAi {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:firebase_vertexai/firebase_vertexai.dart' as fb; | ||
import 'package:tekartik_firebase_vertex_ai/vertex_ai.dart'; | ||
import 'package:tekartik_firebase_vertex_ai_flutter/src/vertex_ai_api_flutter.dart'; | ||
import 'package:tekartik_firebase_vertex_ai_flutter/src/vertex_ai_flutter.dart'; | ||
|
||
extension on Iterable<VaiContent> { | ||
Iterable<fb.Content> toNative() { | ||
return map((e) => e.toNative()); | ||
} | ||
} | ||
|
||
extension on VaiContent { | ||
fb.Content toNative() { | ||
return fb.Content(role, parts.map((e) => e.toNative()).toList()); | ||
} | ||
} | ||
|
||
extension on VaiContentPart { | ||
fb.Part toNative() { | ||
var part = this; | ||
if (part is VaiContentTextPart) { | ||
return fb.TextPart(part.text); | ||
} else if (part is VaiContentDataPart) { | ||
return fb.DataPart(part.mimeType, part.bytes); | ||
} else { | ||
throw 'Unsupported part $part (${part.runtimeType})'; | ||
} | ||
} | ||
} | ||
|
||
/// Flutter impl | ||
class VaiGenerativeModelFlutter implements VaiGenerativeModel { | ||
/// Vertex AI | ||
final FirebaseVertexAiFlutter vertexAiFlutter; | ||
|
||
/// The native instance | ||
final fb.GenerativeModel nativeInstance; | ||
|
||
/// Constructor | ||
VaiGenerativeModelFlutter(this.vertexAiFlutter, this.nativeInstance); | ||
|
||
@override | ||
Future<VaiGenerateContentResponse> generateContent( | ||
Iterable<VaiContent> prompt) async { | ||
var nativeResponse = | ||
await nativeInstance.generateContent(prompt.toNative()); | ||
return VaiGenerateContentResponseFlutter(nativeResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export 'package:tekartik_firebase_vertex_ai/vertex_ai.dart'; | ||
export 'src/vertex_ai_constant.dart'; | ||
export 'src/vertex_ai_flutter.dart' | ||
show FirebaseVertexAiServiceFlutter, FirebaseVertexAiFlutter; |
Oops, something went wrong.