@langchain/google-common 0.2.15 → 0.2.16

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.
@@ -242,6 +242,12 @@ class ChatGoogleBase extends chat_models_1.BaseChatModel {
242
242
  writable: true,
243
243
  value: false
244
244
  });
245
+ Object.defineProperty(this, "labels", {
246
+ enumerable: true,
247
+ configurable: true,
248
+ writable: true,
249
+ value: void 0
250
+ });
245
251
  Object.defineProperty(this, "connection", {
246
252
  enumerable: true,
247
253
  configurable: true,
@@ -55,6 +55,7 @@ export declare abstract class ChatGoogleBase<AuthOptions> extends BaseChatModel<
55
55
  speechConfig: GoogleSpeechConfig;
56
56
  streamUsage: boolean;
57
57
  streaming: boolean;
58
+ labels?: Record<string, string>;
58
59
  protected connection: ChatConnection<AuthOptions>;
59
60
  protected streamedConnection: ChatConnection<AuthOptions>;
60
61
  constructor(fields?: ChatGoogleBaseInput<AuthOptions>);
@@ -238,6 +238,12 @@ export class ChatGoogleBase extends BaseChatModel {
238
238
  writable: true,
239
239
  value: false
240
240
  });
241
+ Object.defineProperty(this, "labels", {
242
+ enumerable: true,
243
+ configurable: true,
244
+ writable: true,
245
+ value: void 0
246
+ });
241
247
  Object.defineProperty(this, "connection", {
242
248
  enumerable: true,
243
249
  configurable: true,
@@ -282,12 +282,7 @@ class GoogleAIConnection extends GoogleHostConnection {
282
282
  get computedLocation() {
283
283
  switch (this.apiName) {
284
284
  case "google":
285
- if (this.modelName.startsWith("gemini-2.5-flash-lite")) {
286
- return "global";
287
- }
288
- else {
289
- return super.computedLocation;
290
- }
285
+ return super.computedLocation;
291
286
  case "anthropic":
292
287
  return "us-east5";
293
288
  default:
@@ -375,7 +370,13 @@ class AbstractGoogleLLMConnection extends GoogleAIConnection {
375
370
  }
376
371
  }
377
372
  async formatData(input, parameters) {
378
- return this.api.formatData(input, parameters);
373
+ // Filter out labels for non-Vertex AI platforms (labels are only supported on Vertex AI)
374
+ let filteredParameters = parameters;
375
+ if (parameters.labels && this.platform !== "gcp") {
376
+ const { labels, ...paramsWithoutLabels } = parameters;
377
+ filteredParameters = paramsWithoutLabels;
378
+ }
379
+ return this.api.formatData(input, filteredParameters);
379
380
  }
380
381
  }
381
382
  exports.AbstractGoogleLLMConnection = AbstractGoogleLLMConnection;
@@ -276,12 +276,7 @@ export class GoogleAIConnection extends GoogleHostConnection {
276
276
  get computedLocation() {
277
277
  switch (this.apiName) {
278
278
  case "google":
279
- if (this.modelName.startsWith("gemini-2.5-flash-lite")) {
280
- return "global";
281
- }
282
- else {
283
- return super.computedLocation;
284
- }
279
+ return super.computedLocation;
285
280
  case "anthropic":
286
281
  return "us-east5";
287
282
  default:
@@ -368,7 +363,13 @@ export class AbstractGoogleLLMConnection extends GoogleAIConnection {
368
363
  }
369
364
  }
370
365
  async formatData(input, parameters) {
371
- return this.api.formatData(input, parameters);
366
+ // Filter out labels for non-Vertex AI platforms (labels are only supported on Vertex AI)
367
+ let filteredParameters = parameters;
368
+ if (parameters.labels && this.platform !== "gcp") {
369
+ const { labels, ...paramsWithoutLabels } = parameters;
370
+ filteredParameters = paramsWithoutLabels;
371
+ }
372
+ return this.api.formatData(input, filteredParameters);
372
373
  }
373
374
  }
374
375
  export class GoogleRequestCallbackHandler extends BaseCallbackHandler {
package/dist/types.d.ts CHANGED
@@ -263,6 +263,23 @@ export interface GoogleAIModelParams extends GoogleModelParams {
263
263
  * The modalities of the response.
264
264
  */
265
265
  responseModalities?: GoogleAIModelModality[];
266
+ /**
267
+ * Custom metadata labels to associate with the request.
268
+ * Only supported on Vertex AI (Google Cloud Platform).
269
+ * Labels are key-value pairs where both keys and values must be strings.
270
+ *
271
+ * Example:
272
+ * ```typescript
273
+ * {
274
+ * labels: {
275
+ * "team": "research",
276
+ * "component": "frontend",
277
+ * "environment": "production"
278
+ * }
279
+ * }
280
+ * ```
281
+ */
282
+ labels?: Record<string, string>;
266
283
  /**
267
284
  * Speech generation configuration.
268
285
  * You can use either Google's definition of the speech configuration,
@@ -530,6 +547,10 @@ export interface GeminiRequest {
530
547
  safetySettings?: GeminiSafetySetting[];
531
548
  generationConfig?: GeminiGenerationConfig;
532
549
  cachedContent?: string;
550
+ /**
551
+ * Custom metadata labels to associate with the API call.
552
+ */
553
+ labels?: Record<string, string>;
533
554
  }
534
555
  export interface GeminiResponseCandidate {
535
556
  content: {
@@ -180,6 +180,7 @@ function copyAIModelParamsInto(params, options, target) {
180
180
  if (options?.cachedContent) {
181
181
  ret.cachedContent = options.cachedContent;
182
182
  }
183
+ ret.labels = options?.labels ?? params?.labels ?? target?.labels;
183
184
  return ret;
184
185
  }
185
186
  function modelToFamily(modelName) {
@@ -171,6 +171,7 @@ export function copyAIModelParamsInto(params, options, target) {
171
171
  if (options?.cachedContent) {
172
172
  ret.cachedContent = options.cachedContent;
173
173
  }
174
+ ret.labels = options?.labels ?? params?.labels ?? target?.labels;
174
175
  return ret;
175
176
  }
176
177
  export function modelToFamily(modelName) {
@@ -1408,6 +1408,9 @@ function getGeminiAPI(config) {
1408
1408
  if (parameters.cachedContent) {
1409
1409
  ret.cachedContent = parameters.cachedContent;
1410
1410
  }
1411
+ if (parameters.labels && Object.keys(parameters.labels).length > 0) {
1412
+ ret.labels = parameters.labels;
1413
+ }
1411
1414
  return ret;
1412
1415
  }
1413
1416
  return {
@@ -1398,6 +1398,9 @@ export function getGeminiAPI(config) {
1398
1398
  if (parameters.cachedContent) {
1399
1399
  ret.cachedContent = parameters.cachedContent;
1400
1400
  }
1401
+ if (parameters.labels && Object.keys(parameters.labels).length > 0) {
1402
+ ret.labels = parameters.labels;
1403
+ }
1401
1404
  return ret;
1402
1405
  }
1403
1406
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-common",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "Core types and classes for Google services.",
5
5
  "type": "module",
6
6
  "engines": {