@firebase/ai 2.7.0-canary.65a553baf → 2.7.0-canary.691a506ec

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.
@@ -165,6 +165,7 @@ declare interface ApiSettings {
165
165
  backend: Backend;
166
166
  getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
167
167
  getAppCheckToken?: () => Promise<AppCheckTokenResult>;
168
+ inferenceMode?: InferenceMode;
168
169
  }
169
170
 
170
171
  /**
package/dist/ai.d.ts CHANGED
@@ -202,6 +202,7 @@ declare interface ApiSettings {
202
202
  backend: Backend;
203
203
  getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
204
204
  getAppCheckToken?: () => Promise<AppCheckTokenResult>;
205
+ inferenceMode?: InferenceMode;
205
206
  }
206
207
 
207
208
  /**
@@ -4,7 +4,7 @@ import { FirebaseError, Deferred, getModularInstance } from '@firebase/util';
4
4
  import { Logger } from '@firebase/logger';
5
5
 
6
6
  var name = "@firebase/ai";
7
- var version = "2.7.0-canary.65a553baf";
7
+ var version = "2.7.0-canary.691a506ec";
8
8
 
9
9
  /**
10
10
  * @license
@@ -28,6 +28,7 @@ const DEFAULT_DOMAIN = 'firebasevertexai.googleapis.com';
28
28
  const DEFAULT_API_VERSION = 'v1beta';
29
29
  const PACKAGE_VERSION = version;
30
30
  const LANGUAGE_TAG = 'gl-js';
31
+ const HYBRID_TAG = 'hybrid';
31
32
  const DEFAULT_FETCH_TIMEOUT_MS = 180 * 1000;
32
33
  /**
33
34
  * Defines the name of the default in-cloud model to use for hybrid inference.
@@ -1512,16 +1513,25 @@ class WebSocketUrl {
1512
1513
  /**
1513
1514
  * Log language and "fire/version" to x-goog-api-client
1514
1515
  */
1515
- function getClientHeaders() {
1516
+ function getClientHeaders(url) {
1516
1517
  const loggingTags = [];
1517
1518
  loggingTags.push(`${LANGUAGE_TAG}/${PACKAGE_VERSION}`);
1518
1519
  loggingTags.push(`fire/${PACKAGE_VERSION}`);
1520
+ /**
1521
+ * No call would be made if ONLY_ON_DEVICE.
1522
+ * ONLY_IN_CLOUD does not indicate an intention to use hybrid.
1523
+ */
1524
+ if (url.params.apiSettings.inferenceMode === InferenceMode.PREFER_ON_DEVICE ||
1525
+ url.params.apiSettings.inferenceMode === InferenceMode.PREFER_IN_CLOUD) {
1526
+ // No version
1527
+ loggingTags.push(HYBRID_TAG);
1528
+ }
1519
1529
  return loggingTags.join(' ');
1520
1530
  }
1521
1531
  async function getHeaders(url) {
1522
1532
  const headers = new Headers();
1523
1533
  headers.append('Content-Type', 'application/json');
1524
- headers.append('x-goog-api-client', getClientHeaders());
1534
+ headers.append('x-goog-api-client', getClientHeaders(url));
1525
1535
  headers.append('x-goog-api-key', url.params.apiSettings.apiKey);
1526
1536
  if (url.params.apiSettings.automaticDataCollectionEnabled) {
1527
1537
  headers.append('X-Firebase-Appid', url.params.apiSettings.appId);
@@ -4463,7 +4473,9 @@ function getGenerativeModel(ai, modelParams, requestOptions) {
4463
4473
  * chromeAdapterFactory() method.
4464
4474
  */
4465
4475
  const chromeAdapter = ai.chromeAdapterFactory?.(hybridParams.mode, typeof window === 'undefined' ? undefined : window, hybridParams.onDeviceParams);
4466
- return new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
4476
+ const generativeModel = new GenerativeModel(ai, inCloudParams, requestOptions, chromeAdapter);
4477
+ generativeModel._apiSettings.inferenceMode = hybridParams.mode;
4478
+ return generativeModel;
4467
4479
  }
4468
4480
  /**
4469
4481
  * Returns an {@link ImagenModel} class with methods for using Imagen.