@langchain/google-common 0.0.11 → 0.0.13

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.
@@ -109,6 +109,11 @@ class ChatGoogleBase extends chat_models_1.BaseChatModel {
109
109
  static lc_name() {
110
110
  return "ChatGoogle";
111
111
  }
112
+ get lc_secrets() {
113
+ return {
114
+ authOptions: "GOOGLE_AUTH_OPTIONS",
115
+ };
116
+ }
112
117
  constructor(fields) {
113
118
  super((0, failed_handler_js_1.ensureParams)(fields));
114
119
  Object.defineProperty(this, "lc_serializable", {
@@ -30,6 +30,9 @@ export interface ChatGoogleBaseInput<AuthOptions> extends BaseChatModelParams, G
30
30
  */
31
31
  export declare abstract class ChatGoogleBase<AuthOptions> extends BaseChatModel<GoogleAIBaseLanguageModelCallOptions, AIMessageChunk> implements ChatGoogleBaseInput<AuthOptions> {
32
32
  static lc_name(): string;
33
+ get lc_secrets(): {
34
+ [key: string]: string;
35
+ } | undefined;
33
36
  lc_serializable: boolean;
34
37
  model: string;
35
38
  modelName: string;
@@ -106,6 +106,11 @@ export class ChatGoogleBase extends BaseChatModel {
106
106
  static lc_name() {
107
107
  return "ChatGoogle";
108
108
  }
109
+ get lc_secrets() {
110
+ return {
111
+ authOptions: "GOOGLE_AUTH_OPTIONS",
112
+ };
113
+ }
109
114
  constructor(fields) {
110
115
  super(ensureParams(fields));
111
116
  Object.defineProperty(this, "lc_serializable", {
@@ -28,21 +28,26 @@ class GoogleConnection {
28
28
  this.streaming = streaming ?? false;
29
29
  }
30
30
  async _clientInfoHeaders() {
31
- const clientLibraryVersion = await this._clientLibraryVersion();
31
+ const { userAgent, clientLibraryVersion } = await this._getClientInfo();
32
32
  return {
33
- "User-Agent": clientLibraryVersion,
33
+ "User-Agent": userAgent,
34
+ "Client-Info": clientLibraryVersion,
34
35
  };
35
36
  }
36
- async _clientLibraryVersion() {
37
+ async _getClientInfo() {
37
38
  const env = await (0, env_1.getRuntimeEnvironment)();
38
39
  const langchain = env?.library ?? "langchain-js";
39
- const langchainVersion = env?.libraryVersion ?? "0";
40
+ // TODO: Add an API for getting the current LangChain version
41
+ const langchainVersion = "0";
40
42
  const moduleName = await this._moduleName();
41
- let ret = `${langchain}/${langchainVersion}`;
43
+ let clientLibraryVersion = `${langchain}/${langchainVersion}`;
42
44
  if (moduleName && moduleName.length) {
43
- ret = `${ret}-${moduleName}`;
45
+ clientLibraryVersion = `${clientLibraryVersion}-${moduleName}`;
44
46
  }
45
- return ret;
47
+ return {
48
+ userAgent: clientLibraryVersion,
49
+ clientLibraryVersion: `${langchainVersion}-${moduleName}`,
50
+ };
46
51
  }
47
52
  async _moduleName() {
48
53
  return this.constructor.name;
@@ -208,6 +213,7 @@ class AbstractGoogleLLMConnection extends GoogleAIConnection {
208
213
  topP: parameters.topP,
209
214
  maxOutputTokens: parameters.maxOutputTokens,
210
215
  stopSequences: parameters.stopSequences,
216
+ responseMimeType: parameters.responseMimeType,
211
217
  };
212
218
  }
213
219
  formatSafetySettings(_input, parameters) {
@@ -11,7 +11,10 @@ export declare abstract class GoogleConnection<CallOptions extends AsyncCallerCa
11
11
  abstract buildUrl(): Promise<string>;
12
12
  abstract buildMethod(): GoogleAbstractedClientOpsMethod;
13
13
  _clientInfoHeaders(): Promise<Record<string, string>>;
14
- _clientLibraryVersion(): Promise<string>;
14
+ _getClientInfo(): Promise<{
15
+ userAgent: string;
16
+ clientLibraryVersion: string;
17
+ }>;
15
18
  _moduleName(): Promise<string>;
16
19
  _request(data: unknown | undefined, options: CallOptions): Promise<ResponseType>;
17
20
  }
@@ -25,21 +25,26 @@ export class GoogleConnection {
25
25
  this.streaming = streaming ?? false;
26
26
  }
27
27
  async _clientInfoHeaders() {
28
- const clientLibraryVersion = await this._clientLibraryVersion();
28
+ const { userAgent, clientLibraryVersion } = await this._getClientInfo();
29
29
  return {
30
- "User-Agent": clientLibraryVersion,
30
+ "User-Agent": userAgent,
31
+ "Client-Info": clientLibraryVersion,
31
32
  };
32
33
  }
33
- async _clientLibraryVersion() {
34
+ async _getClientInfo() {
34
35
  const env = await getRuntimeEnvironment();
35
36
  const langchain = env?.library ?? "langchain-js";
36
- const langchainVersion = env?.libraryVersion ?? "0";
37
+ // TODO: Add an API for getting the current LangChain version
38
+ const langchainVersion = "0";
37
39
  const moduleName = await this._moduleName();
38
- let ret = `${langchain}/${langchainVersion}`;
40
+ let clientLibraryVersion = `${langchain}/${langchainVersion}`;
39
41
  if (moduleName && moduleName.length) {
40
- ret = `${ret}-${moduleName}`;
42
+ clientLibraryVersion = `${clientLibraryVersion}-${moduleName}`;
41
43
  }
42
- return ret;
44
+ return {
45
+ userAgent: clientLibraryVersion,
46
+ clientLibraryVersion: `${langchainVersion}-${moduleName}`,
47
+ };
43
48
  }
44
49
  async _moduleName() {
45
50
  return this.constructor.name;
@@ -202,6 +207,7 @@ export class AbstractGoogleLLMConnection extends GoogleAIConnection {
202
207
  topP: parameters.topP,
203
208
  maxOutputTokens: parameters.maxOutputTokens,
204
209
  stopSequences: parameters.stopSequences,
210
+ responseMimeType: parameters.responseMimeType,
205
211
  };
206
212
  }
207
213
  formatSafetySettings(_input, parameters) {
package/dist/llms.cjs CHANGED
@@ -107,6 +107,12 @@ class GoogleBaseLLM extends llms_1.LLM {
107
107
  writable: true,
108
108
  value: void 0
109
109
  });
110
+ Object.defineProperty(this, "responseMimeType", {
111
+ enumerable: true,
112
+ configurable: true,
113
+ writable: true,
114
+ value: "text/plain"
115
+ });
110
116
  Object.defineProperty(this, "connection", {
111
117
  enumerable: true,
112
118
  configurable: true,
package/dist/llms.d.ts CHANGED
@@ -3,7 +3,7 @@ import { LLM } from "@langchain/core/language_models/llms";
3
3
  import { type BaseLanguageModelCallOptions, BaseLanguageModelInput } from "@langchain/core/language_models/base";
4
4
  import { BaseMessage, MessageContent } from "@langchain/core/messages";
5
5
  import { AbstractGoogleLLMConnection } from "./connection.js";
6
- import { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GooglePlatformType, GeminiContent } from "./types.js";
6
+ import { GoogleAIBaseLLMInput, GoogleAIModelParams, GoogleAISafetySetting, GooglePlatformType, GeminiContent, GoogleAIResponseMimeType } from "./types.js";
7
7
  import { GoogleAbstractedClient } from "./auth.js";
8
8
  import { ChatGoogleBase } from "./chat_models.js";
9
9
  import type { GoogleBaseLLMInput, GoogleAISafetyHandler } from "./types.js";
@@ -27,6 +27,7 @@ export declare abstract class GoogleBaseLLM<AuthOptions> extends LLM<BaseLanguag
27
27
  stopSequences: string[];
28
28
  safetySettings: GoogleAISafetySetting[];
29
29
  safetyHandler: GoogleAISafetyHandler;
30
+ responseMimeType: GoogleAIResponseMimeType;
30
31
  protected connection: GoogleLLMConnection<AuthOptions>;
31
32
  protected streamedConnection: GoogleLLMConnection<AuthOptions>;
32
33
  constructor(fields?: GoogleBaseLLMInput<AuthOptions>);
package/dist/llms.js CHANGED
@@ -104,6 +104,12 @@ export class GoogleBaseLLM extends LLM {
104
104
  writable: true,
105
105
  value: void 0
106
106
  });
107
+ Object.defineProperty(this, "responseMimeType", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: "text/plain"
112
+ });
107
113
  Object.defineProperty(this, "connection", {
108
114
  enumerable: true,
109
115
  configurable: true,
package/dist/types.d.ts CHANGED
@@ -37,6 +37,7 @@ export interface GoogleAISafetySetting {
37
37
  category: string;
38
38
  threshold: string;
39
39
  }
40
+ export type GoogleAIResponseMimeType = "text/plain" | "application/json";
40
41
  export interface GoogleAIModelParams {
41
42
  /** Model to use */
42
43
  model?: string;
@@ -74,6 +75,16 @@ export interface GoogleAIModelParams {
74
75
  stopSequences?: string[];
75
76
  safetySettings?: GoogleAISafetySetting[];
76
77
  convertSystemMessageToHumanContent?: boolean;
78
+ /**
79
+ * Available for `gemini-1.5-pro`.
80
+ * The output format of the generated candidate text.
81
+ * Supported MIME types:
82
+ * - `text/plain`: Text output.
83
+ * - `application/json`: JSON response in the candidates.
84
+ *
85
+ * @default "text/plain"
86
+ */
87
+ responseMimeType?: GoogleAIResponseMimeType;
77
88
  }
78
89
  /**
79
90
  * The params which can be passed to the API at request time.
@@ -160,6 +171,7 @@ export interface GeminiGenerationConfig {
160
171
  temperature?: number;
161
172
  topP?: number;
162
173
  topK?: number;
174
+ responseMimeType?: GoogleAIResponseMimeType;
163
175
  }
164
176
  export interface GeminiRequest {
165
177
  contents?: GeminiContent[];
@@ -204,4 +216,12 @@ export interface GoogleAISafetyHandler {
204
216
  export interface GoogleAISafetyParams {
205
217
  safetyHandler?: GoogleAISafetyHandler;
206
218
  }
219
+ export type GeminiJsonSchema = Record<string, unknown> & {
220
+ properties?: Record<string, GeminiJsonSchema>;
221
+ type: GeminiFunctionSchemaType;
222
+ };
223
+ export interface GeminiJsonSchemaDirty extends GeminiJsonSchema {
224
+ properties?: Record<string, GeminiJsonSchemaDirty>;
225
+ additionalProperties?: boolean;
226
+ }
207
227
  export {};
@@ -28,6 +28,10 @@ function copyAIModelParamsInto(params, options, target) {
28
28
  options?.convertSystemMessageToHumanContent ??
29
29
  params?.convertSystemMessageToHumanContent ??
30
30
  target?.convertSystemMessageToHumanContent;
31
+ ret.responseMimeType =
32
+ options?.responseMimeType ??
33
+ params?.responseMimeType ??
34
+ target?.responseMimeType;
31
35
  ret.tools = options?.tools;
32
36
  // Ensure tools are formatted properly for Gemini
33
37
  const geminiTools = options?.tools
@@ -24,6 +24,10 @@ export function copyAIModelParamsInto(params, options, target) {
24
24
  options?.convertSystemMessageToHumanContent ??
25
25
  params?.convertSystemMessageToHumanContent ??
26
26
  target?.convertSystemMessageToHumanContent;
27
+ ret.responseMimeType =
28
+ options?.responseMimeType ??
29
+ params?.responseMimeType ??
30
+ target?.responseMimeType;
27
31
  ret.tools = options?.tools;
28
32
  // Ensure tools are formatted properly for Gemini
29
33
  const geminiTools = options?.tools
@@ -3,14 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.zodToGeminiParameters = void 0;
5
5
  const zod_to_json_schema_1 = require("zod-to-json-schema");
6
+ function removeAdditionalProperties(schema) {
7
+ const updatedSchema = { ...schema };
8
+ if (Object.hasOwn(updatedSchema, "additionalProperties")) {
9
+ delete updatedSchema.additionalProperties;
10
+ }
11
+ if (updatedSchema.properties) {
12
+ const keys = Object.keys(updatedSchema.properties);
13
+ removeProperties(updatedSchema.properties, keys, 0);
14
+ }
15
+ return updatedSchema;
16
+ }
17
+ function removeProperties(properties, keys, index) {
18
+ if (index >= keys.length) {
19
+ return;
20
+ }
21
+ const key = keys[index];
22
+ // eslint-disable-next-line no-param-reassign
23
+ properties[key] = removeAdditionalProperties(properties[key]);
24
+ removeProperties(properties, keys, index + 1);
25
+ }
6
26
  function zodToGeminiParameters(
7
27
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
28
  zodObj) {
9
29
  // Gemini doesn't accept either the $schema or additionalProperties
10
30
  // attributes, so we need to explicitly remove them.
11
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
- const jsonSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(zodObj);
13
- const { $schema, additionalProperties, ...rest } = jsonSchema;
32
+ // const jsonSchema = zodToJsonSchema(zodObj) as any;
33
+ const jsonSchema = removeAdditionalProperties((0, zod_to_json_schema_1.zodToJsonSchema)(zodObj));
34
+ const { $schema, ...rest } = jsonSchema;
14
35
  return rest;
15
36
  }
16
37
  exports.zodToGeminiParameters = zodToGeminiParameters;
@@ -1,12 +1,33 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  import { zodToJsonSchema } from "zod-to-json-schema";
3
+ function removeAdditionalProperties(schema) {
4
+ const updatedSchema = { ...schema };
5
+ if (Object.hasOwn(updatedSchema, "additionalProperties")) {
6
+ delete updatedSchema.additionalProperties;
7
+ }
8
+ if (updatedSchema.properties) {
9
+ const keys = Object.keys(updatedSchema.properties);
10
+ removeProperties(updatedSchema.properties, keys, 0);
11
+ }
12
+ return updatedSchema;
13
+ }
14
+ function removeProperties(properties, keys, index) {
15
+ if (index >= keys.length) {
16
+ return;
17
+ }
18
+ const key = keys[index];
19
+ // eslint-disable-next-line no-param-reassign
20
+ properties[key] = removeAdditionalProperties(properties[key]);
21
+ removeProperties(properties, keys, index + 1);
22
+ }
3
23
  export function zodToGeminiParameters(
4
24
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
25
  zodObj) {
6
26
  // Gemini doesn't accept either the $schema or additionalProperties
7
27
  // attributes, so we need to explicitly remove them.
8
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const jsonSchema = zodToJsonSchema(zodObj);
10
- const { $schema, additionalProperties, ...rest } = jsonSchema;
29
+ // const jsonSchema = zodToJsonSchema(zodObj) as any;
30
+ const jsonSchema = removeAdditionalProperties(zodToJsonSchema(zodObj));
31
+ const { $schema, ...rest } = jsonSchema;
11
32
  return rest;
12
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-common",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "description": "Core types and classes for Google services.",
5
5
  "type": "module",
6
6
  "engines": {