1515part of 'base_model.dart' ;
1616
1717const _apiUrl = 'ws/google.firebase.vertexai' ;
18- const _apiUrlSuffix = 'LlmBidiService/BidiGenerateContent/locations' ;
18+ const _apiUrlSuffixVertexAI = 'LlmBidiService/BidiGenerateContent/locations' ;
19+ const _apiUrlSuffixGoogleAI = 'GenerativeService/BidiGenerateContent' ;
1920
2021/// A live, generative AI model for real-time interaction.
2122///
@@ -32,36 +33,56 @@ final class LiveGenerativeModel extends BaseModel {
3233 {required String model,
3334 required String location,
3435 required FirebaseApp app,
36+ required bool useVertexBackend,
3537 FirebaseAppCheck ? appCheck,
3638 FirebaseAuth ? auth,
3739 LiveGenerationConfig ? liveGenerationConfig,
3840 List <Tool >? tools,
3941 Content ? systemInstruction})
4042 : _app = app,
4143 _location = location,
44+ _useVertexBackend = useVertexBackend,
4245 _appCheck = appCheck,
4346 _auth = auth,
4447 _liveGenerationConfig = liveGenerationConfig,
4548 _tools = tools,
4649 _systemInstruction = systemInstruction,
4750 super ._(
4851 serializationStrategy: VertexSerialization (),
49- modelUri: _VertexUri (
50- model: model,
51- app: app,
52- location: location,
53- ),
52+ modelUri: useVertexBackend
53+ ? _VertexUri (
54+ model: model,
55+ app: app,
56+ location: location,
57+ )
58+ : _GoogleAIUri (
59+ model: model,
60+ app: app,
61+ ),
5462 );
55- static const _apiVersion = 'v1beta' ;
5663
5764 final FirebaseApp _app;
5865 final String _location;
66+ final bool _useVertexBackend;
5967 final FirebaseAppCheck ? _appCheck;
6068 final FirebaseAuth ? _auth;
6169 final LiveGenerationConfig ? _liveGenerationConfig;
6270 final List <Tool >? _tools;
6371 final Content ? _systemInstruction;
6472
73+ String _vertexAIUri () => 'wss://${_modelUri .baseAuthority }/'
74+ '$_apiUrl .${_modelUri .apiVersion }.$_apiUrlSuffixVertexAI /'
75+ '$_location ?key=${_app .options .apiKey }' ;
76+
77+ String _vertexAIModelString () => 'projects/${_app .options .projectId }/'
78+ 'locations/$_location /publishers/google/models/${model .name }' ;
79+
80+ String _googleAIUri () => 'wss://${_modelUri .baseAuthority }/'
81+ '$_apiUrl .${_modelUri .apiVersion }.$_apiUrlSuffixGoogleAI ?key=${_app .options .apiKey }' ;
82+
83+ String _googleAIModelString () =>
84+ 'projects/${_app .options .projectId }/models/${model .name }' ;
85+
6586 /// Establishes a connection to a live generation service.
6687 ///
6788 /// This function handles the WebSocket connection setup and returns an [LiveSession]
@@ -70,11 +91,9 @@ final class LiveGenerativeModel extends BaseModel {
7091 /// Returns a [Future] that resolves to an [LiveSession] object upon successful
7192 /// connection.
7293 Future <LiveSession > connect () async {
73- final uri = 'wss://${_modelUri .baseAuthority }/'
74- '$_apiUrl .$_apiVersion .$_apiUrlSuffix /'
75- '$_location ?key=${_app .options .apiKey }' ;
76- final modelString = 'projects/${_app .options .projectId }/'
77- 'locations/$_location /publishers/google/models/${model .name }' ;
94+ final uri = _useVertexBackend ? _vertexAIUri () : _googleAIUri ();
95+ final modelString =
96+ _useVertexBackend ? _vertexAIModelString () : _googleAIModelString ();
7897
7998 final setupJson = {
8099 'setup' : {
@@ -96,6 +115,7 @@ final class LiveGenerativeModel extends BaseModel {
96115 await ws.ready;
97116
98117 ws.sink.add (request);
118+
99119 return LiveSession (ws);
100120 }
101121}
@@ -105,6 +125,7 @@ LiveGenerativeModel createLiveGenerativeModel({
105125 required FirebaseApp app,
106126 required String location,
107127 required String model,
128+ required bool useVertexBackend,
108129 FirebaseAppCheck ? appCheck,
109130 FirebaseAuth ? auth,
110131 LiveGenerationConfig ? liveGenerationConfig,
@@ -117,6 +138,7 @@ LiveGenerativeModel createLiveGenerativeModel({
117138 appCheck: appCheck,
118139 auth: auth,
119140 location: location,
141+ useVertexBackend: useVertexBackend,
120142 liveGenerationConfig: liveGenerationConfig,
121143 tools: tools,
122144 systemInstruction: systemInstruction,
0 commit comments