@firebase/ai 1.4.0 → 1.4.1-canary.2b5731292
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ai-public.d.ts +439 -198
- package/dist/ai.d.ts +439 -198
- package/dist/esm/index.esm2017.js +181 -185
- package/dist/esm/index.esm2017.js.map +1 -1
- package/dist/esm/src/api.d.ts +2 -38
- package/dist/esm/src/errors.d.ts +1 -1
- package/dist/esm/src/public-types.d.ts +0 -18
- package/dist/esm/src/requests/schema-builder.d.ts +3 -3
- package/dist/esm/src/types/enums.d.ts +102 -60
- package/dist/esm/src/types/error.d.ts +21 -15
- package/dist/esm/src/types/imagen/requests.d.ts +53 -19
- package/dist/esm/src/types/imagen/responses.d.ts +2 -2
- package/dist/esm/src/types/requests.d.ts +68 -6
- package/dist/esm/src/types/responses.d.ts +148 -11
- package/dist/esm/src/types/schema.d.ts +31 -16
- package/dist/index.cjs.js +204 -197
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.node.cjs.js +204 -197
- package/dist/index.node.cjs.js.map +1 -1
- package/dist/index.node.mjs +181 -185
- package/dist/index.node.mjs.map +1 -1
- package/dist/src/api.d.ts +2 -38
- package/dist/src/errors.d.ts +1 -1
- package/dist/src/public-types.d.ts +0 -18
- package/dist/src/requests/schema-builder.d.ts +3 -3
- package/dist/src/types/enums.d.ts +102 -60
- package/dist/src/types/error.d.ts +21 -15
- package/dist/src/types/imagen/requests.d.ts +53 -19
- package/dist/src/types/imagen/responses.d.ts +2 -2
- package/dist/src/types/requests.d.ts +68 -6
- package/dist/src/types/responses.d.ts +148 -11
- package/dist/src/types/schema.d.ts +31 -16
- package/package.json +9 -8
|
@@ -5,7 +5,7 @@ import { Logger } from '@firebase/logger';
|
|
|
5
5
|
import { __asyncGenerator, __await } from 'tslib';
|
|
6
6
|
|
|
7
7
|
var name = "@firebase/ai";
|
|
8
|
-
var version = "1.4.
|
|
8
|
+
var version = "1.4.1-canary.2b5731292";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* @license
|
|
@@ -56,230 +56,221 @@ const POSSIBLE_ROLES = ['user', 'model', 'function', 'system'];
|
|
|
56
56
|
* Harm categories that would cause prompts or candidates to be blocked.
|
|
57
57
|
* @public
|
|
58
58
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
})(HarmCategory || (HarmCategory = {}));
|
|
59
|
+
const HarmCategory = {
|
|
60
|
+
HARM_CATEGORY_HATE_SPEECH: 'HARM_CATEGORY_HATE_SPEECH',
|
|
61
|
+
HARM_CATEGORY_SEXUALLY_EXPLICIT: 'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
|
62
|
+
HARM_CATEGORY_HARASSMENT: 'HARM_CATEGORY_HARASSMENT',
|
|
63
|
+
HARM_CATEGORY_DANGEROUS_CONTENT: 'HARM_CATEGORY_DANGEROUS_CONTENT'
|
|
64
|
+
};
|
|
66
65
|
/**
|
|
67
66
|
* Threshold above which a prompt or candidate will be blocked.
|
|
68
67
|
* @public
|
|
69
68
|
*/
|
|
70
|
-
|
|
71
|
-
(function (HarmBlockThreshold) {
|
|
69
|
+
const HarmBlockThreshold = {
|
|
72
70
|
/**
|
|
73
71
|
* Content with `NEGLIGIBLE` will be allowed.
|
|
74
72
|
*/
|
|
75
|
-
|
|
73
|
+
BLOCK_LOW_AND_ABOVE: 'BLOCK_LOW_AND_ABOVE',
|
|
76
74
|
/**
|
|
77
75
|
* Content with `NEGLIGIBLE` and `LOW` will be allowed.
|
|
78
76
|
*/
|
|
79
|
-
|
|
77
|
+
BLOCK_MEDIUM_AND_ABOVE: 'BLOCK_MEDIUM_AND_ABOVE',
|
|
80
78
|
/**
|
|
81
79
|
* Content with `NEGLIGIBLE`, `LOW`, and `MEDIUM` will be allowed.
|
|
82
80
|
*/
|
|
83
|
-
|
|
81
|
+
BLOCK_ONLY_HIGH: 'BLOCK_ONLY_HIGH',
|
|
84
82
|
/**
|
|
85
83
|
* All content will be allowed.
|
|
86
84
|
*/
|
|
87
|
-
|
|
85
|
+
BLOCK_NONE: 'BLOCK_NONE',
|
|
88
86
|
/**
|
|
89
87
|
* All content will be allowed. This is the same as `BLOCK_NONE`, but the metadata corresponding
|
|
90
88
|
* to the {@link HarmCategory} will not be present in the response.
|
|
91
89
|
*/
|
|
92
|
-
|
|
93
|
-
}
|
|
90
|
+
OFF: 'OFF'
|
|
91
|
+
};
|
|
94
92
|
/**
|
|
95
93
|
* This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
96
94
|
*
|
|
97
95
|
* @public
|
|
98
96
|
*/
|
|
99
|
-
|
|
100
|
-
(function (HarmBlockMethod) {
|
|
97
|
+
const HarmBlockMethod = {
|
|
101
98
|
/**
|
|
102
99
|
* The harm block method uses both probability and severity scores.
|
|
103
100
|
*/
|
|
104
|
-
|
|
101
|
+
SEVERITY: 'SEVERITY',
|
|
105
102
|
/**
|
|
106
103
|
* The harm block method uses the probability score.
|
|
107
104
|
*/
|
|
108
|
-
|
|
109
|
-
}
|
|
105
|
+
PROBABILITY: 'PROBABILITY'
|
|
106
|
+
};
|
|
110
107
|
/**
|
|
111
108
|
* Probability that a prompt or candidate matches a harm category.
|
|
112
109
|
* @public
|
|
113
110
|
*/
|
|
114
|
-
|
|
115
|
-
(function (HarmProbability) {
|
|
111
|
+
const HarmProbability = {
|
|
116
112
|
/**
|
|
117
113
|
* Content has a negligible chance of being unsafe.
|
|
118
114
|
*/
|
|
119
|
-
|
|
115
|
+
NEGLIGIBLE: 'NEGLIGIBLE',
|
|
120
116
|
/**
|
|
121
117
|
* Content has a low chance of being unsafe.
|
|
122
118
|
*/
|
|
123
|
-
|
|
119
|
+
LOW: 'LOW',
|
|
124
120
|
/**
|
|
125
121
|
* Content has a medium chance of being unsafe.
|
|
126
122
|
*/
|
|
127
|
-
|
|
123
|
+
MEDIUM: 'MEDIUM',
|
|
128
124
|
/**
|
|
129
125
|
* Content has a high chance of being unsafe.
|
|
130
126
|
*/
|
|
131
|
-
|
|
132
|
-
}
|
|
127
|
+
HIGH: 'HIGH'
|
|
128
|
+
};
|
|
133
129
|
/**
|
|
134
130
|
* Harm severity levels.
|
|
135
131
|
* @public
|
|
136
132
|
*/
|
|
137
|
-
|
|
138
|
-
(function (HarmSeverity) {
|
|
133
|
+
const HarmSeverity = {
|
|
139
134
|
/**
|
|
140
135
|
* Negligible level of harm severity.
|
|
141
136
|
*/
|
|
142
|
-
|
|
137
|
+
HARM_SEVERITY_NEGLIGIBLE: 'HARM_SEVERITY_NEGLIGIBLE',
|
|
143
138
|
/**
|
|
144
139
|
* Low level of harm severity.
|
|
145
140
|
*/
|
|
146
|
-
|
|
141
|
+
HARM_SEVERITY_LOW: 'HARM_SEVERITY_LOW',
|
|
147
142
|
/**
|
|
148
143
|
* Medium level of harm severity.
|
|
149
144
|
*/
|
|
150
|
-
|
|
145
|
+
HARM_SEVERITY_MEDIUM: 'HARM_SEVERITY_MEDIUM',
|
|
151
146
|
/**
|
|
152
147
|
* High level of harm severity.
|
|
153
148
|
*/
|
|
154
|
-
|
|
149
|
+
HARM_SEVERITY_HIGH: 'HARM_SEVERITY_HIGH',
|
|
155
150
|
/**
|
|
156
151
|
* Harm severity is not supported.
|
|
157
152
|
*
|
|
158
153
|
* @remarks
|
|
159
154
|
* The GoogleAI backend does not support `HarmSeverity`, so this value is used as a fallback.
|
|
160
155
|
*/
|
|
161
|
-
|
|
162
|
-
}
|
|
156
|
+
HARM_SEVERITY_UNSUPPORTED: 'HARM_SEVERITY_UNSUPPORTED'
|
|
157
|
+
};
|
|
163
158
|
/**
|
|
164
159
|
* Reason that a prompt was blocked.
|
|
165
160
|
* @public
|
|
166
161
|
*/
|
|
167
|
-
|
|
168
|
-
(function (BlockReason) {
|
|
162
|
+
const BlockReason = {
|
|
169
163
|
/**
|
|
170
164
|
* Content was blocked by safety settings.
|
|
171
165
|
*/
|
|
172
|
-
|
|
166
|
+
SAFETY: 'SAFETY',
|
|
173
167
|
/**
|
|
174
168
|
* Content was blocked, but the reason is uncategorized.
|
|
175
169
|
*/
|
|
176
|
-
|
|
170
|
+
OTHER: 'OTHER',
|
|
177
171
|
/**
|
|
178
172
|
* Content was blocked because it contained terms from the terminology blocklist.
|
|
179
173
|
*/
|
|
180
|
-
|
|
174
|
+
BLOCKLIST: 'BLOCKLIST',
|
|
181
175
|
/**
|
|
182
176
|
* Content was blocked due to prohibited content.
|
|
183
177
|
*/
|
|
184
|
-
|
|
185
|
-
}
|
|
178
|
+
PROHIBITED_CONTENT: 'PROHIBITED_CONTENT'
|
|
179
|
+
};
|
|
186
180
|
/**
|
|
187
181
|
* Reason that a candidate finished.
|
|
188
182
|
* @public
|
|
189
183
|
*/
|
|
190
|
-
|
|
191
|
-
(function (FinishReason) {
|
|
184
|
+
const FinishReason = {
|
|
192
185
|
/**
|
|
193
186
|
* Natural stop point of the model or provided stop sequence.
|
|
194
187
|
*/
|
|
195
|
-
|
|
188
|
+
STOP: 'STOP',
|
|
196
189
|
/**
|
|
197
190
|
* The maximum number of tokens as specified in the request was reached.
|
|
198
191
|
*/
|
|
199
|
-
|
|
192
|
+
MAX_TOKENS: 'MAX_TOKENS',
|
|
200
193
|
/**
|
|
201
194
|
* The candidate content was flagged for safety reasons.
|
|
202
195
|
*/
|
|
203
|
-
|
|
196
|
+
SAFETY: 'SAFETY',
|
|
204
197
|
/**
|
|
205
198
|
* The candidate content was flagged for recitation reasons.
|
|
206
199
|
*/
|
|
207
|
-
|
|
200
|
+
RECITATION: 'RECITATION',
|
|
208
201
|
/**
|
|
209
202
|
* Unknown reason.
|
|
210
203
|
*/
|
|
211
|
-
|
|
204
|
+
OTHER: 'OTHER',
|
|
212
205
|
/**
|
|
213
206
|
* The candidate content contained forbidden terms.
|
|
214
207
|
*/
|
|
215
|
-
|
|
208
|
+
BLOCKLIST: 'BLOCKLIST',
|
|
216
209
|
/**
|
|
217
210
|
* The candidate content potentially contained prohibited content.
|
|
218
211
|
*/
|
|
219
|
-
|
|
212
|
+
PROHIBITED_CONTENT: 'PROHIBITED_CONTENT',
|
|
220
213
|
/**
|
|
221
214
|
* The candidate content potentially contained Sensitive Personally Identifiable Information (SPII).
|
|
222
215
|
*/
|
|
223
|
-
|
|
216
|
+
SPII: 'SPII',
|
|
224
217
|
/**
|
|
225
218
|
* The function call generated by the model was invalid.
|
|
226
219
|
*/
|
|
227
|
-
|
|
228
|
-
}
|
|
220
|
+
MALFORMED_FUNCTION_CALL: 'MALFORMED_FUNCTION_CALL'
|
|
221
|
+
};
|
|
229
222
|
/**
|
|
230
223
|
* @public
|
|
231
224
|
*/
|
|
232
|
-
|
|
233
|
-
(function (FunctionCallingMode) {
|
|
225
|
+
const FunctionCallingMode = {
|
|
234
226
|
/**
|
|
235
227
|
* Default model behavior; model decides to predict either a function call
|
|
236
228
|
* or a natural language response.
|
|
237
229
|
*/
|
|
238
|
-
|
|
230
|
+
AUTO: 'AUTO',
|
|
239
231
|
/**
|
|
240
232
|
* Model is constrained to always predicting a function call only.
|
|
241
233
|
* If `allowed_function_names` is set, the predicted function call will be
|
|
242
234
|
* limited to any one of `allowed_function_names`, else the predicted
|
|
243
235
|
* function call will be any one of the provided `function_declarations`.
|
|
244
236
|
*/
|
|
245
|
-
|
|
237
|
+
ANY: 'ANY',
|
|
246
238
|
/**
|
|
247
239
|
* Model will not predict any function call. Model behavior is same as when
|
|
248
240
|
* not passing any function declarations.
|
|
249
241
|
*/
|
|
250
|
-
|
|
251
|
-
}
|
|
242
|
+
NONE: 'NONE'
|
|
243
|
+
};
|
|
252
244
|
/**
|
|
253
245
|
* Content part modality.
|
|
254
246
|
* @public
|
|
255
247
|
*/
|
|
256
|
-
|
|
257
|
-
(function (Modality) {
|
|
248
|
+
const Modality = {
|
|
258
249
|
/**
|
|
259
250
|
* Unspecified modality.
|
|
260
251
|
*/
|
|
261
|
-
|
|
252
|
+
MODALITY_UNSPECIFIED: 'MODALITY_UNSPECIFIED',
|
|
262
253
|
/**
|
|
263
254
|
* Plain text.
|
|
264
255
|
*/
|
|
265
|
-
|
|
256
|
+
TEXT: 'TEXT',
|
|
266
257
|
/**
|
|
267
258
|
* Image.
|
|
268
259
|
*/
|
|
269
|
-
|
|
260
|
+
IMAGE: 'IMAGE',
|
|
270
261
|
/**
|
|
271
262
|
* Video.
|
|
272
263
|
*/
|
|
273
|
-
|
|
264
|
+
VIDEO: 'VIDEO',
|
|
274
265
|
/**
|
|
275
266
|
* Audio.
|
|
276
267
|
*/
|
|
277
|
-
|
|
268
|
+
AUDIO: 'AUDIO',
|
|
278
269
|
/**
|
|
279
270
|
* Document (for example, PDF).
|
|
280
271
|
*/
|
|
281
|
-
|
|
282
|
-
}
|
|
272
|
+
DOCUMENT: 'DOCUMENT'
|
|
273
|
+
};
|
|
283
274
|
/**
|
|
284
275
|
* Generation modalities to be returned in generation responses.
|
|
285
276
|
*
|
|
@@ -298,6 +289,56 @@ const ResponseModality = {
|
|
|
298
289
|
IMAGE: 'IMAGE'
|
|
299
290
|
};
|
|
300
291
|
|
|
292
|
+
/**
|
|
293
|
+
* @license
|
|
294
|
+
* Copyright 2024 Google LLC
|
|
295
|
+
*
|
|
296
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
297
|
+
* you may not use this file except in compliance with the License.
|
|
298
|
+
* You may obtain a copy of the License at
|
|
299
|
+
*
|
|
300
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
301
|
+
*
|
|
302
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
303
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
304
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
305
|
+
* See the License for the specific language governing permissions and
|
|
306
|
+
* limitations under the License.
|
|
307
|
+
*/
|
|
308
|
+
/**
|
|
309
|
+
* Standardized error codes that {@link AIError} can have.
|
|
310
|
+
*
|
|
311
|
+
* @public
|
|
312
|
+
*/
|
|
313
|
+
const AIErrorCode = {
|
|
314
|
+
/** A generic error occurred. */
|
|
315
|
+
ERROR: 'error',
|
|
316
|
+
/** An error occurred in a request. */
|
|
317
|
+
REQUEST_ERROR: 'request-error',
|
|
318
|
+
/** An error occurred in a response. */
|
|
319
|
+
RESPONSE_ERROR: 'response-error',
|
|
320
|
+
/** An error occurred while performing a fetch. */
|
|
321
|
+
FETCH_ERROR: 'fetch-error',
|
|
322
|
+
/** An error associated with a Content object. */
|
|
323
|
+
INVALID_CONTENT: 'invalid-content',
|
|
324
|
+
/** An error due to the Firebase API not being enabled in the Console. */
|
|
325
|
+
API_NOT_ENABLED: 'api-not-enabled',
|
|
326
|
+
/** An error due to invalid Schema input. */
|
|
327
|
+
INVALID_SCHEMA: 'invalid-schema',
|
|
328
|
+
/** An error occurred due to a missing Firebase API key. */
|
|
329
|
+
NO_API_KEY: 'no-api-key',
|
|
330
|
+
/** An error occurred due to a missing Firebase app ID. */
|
|
331
|
+
NO_APP_ID: 'no-app-id',
|
|
332
|
+
/** An error occurred due to a model name not being specified during initialization. */
|
|
333
|
+
NO_MODEL: 'no-model',
|
|
334
|
+
/** An error occurred due to a missing project ID. */
|
|
335
|
+
NO_PROJECT_ID: 'no-project-id',
|
|
336
|
+
/** An error occurred while parsing. */
|
|
337
|
+
PARSE_FAILED: 'parse-failed',
|
|
338
|
+
/** An error occurred due an attempt to use an unsupported feature. */
|
|
339
|
+
UNSUPPORTED: 'unsupported'
|
|
340
|
+
};
|
|
341
|
+
|
|
301
342
|
/**
|
|
302
343
|
* @license
|
|
303
344
|
* Copyright 2024 Google LLC
|
|
@@ -320,21 +361,20 @@ const ResponseModality = {
|
|
|
320
361
|
* {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification}
|
|
321
362
|
* @public
|
|
322
363
|
*/
|
|
323
|
-
|
|
324
|
-
(function (SchemaType) {
|
|
364
|
+
const SchemaType = {
|
|
325
365
|
/** String type. */
|
|
326
|
-
|
|
366
|
+
STRING: 'string',
|
|
327
367
|
/** Number type. */
|
|
328
|
-
|
|
368
|
+
NUMBER: 'number',
|
|
329
369
|
/** Integer type. */
|
|
330
|
-
|
|
370
|
+
INTEGER: 'integer',
|
|
331
371
|
/** Boolean type. */
|
|
332
|
-
|
|
372
|
+
BOOLEAN: 'boolean',
|
|
333
373
|
/** Array type. */
|
|
334
|
-
|
|
374
|
+
ARRAY: 'array',
|
|
335
375
|
/** Object type. */
|
|
336
|
-
|
|
337
|
-
}
|
|
376
|
+
OBJECT: 'object'
|
|
377
|
+
};
|
|
338
378
|
|
|
339
379
|
/**
|
|
340
380
|
* @license
|
|
@@ -364,28 +404,27 @@ var SchemaType;
|
|
|
364
404
|
*
|
|
365
405
|
* @beta
|
|
366
406
|
*/
|
|
367
|
-
|
|
368
|
-
(function (ImagenSafetyFilterLevel) {
|
|
407
|
+
const ImagenSafetyFilterLevel = {
|
|
369
408
|
/**
|
|
370
409
|
* The most aggressive filtering level; most strict blocking.
|
|
371
410
|
*/
|
|
372
|
-
|
|
411
|
+
BLOCK_LOW_AND_ABOVE: 'block_low_and_above',
|
|
373
412
|
/**
|
|
374
413
|
* Blocks some sensitive prompts and responses.
|
|
375
414
|
*/
|
|
376
|
-
|
|
415
|
+
BLOCK_MEDIUM_AND_ABOVE: 'block_medium_and_above',
|
|
377
416
|
/**
|
|
378
417
|
* Blocks few sensitive prompts and responses.
|
|
379
418
|
*/
|
|
380
|
-
|
|
419
|
+
BLOCK_ONLY_HIGH: 'block_only_high',
|
|
381
420
|
/**
|
|
382
421
|
* The least aggressive filtering level; blocks very few sensitive prompts and responses.
|
|
383
422
|
*
|
|
384
423
|
* Access to this feature is restricted and may require your case to be reviewed and approved by
|
|
385
424
|
* Cloud support.
|
|
386
425
|
*/
|
|
387
|
-
|
|
388
|
-
}
|
|
426
|
+
BLOCK_NONE: 'block_none'
|
|
427
|
+
};
|
|
389
428
|
/**
|
|
390
429
|
* A filter level controlling whether generation of images containing people or faces is allowed.
|
|
391
430
|
*
|
|
@@ -394,12 +433,11 @@ var ImagenSafetyFilterLevel;
|
|
|
394
433
|
*
|
|
395
434
|
* @beta
|
|
396
435
|
*/
|
|
397
|
-
|
|
398
|
-
(function (ImagenPersonFilterLevel) {
|
|
436
|
+
const ImagenPersonFilterLevel = {
|
|
399
437
|
/**
|
|
400
438
|
* Disallow generation of images containing people or faces; images of people are filtered out.
|
|
401
439
|
*/
|
|
402
|
-
|
|
440
|
+
BLOCK_ALL: 'dont_allow',
|
|
403
441
|
/**
|
|
404
442
|
* Allow generation of images containing adults only; images of children are filtered out.
|
|
405
443
|
*
|
|
@@ -407,7 +445,7 @@ var ImagenPersonFilterLevel;
|
|
|
407
445
|
* reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines}
|
|
408
446
|
* for more details.
|
|
409
447
|
*/
|
|
410
|
-
|
|
448
|
+
ALLOW_ADULT: 'allow_adult',
|
|
411
449
|
/**
|
|
412
450
|
* Allow generation of images containing adults only; images of children are filtered out.
|
|
413
451
|
*
|
|
@@ -415,8 +453,8 @@ var ImagenPersonFilterLevel;
|
|
|
415
453
|
* reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines}
|
|
416
454
|
* for more details.
|
|
417
455
|
*/
|
|
418
|
-
|
|
419
|
-
}
|
|
456
|
+
ALLOW_ALL: 'allow_all'
|
|
457
|
+
};
|
|
420
458
|
/**
|
|
421
459
|
* Aspect ratios for Imagen images.
|
|
422
460
|
*
|
|
@@ -428,29 +466,28 @@ var ImagenPersonFilterLevel;
|
|
|
428
466
|
*
|
|
429
467
|
* @beta
|
|
430
468
|
*/
|
|
431
|
-
|
|
432
|
-
(function (ImagenAspectRatio) {
|
|
469
|
+
const ImagenAspectRatio = {
|
|
433
470
|
/**
|
|
434
471
|
* Square (1:1) aspect ratio.
|
|
435
472
|
*/
|
|
436
|
-
|
|
473
|
+
'SQUARE': '1:1',
|
|
437
474
|
/**
|
|
438
475
|
* Landscape (3:4) aspect ratio.
|
|
439
476
|
*/
|
|
440
|
-
|
|
477
|
+
'LANDSCAPE_3x4': '3:4',
|
|
441
478
|
/**
|
|
442
479
|
* Portrait (4:3) aspect ratio.
|
|
443
480
|
*/
|
|
444
|
-
|
|
481
|
+
'PORTRAIT_4x3': '4:3',
|
|
445
482
|
/**
|
|
446
483
|
* Landscape (16:9) aspect ratio.
|
|
447
484
|
*/
|
|
448
|
-
|
|
485
|
+
'LANDSCAPE_16x9': '16:9',
|
|
449
486
|
/**
|
|
450
487
|
* Portrait (9:16) aspect ratio.
|
|
451
488
|
*/
|
|
452
|
-
|
|
453
|
-
}
|
|
489
|
+
'PORTRAIT_9x16': '9:16'
|
|
490
|
+
};
|
|
454
491
|
|
|
455
492
|
/**
|
|
456
493
|
* @license
|
|
@@ -630,7 +667,7 @@ class AIError extends FirebaseError {
|
|
|
630
667
|
/**
|
|
631
668
|
* Constructs a new instance of the `AIError` class.
|
|
632
669
|
*
|
|
633
|
-
* @param code - The error code from {@link AIErrorCode}.
|
|
670
|
+
* @param code - The error code from {@link (AIErrorCode:type)}.
|
|
634
671
|
* @param message - A human-readable message describing the error.
|
|
635
672
|
* @param customErrorData - Optional error data.
|
|
636
673
|
*/
|
|
@@ -691,7 +728,7 @@ function encodeInstanceIdentifier(backend) {
|
|
|
691
728
|
return `${AI_TYPE}/vertexai/${backend.location}`;
|
|
692
729
|
}
|
|
693
730
|
else {
|
|
694
|
-
throw new AIError(
|
|
731
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid backend: ${JSON.stringify(backend.backendType)}`);
|
|
695
732
|
}
|
|
696
733
|
}
|
|
697
734
|
/**
|
|
@@ -702,20 +739,20 @@ function encodeInstanceIdentifier(backend) {
|
|
|
702
739
|
function decodeInstanceIdentifier(instanceIdentifier) {
|
|
703
740
|
const identifierParts = instanceIdentifier.split('/');
|
|
704
741
|
if (identifierParts[0] !== AI_TYPE) {
|
|
705
|
-
throw new AIError(
|
|
742
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown prefix '${identifierParts[0]}'`);
|
|
706
743
|
}
|
|
707
744
|
const backendType = identifierParts[1];
|
|
708
745
|
switch (backendType) {
|
|
709
746
|
case 'vertexai':
|
|
710
747
|
const location = identifierParts[2];
|
|
711
748
|
if (!location) {
|
|
712
|
-
throw new AIError(
|
|
749
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier, unknown location '${instanceIdentifier}'`);
|
|
713
750
|
}
|
|
714
751
|
return new VertexAIBackend(location);
|
|
715
752
|
case 'googleai':
|
|
716
753
|
return new GoogleAIBackend();
|
|
717
754
|
default:
|
|
718
|
-
throw new AIError(
|
|
755
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid instance identifier string: '${instanceIdentifier}'`);
|
|
719
756
|
}
|
|
720
757
|
}
|
|
721
758
|
|
|
@@ -764,13 +801,13 @@ class AIModel {
|
|
|
764
801
|
constructor(ai, modelName) {
|
|
765
802
|
var _a, _b, _c, _d, _e, _f;
|
|
766
803
|
if (!((_b = (_a = ai.app) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.apiKey)) {
|
|
767
|
-
throw new AIError(
|
|
804
|
+
throw new AIError(AIErrorCode.NO_API_KEY, `The "apiKey" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid API key.`);
|
|
768
805
|
}
|
|
769
806
|
else if (!((_d = (_c = ai.app) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.projectId)) {
|
|
770
|
-
throw new AIError(
|
|
807
|
+
throw new AIError(AIErrorCode.NO_PROJECT_ID, `The "projectId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid project ID.`);
|
|
771
808
|
}
|
|
772
809
|
else if (!((_f = (_e = ai.app) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.appId)) {
|
|
773
|
-
throw new AIError(
|
|
810
|
+
throw new AIError(AIErrorCode.NO_APP_ID, `The "appId" field is empty in the local Firebase config. Firebase AI requires this field to contain a valid app ID.`);
|
|
774
811
|
}
|
|
775
812
|
else {
|
|
776
813
|
this._apiSettings = {
|
|
@@ -911,7 +948,7 @@ class RequestUrl {
|
|
|
911
948
|
return `projects/${this.apiSettings.project}/locations/${this.apiSettings.backend.location}/${this.model}`;
|
|
912
949
|
}
|
|
913
950
|
else {
|
|
914
|
-
throw new AIError(
|
|
951
|
+
throw new AIError(AIErrorCode.ERROR, `Invalid backend: ${JSON.stringify(this.apiSettings.backend)}`);
|
|
915
952
|
}
|
|
916
953
|
}
|
|
917
954
|
get queryParams() {
|
|
@@ -996,12 +1033,13 @@ async function makeRequest(model, task, apiSettings, stream, body, requestOption
|
|
|
996
1033
|
// ignored
|
|
997
1034
|
}
|
|
998
1035
|
if (response.status === 403 &&
|
|
1036
|
+
errorDetails &&
|
|
999
1037
|
errorDetails.some((detail) => detail.reason === 'SERVICE_DISABLED') &&
|
|
1000
1038
|
errorDetails.some((detail) => {
|
|
1001
1039
|
var _a, _b;
|
|
1002
1040
|
return (_b = (_a = detail.links) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.description.includes('Google developers console API activation');
|
|
1003
1041
|
})) {
|
|
1004
|
-
throw new AIError(
|
|
1042
|
+
throw new AIError(AIErrorCode.API_NOT_ENABLED, `The Firebase AI SDK requires the Firebase AI ` +
|
|
1005
1043
|
`API ('firebasevertexai.googleapis.com') to be enabled in your ` +
|
|
1006
1044
|
`Firebase project. Enable this API by visiting the Firebase Console ` +
|
|
1007
1045
|
`at https://console.firebase.google.com/project/${url.apiSettings.project}/genai/ ` +
|
|
@@ -1013,7 +1051,7 @@ async function makeRequest(model, task, apiSettings, stream, body, requestOption
|
|
|
1013
1051
|
errorDetails
|
|
1014
1052
|
});
|
|
1015
1053
|
}
|
|
1016
|
-
throw new AIError(
|
|
1054
|
+
throw new AIError(AIErrorCode.FETCH_ERROR, `Error fetching from ${url}: [${response.status} ${response.statusText}] ${message}`, {
|
|
1017
1055
|
status: response.status,
|
|
1018
1056
|
statusText: response.statusText,
|
|
1019
1057
|
errorDetails
|
|
@@ -1022,10 +1060,10 @@ async function makeRequest(model, task, apiSettings, stream, body, requestOption
|
|
|
1022
1060
|
}
|
|
1023
1061
|
catch (e) {
|
|
1024
1062
|
let err = e;
|
|
1025
|
-
if (e.code !==
|
|
1026
|
-
e.code !==
|
|
1063
|
+
if (e.code !== AIErrorCode.FETCH_ERROR &&
|
|
1064
|
+
e.code !== AIErrorCode.API_NOT_ENABLED &&
|
|
1027
1065
|
e instanceof Error) {
|
|
1028
|
-
err = new AIError(
|
|
1066
|
+
err = new AIError(AIErrorCode.ERROR, `Error fetching from ${url.toString()}: ${e.message}`);
|
|
1029
1067
|
err.stack = e.stack;
|
|
1030
1068
|
}
|
|
1031
1069
|
throw err;
|
|
@@ -1084,14 +1122,14 @@ function addHelpers(response) {
|
|
|
1084
1122
|
`Access response.candidates directly to use the other candidates.`);
|
|
1085
1123
|
}
|
|
1086
1124
|
if (hadBadFinishReason(response.candidates[0])) {
|
|
1087
|
-
throw new AIError(
|
|
1125
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage(response)}. Response body stored in error.response`, {
|
|
1088
1126
|
response
|
|
1089
1127
|
});
|
|
1090
1128
|
}
|
|
1091
1129
|
return getText(response);
|
|
1092
1130
|
}
|
|
1093
1131
|
else if (response.promptFeedback) {
|
|
1094
|
-
throw new AIError(
|
|
1132
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Text not available. ${formatBlockErrorMessage(response)}`, {
|
|
1095
1133
|
response
|
|
1096
1134
|
});
|
|
1097
1135
|
}
|
|
@@ -1105,14 +1143,14 @@ function addHelpers(response) {
|
|
|
1105
1143
|
`Access response.candidates directly to use the other candidates.`);
|
|
1106
1144
|
}
|
|
1107
1145
|
if (hadBadFinishReason(response.candidates[0])) {
|
|
1108
|
-
throw new AIError(
|
|
1146
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage(response)}. Response body stored in error.response`, {
|
|
1109
1147
|
response
|
|
1110
1148
|
});
|
|
1111
1149
|
}
|
|
1112
1150
|
return getInlineDataParts(response);
|
|
1113
1151
|
}
|
|
1114
1152
|
else if (response.promptFeedback) {
|
|
1115
|
-
throw new AIError(
|
|
1153
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Data not available. ${formatBlockErrorMessage(response)}`, {
|
|
1116
1154
|
response
|
|
1117
1155
|
});
|
|
1118
1156
|
}
|
|
@@ -1126,14 +1164,14 @@ function addHelpers(response) {
|
|
|
1126
1164
|
`Access response.candidates directly to use the other candidates.`);
|
|
1127
1165
|
}
|
|
1128
1166
|
if (hadBadFinishReason(response.candidates[0])) {
|
|
1129
|
-
throw new AIError(
|
|
1167
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Response error: ${formatBlockErrorMessage(response)}. Response body stored in error.response`, {
|
|
1130
1168
|
response
|
|
1131
1169
|
});
|
|
1132
1170
|
}
|
|
1133
1171
|
return getFunctionCalls(response);
|
|
1134
1172
|
}
|
|
1135
1173
|
else if (response.promptFeedback) {
|
|
1136
|
-
throw new AIError(
|
|
1174
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Function call not available. ${formatBlockErrorMessage(response)}`, {
|
|
1137
1175
|
response
|
|
1138
1176
|
});
|
|
1139
1177
|
}
|
|
@@ -1206,7 +1244,7 @@ function getInlineDataParts(response) {
|
|
|
1206
1244
|
const badFinishReasons = [FinishReason.RECITATION, FinishReason.SAFETY];
|
|
1207
1245
|
function hadBadFinishReason(candidate) {
|
|
1208
1246
|
return (!!candidate.finishReason &&
|
|
1209
|
-
badFinishReasons.
|
|
1247
|
+
badFinishReasons.some(reason => reason === candidate.finishReason));
|
|
1210
1248
|
}
|
|
1211
1249
|
function formatBlockErrorMessage(response) {
|
|
1212
1250
|
var _a, _b, _c;
|
|
@@ -1246,7 +1284,7 @@ async function handlePredictResponse(response) {
|
|
|
1246
1284
|
let filteredReason = undefined;
|
|
1247
1285
|
// The backend should always send a non-empty array of predictions if the response was successful.
|
|
1248
1286
|
if (!responseJson.predictions || ((_a = responseJson.predictions) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
1249
|
-
throw new AIError(
|
|
1287
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, 'No predictions or filtered reason received from Vertex AI. Please report this issue with the full error details at https://github.com/firebase/firebase-js-sdk/issues.');
|
|
1250
1288
|
}
|
|
1251
1289
|
for (const prediction of responseJson.predictions) {
|
|
1252
1290
|
if (prediction.raiFilteredReason) {
|
|
@@ -1265,7 +1303,7 @@ async function handlePredictResponse(response) {
|
|
|
1265
1303
|
});
|
|
1266
1304
|
}
|
|
1267
1305
|
else {
|
|
1268
|
-
throw new AIError(
|
|
1306
|
+
throw new AIError(AIErrorCode.RESPONSE_ERROR, `Predictions array in response has missing properties. Response: ${JSON.stringify(responseJson)}`);
|
|
1269
1307
|
}
|
|
1270
1308
|
}
|
|
1271
1309
|
return { images, filteredReason };
|
|
@@ -1312,7 +1350,7 @@ function mapGenerateContentRequest(generateContentRequest) {
|
|
|
1312
1350
|
var _a, _b;
|
|
1313
1351
|
(_a = generateContentRequest.safetySettings) === null || _a === void 0 ? void 0 : _a.forEach(safetySetting => {
|
|
1314
1352
|
if (safetySetting.method) {
|
|
1315
|
-
throw new AIError(
|
|
1353
|
+
throw new AIError(AIErrorCode.UNSUPPORTED, 'SafetySetting.method is not supported in the the Gemini Developer API. Please remove this property.');
|
|
1316
1354
|
}
|
|
1317
1355
|
});
|
|
1318
1356
|
if ((_b = generateContentRequest.generationConfig) === null || _b === void 0 ? void 0 : _b.topK) {
|
|
@@ -1395,7 +1433,7 @@ function mapGenerateContentCandidates(candidates) {
|
|
|
1395
1433
|
// Throw early since developers may send a long video as input and only expect to pay
|
|
1396
1434
|
// for inference on a small portion of the video.
|
|
1397
1435
|
if ((_a = candidate.content) === null || _a === void 0 ? void 0 : _a.parts.some(part => part === null || part === void 0 ? void 0 : part.videoMetadata)) {
|
|
1398
|
-
throw new AIError(
|
|
1436
|
+
throw new AIError(AIErrorCode.UNSUPPORTED, 'Part.videoMetadata is not supported in the Gemini Developer API. Please remove this property.');
|
|
1399
1437
|
}
|
|
1400
1438
|
const mappedCandidate = {
|
|
1401
1439
|
index: candidate.index,
|
|
@@ -1516,7 +1554,7 @@ function getResponseStream(inputStream) {
|
|
|
1516
1554
|
return reader.read().then(({ value, done }) => {
|
|
1517
1555
|
if (done) {
|
|
1518
1556
|
if (currentText.trim()) {
|
|
1519
|
-
controller.error(new AIError(
|
|
1557
|
+
controller.error(new AIError(AIErrorCode.PARSE_FAILED, 'Failed to parse stream'));
|
|
1520
1558
|
return;
|
|
1521
1559
|
}
|
|
1522
1560
|
controller.close();
|
|
@@ -1530,7 +1568,7 @@ function getResponseStream(inputStream) {
|
|
|
1530
1568
|
parsedResponse = JSON.parse(match[1]);
|
|
1531
1569
|
}
|
|
1532
1570
|
catch (e) {
|
|
1533
|
-
controller.error(new AIError(
|
|
1571
|
+
controller.error(new AIError(AIErrorCode.PARSE_FAILED, `Error parsing JSON response: "${match[1]}`));
|
|
1534
1572
|
return;
|
|
1535
1573
|
}
|
|
1536
1574
|
controller.enqueue(parsedResponse);
|
|
@@ -1575,6 +1613,8 @@ function aggregateResponses(responses) {
|
|
|
1575
1613
|
candidate.finishMessage;
|
|
1576
1614
|
aggregatedResponse.candidates[i].safetyRatings =
|
|
1577
1615
|
candidate.safetyRatings;
|
|
1616
|
+
aggregatedResponse.candidates[i].groundingMetadata =
|
|
1617
|
+
candidate.groundingMetadata;
|
|
1578
1618
|
/**
|
|
1579
1619
|
* Candidates should always have content and parts, but this handles
|
|
1580
1620
|
* possible malformed responses.
|
|
@@ -1601,7 +1641,7 @@ function aggregateResponses(responses) {
|
|
|
1601
1641
|
newPart.functionCall = part.functionCall;
|
|
1602
1642
|
}
|
|
1603
1643
|
if (Object.keys(newPart).length === 0) {
|
|
1604
|
-
throw new AIError(
|
|
1644
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, 'Part should have at least one property, but there are none. This is likely caused ' +
|
|
1605
1645
|
'by a malformed response from the backend.');
|
|
1606
1646
|
}
|
|
1607
1647
|
aggregatedResponse.candidates[i].content.parts.push(newPart);
|
|
@@ -1736,10 +1776,10 @@ function assignRoleToPartsAndValidateSendMessageRequest(parts) {
|
|
|
1736
1776
|
}
|
|
1737
1777
|
}
|
|
1738
1778
|
if (hasUserContent && hasFunctionContent) {
|
|
1739
|
-
throw new AIError(
|
|
1779
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, 'Within a single message, FunctionResponse cannot be mixed with other type of Part in the request for sending chat message.');
|
|
1740
1780
|
}
|
|
1741
1781
|
if (!hasUserContent && !hasFunctionContent) {
|
|
1742
|
-
throw new AIError(
|
|
1782
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, 'No Content is provided for sending chat message.');
|
|
1743
1783
|
}
|
|
1744
1784
|
if (hasUserContent) {
|
|
1745
1785
|
return userContent;
|
|
@@ -1832,16 +1872,16 @@ function validateChatHistory(history) {
|
|
|
1832
1872
|
for (const currContent of history) {
|
|
1833
1873
|
const { role, parts } = currContent;
|
|
1834
1874
|
if (!prevContent && role !== 'user') {
|
|
1835
|
-
throw new AIError(
|
|
1875
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `First Content should be with role 'user', got ${role}`);
|
|
1836
1876
|
}
|
|
1837
1877
|
if (!POSSIBLE_ROLES.includes(role)) {
|
|
1838
|
-
throw new AIError(
|
|
1878
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `Each item should include role field. Got ${role} but valid roles are: ${JSON.stringify(POSSIBLE_ROLES)}`);
|
|
1839
1879
|
}
|
|
1840
1880
|
if (!Array.isArray(parts)) {
|
|
1841
|
-
throw new AIError(
|
|
1881
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `Content should have 'parts' but property with an array of Parts`);
|
|
1842
1882
|
}
|
|
1843
1883
|
if (parts.length === 0) {
|
|
1844
|
-
throw new AIError(
|
|
1884
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `Each Content should have at least one part`);
|
|
1845
1885
|
}
|
|
1846
1886
|
const countFields = {
|
|
1847
1887
|
text: 0,
|
|
@@ -1859,13 +1899,13 @@ function validateChatHistory(history) {
|
|
|
1859
1899
|
const validParts = VALID_PARTS_PER_ROLE[role];
|
|
1860
1900
|
for (const key of VALID_PART_FIELDS) {
|
|
1861
1901
|
if (!validParts.includes(key) && countFields[key] > 0) {
|
|
1862
|
-
throw new AIError(
|
|
1902
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `Content with role '${role}' can't contain '${key}' part`);
|
|
1863
1903
|
}
|
|
1864
1904
|
}
|
|
1865
1905
|
if (prevContent) {
|
|
1866
1906
|
const validPreviousContentRoles = VALID_PREVIOUS_CONTENT_ROLES[role];
|
|
1867
1907
|
if (!validPreviousContentRoles.includes(prevContent.role)) {
|
|
1868
|
-
throw new AIError(
|
|
1908
|
+
throw new AIError(AIErrorCode.INVALID_CONTENT, `Content with role '${role}' can't follow '${prevContent.role}'. Valid previous roles: ${JSON.stringify(VALID_PREVIOUS_CONTENT_ROLES)}`);
|
|
1869
1909
|
}
|
|
1870
1910
|
}
|
|
1871
1911
|
prevContent = currContent;
|
|
@@ -2388,7 +2428,7 @@ class ObjectSchema extends Schema {
|
|
|
2388
2428
|
if (this.optionalProperties) {
|
|
2389
2429
|
for (const propertyKey of this.optionalProperties) {
|
|
2390
2430
|
if (!this.properties.hasOwnProperty(propertyKey)) {
|
|
2391
|
-
throw new AIError(
|
|
2431
|
+
throw new AIError(AIErrorCode.INVALID_SCHEMA, `Property "${propertyKey}" specified in "optionalProperties" does not exist.`);
|
|
2392
2432
|
}
|
|
2393
2433
|
}
|
|
2394
2434
|
}
|
|
@@ -2488,50 +2528,6 @@ class ImagenImageFormat {
|
|
|
2488
2528
|
* See the License for the specific language governing permissions and
|
|
2489
2529
|
* limitations under the License.
|
|
2490
2530
|
*/
|
|
2491
|
-
/**
|
|
2492
|
-
* @deprecated Use the new {@link AIModel} instead. The Vertex AI in Firebase SDK has been
|
|
2493
|
-
* replaced with the Firebase AI SDK to accommodate the evolving set of supported features and
|
|
2494
|
-
* services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}.
|
|
2495
|
-
*
|
|
2496
|
-
* Base class for Firebase AI model APIs.
|
|
2497
|
-
*
|
|
2498
|
-
* @public
|
|
2499
|
-
*/
|
|
2500
|
-
const VertexAIModel = AIModel;
|
|
2501
|
-
/**
|
|
2502
|
-
* @deprecated Use the new {@link AIError} instead. The Vertex AI in Firebase SDK has been
|
|
2503
|
-
* replaced with the Firebase AI SDK to accommodate the evolving set of supported features and
|
|
2504
|
-
* services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}.
|
|
2505
|
-
*
|
|
2506
|
-
* Error class for the Firebase AI SDK.
|
|
2507
|
-
*
|
|
2508
|
-
* @public
|
|
2509
|
-
*/
|
|
2510
|
-
const VertexAIError = AIError;
|
|
2511
|
-
/**
|
|
2512
|
-
* @deprecated Use the new {@link getAI | getAI()} instead. The Vertex AI in Firebase SDK has been
|
|
2513
|
-
* replaced with the Firebase AI SDK to accommodate the evolving set of supported features and
|
|
2514
|
-
* services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}.
|
|
2515
|
-
*
|
|
2516
|
-
* Returns a {@link VertexAI} instance for the given app, configured to use the
|
|
2517
|
-
* Vertex AI Gemini API. This instance will be
|
|
2518
|
-
* configured to use the Vertex AI Gemini API.
|
|
2519
|
-
*
|
|
2520
|
-
* @param app - The {@link @firebase/app#FirebaseApp} to use.
|
|
2521
|
-
* @param options - Options to configure the Vertex AI instance, including the location.
|
|
2522
|
-
*
|
|
2523
|
-
* @public
|
|
2524
|
-
*/
|
|
2525
|
-
function getVertexAI(app = getApp(), options) {
|
|
2526
|
-
app = getModularInstance(app);
|
|
2527
|
-
// Dependencies
|
|
2528
|
-
const AIProvider = _getProvider(app, AI_TYPE);
|
|
2529
|
-
const backend = new VertexAIBackend(options === null || options === void 0 ? void 0 : options.location);
|
|
2530
|
-
const identifier = encodeInstanceIdentifier(backend);
|
|
2531
|
-
return AIProvider.getImmediate({
|
|
2532
|
-
identifier
|
|
2533
|
-
});
|
|
2534
|
-
}
|
|
2535
2531
|
/**
|
|
2536
2532
|
* Returns the default {@link AI} instance that is associated with the provided
|
|
2537
2533
|
* {@link @firebase/app#FirebaseApp}. If no instance exists, initializes a new instance with the
|
|
@@ -2577,7 +2573,7 @@ function getAI(app = getApp(), options = { backend: new GoogleAIBackend() }) {
|
|
|
2577
2573
|
*/
|
|
2578
2574
|
function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
2579
2575
|
if (!modelParams.model) {
|
|
2580
|
-
throw new AIError(
|
|
2576
|
+
throw new AIError(AIErrorCode.NO_MODEL, `Must provide a model name. Example: getGenerativeModel({ model: 'my-model-name' })`);
|
|
2581
2577
|
}
|
|
2582
2578
|
return new GenerativeModel(ai, modelParams, requestOptions);
|
|
2583
2579
|
}
|
|
@@ -2597,7 +2593,7 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
|
|
|
2597
2593
|
*/
|
|
2598
2594
|
function getImagenModel(ai, modelParams, requestOptions) {
|
|
2599
2595
|
if (!modelParams.model) {
|
|
2600
|
-
throw new AIError(
|
|
2596
|
+
throw new AIError(AIErrorCode.NO_MODEL, `Must provide a model name. Example: getImagenModel({ model: 'my-model-name' })`);
|
|
2601
2597
|
}
|
|
2602
2598
|
return new ImagenModel(ai, modelParams, requestOptions);
|
|
2603
2599
|
}
|
|
@@ -2610,7 +2606,7 @@ function getImagenModel(ai, modelParams, requestOptions) {
|
|
|
2610
2606
|
function registerAI() {
|
|
2611
2607
|
_registerComponent(new Component(AI_TYPE, (container, { instanceIdentifier }) => {
|
|
2612
2608
|
if (!instanceIdentifier) {
|
|
2613
|
-
throw new AIError(
|
|
2609
|
+
throw new AIError(AIErrorCode.ERROR, 'AIService instance identifier is undefined.');
|
|
2614
2610
|
}
|
|
2615
2611
|
const backend = decodeInstanceIdentifier(instanceIdentifier);
|
|
2616
2612
|
// getImmediate for FirebaseApp will always succeed
|
|
@@ -2625,5 +2621,5 @@ function registerAI() {
|
|
|
2625
2621
|
}
|
|
2626
2622
|
registerAI();
|
|
2627
2623
|
|
|
2628
|
-
export { AIError, AIModel, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, IntegerSchema, Modality, NumberSchema, ObjectSchema, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, VertexAIBackend,
|
|
2624
|
+
export { AIError, AIErrorCode, AIModel, ArraySchema, Backend, BackendType, BlockReason, BooleanSchema, ChatSession, FinishReason, FunctionCallingMode, GenerativeModel, GoogleAIBackend, HarmBlockMethod, HarmBlockThreshold, HarmCategory, HarmProbability, HarmSeverity, ImagenAspectRatio, ImagenImageFormat, ImagenModel, ImagenPersonFilterLevel, ImagenSafetyFilterLevel, IntegerSchema, Modality, NumberSchema, ObjectSchema, POSSIBLE_ROLES, ResponseModality, Schema, SchemaType, StringSchema, VertexAIBackend, getAI, getGenerativeModel, getImagenModel };
|
|
2629
2625
|
//# sourceMappingURL=index.esm2017.js.map
|