@langchain/google-genai 0.0.23 → 0.0.25
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/chat_models.cjs +14 -0
- package/dist/chat_models.d.ts +12 -8
- package/dist/chat_models.js +14 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/utils/common.cjs +13 -14
- package/dist/utils/common.d.ts +2 -4
- package/dist/utils/common.js +15 -16
- package/package.json +6 -6
package/dist/chat_models.cjs
CHANGED
|
@@ -47,6 +47,11 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
47
47
|
apiKey: "GOOGLE_API_KEY",
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
|
+
get lc_aliases() {
|
|
51
|
+
return {
|
|
52
|
+
apiKey: "google_api_key",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
50
55
|
get _isMultimodalModel() {
|
|
51
56
|
return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
|
|
52
57
|
}
|
|
@@ -58,6 +63,12 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
58
63
|
writable: true,
|
|
59
64
|
value: true
|
|
60
65
|
});
|
|
66
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: ["langchain", "chat_models", "google_genai"]
|
|
71
|
+
});
|
|
61
72
|
Object.defineProperty(this, "modelName", {
|
|
62
73
|
enumerable: true,
|
|
63
74
|
configurable: true,
|
|
@@ -207,6 +218,9 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
|
|
|
207
218
|
return this.bind({ tools: (0, common_js_1.convertToGenerativeAITools)(tools), ...kwargs });
|
|
208
219
|
}
|
|
209
220
|
invocationParams(options) {
|
|
221
|
+
if (options?.tool_choice) {
|
|
222
|
+
throw new Error("'tool_choice' call option is not supported by ChatGoogleGenerativeAI.");
|
|
223
|
+
}
|
|
210
224
|
const tools = options?.tools;
|
|
211
225
|
if (Array.isArray(tools) &&
|
|
212
226
|
!tools.some(
|
package/dist/chat_models.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenerateContentRequest, SafetySetting, Part as GenerativeAIPart } from "@google/generative-ai";
|
|
2
2
|
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
|
|
3
3
|
import { AIMessageChunk, BaseMessage } from "@langchain/core/messages";
|
|
4
4
|
import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
|
5
|
-
import { BaseChatModel, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { Runnable, RunnableToolLike } from "@langchain/core/runnables";
|
|
5
|
+
import { BaseChatModel, type BaseChatModelCallOptions, type LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
|
+
import { BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
|
|
7
|
+
import { Runnable } from "@langchain/core/runnables";
|
|
9
8
|
import type { z } from "zod";
|
|
9
|
+
import { GoogleGenerativeAIToolType } from "./types.js";
|
|
10
10
|
export type BaseMessageExamplePair = {
|
|
11
11
|
input: BaseMessage;
|
|
12
12
|
output: BaseMessage;
|
|
13
13
|
};
|
|
14
|
-
export interface GoogleGenerativeAIChatCallOptions extends
|
|
15
|
-
tools?:
|
|
14
|
+
export interface GoogleGenerativeAIChatCallOptions extends BaseChatModelCallOptions {
|
|
15
|
+
tools?: GoogleGenerativeAIToolType[];
|
|
16
16
|
/**
|
|
17
17
|
* Whether or not to include usage data, like token counts
|
|
18
18
|
* in the streamed response chunks.
|
|
@@ -143,6 +143,10 @@ export declare class ChatGoogleGenerativeAI extends BaseChatModel<GoogleGenerati
|
|
|
143
143
|
get lc_secrets(): {
|
|
144
144
|
[key: string]: string;
|
|
145
145
|
} | undefined;
|
|
146
|
+
lc_namespace: string[];
|
|
147
|
+
get lc_aliases(): {
|
|
148
|
+
apiKey: string;
|
|
149
|
+
};
|
|
146
150
|
modelName: string;
|
|
147
151
|
model: string;
|
|
148
152
|
temperature?: number;
|
|
@@ -160,7 +164,7 @@ export declare class ChatGoogleGenerativeAI extends BaseChatModel<GoogleGenerati
|
|
|
160
164
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
161
165
|
_combineLLMOutput(): never[];
|
|
162
166
|
_llmType(): string;
|
|
163
|
-
bindTools(tools:
|
|
167
|
+
bindTools(tools: GoogleGenerativeAIToolType[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
|
|
164
168
|
invocationParams(options?: this["ParsedCallOptions"]): Omit<GenerateContentRequest, "contents">;
|
|
165
169
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
166
170
|
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
package/dist/chat_models.js
CHANGED
|
@@ -44,6 +44,11 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
44
44
|
apiKey: "GOOGLE_API_KEY",
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
+
get lc_aliases() {
|
|
48
|
+
return {
|
|
49
|
+
apiKey: "google_api_key",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
47
52
|
get _isMultimodalModel() {
|
|
48
53
|
return this.model.includes("vision") || this.model.startsWith("gemini-1.5");
|
|
49
54
|
}
|
|
@@ -55,6 +60,12 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
55
60
|
writable: true,
|
|
56
61
|
value: true
|
|
57
62
|
});
|
|
63
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: ["langchain", "chat_models", "google_genai"]
|
|
68
|
+
});
|
|
58
69
|
Object.defineProperty(this, "modelName", {
|
|
59
70
|
enumerable: true,
|
|
60
71
|
configurable: true,
|
|
@@ -204,6 +215,9 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
|
|
|
204
215
|
return this.bind({ tools: convertToGenerativeAITools(tools), ...kwargs });
|
|
205
216
|
}
|
|
206
217
|
invocationParams(options) {
|
|
218
|
+
if (options?.tool_choice) {
|
|
219
|
+
throw new Error("'tool_choice' call option is not supported by ChatGoogleGenerativeAI.");
|
|
220
|
+
}
|
|
207
221
|
const tools = options?.tools;
|
|
208
222
|
if (Array.isArray(tools) &&
|
|
209
223
|
!tools.some(
|
package/dist/types.cjs
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool } from "@google/generative-ai";
|
|
2
|
+
import { BindToolsInput } from "@langchain/core/language_models/chat_models";
|
|
3
|
+
export type GoogleGenerativeAIToolType = BindToolsInput | GoogleGenerativeAIFunctionDeclarationsTool;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils/common.cjs
CHANGED
|
@@ -246,31 +246,30 @@ function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
|
246
246
|
});
|
|
247
247
|
}
|
|
248
248
|
exports.convertResponseContentToChatGenerationChunk = convertResponseContentToChatGenerationChunk;
|
|
249
|
-
function convertToGenerativeAITools(
|
|
250
|
-
if (
|
|
249
|
+
function convertToGenerativeAITools(tools) {
|
|
250
|
+
if (tools.every((tool) => "functionDeclarations" in tool &&
|
|
251
251
|
Array.isArray(tool.functionDeclarations))) {
|
|
252
|
-
return
|
|
252
|
+
return tools;
|
|
253
253
|
}
|
|
254
254
|
return [
|
|
255
255
|
{
|
|
256
|
-
functionDeclarations:
|
|
257
|
-
if ((0, function_calling_1.
|
|
258
|
-
const jsonSchema = (0, zod_to_genai_parameters_js_1.zodToGenerativeAIParameters)(
|
|
256
|
+
functionDeclarations: tools.map((tool) => {
|
|
257
|
+
if ((0, function_calling_1.isLangChainTool)(tool)) {
|
|
258
|
+
const jsonSchema = (0, zod_to_genai_parameters_js_1.zodToGenerativeAIParameters)(tool.schema);
|
|
259
259
|
return {
|
|
260
|
-
name:
|
|
261
|
-
description:
|
|
260
|
+
name: tool.name,
|
|
261
|
+
description: tool.description,
|
|
262
262
|
parameters: jsonSchema,
|
|
263
263
|
};
|
|
264
264
|
}
|
|
265
|
-
if ((0, base_1.isOpenAITool)(
|
|
265
|
+
if ((0, base_1.isOpenAITool)(tool)) {
|
|
266
266
|
return {
|
|
267
|
-
name:
|
|
268
|
-
description:
|
|
269
|
-
|
|
270
|
-
parameters: (0, zod_to_genai_parameters_js_1.jsonSchemaToGeminiParameters)(structuredTool.function.parameters),
|
|
267
|
+
name: tool.function.name,
|
|
268
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
269
|
+
parameters: (0, zod_to_genai_parameters_js_1.jsonSchemaToGeminiParameters)(tool.function.parameters),
|
|
271
270
|
};
|
|
272
271
|
}
|
|
273
|
-
return
|
|
272
|
+
return tool;
|
|
274
273
|
}),
|
|
275
274
|
},
|
|
276
275
|
];
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { EnhancedGenerateContentResponse, Content, Part, type FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, POSSIBLE_ROLES } from "@google/generative-ai";
|
|
2
2
|
import { BaseMessage, UsageMetadata } from "@langchain/core/messages";
|
|
3
3
|
import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
|
4
|
-
import {
|
|
5
|
-
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
6
|
-
import { RunnableToolLike } from "@langchain/core/runnables";
|
|
4
|
+
import { GoogleGenerativeAIToolType } from "../types.js";
|
|
7
5
|
export declare function getMessageAuthor(message: BaseMessage): string;
|
|
8
6
|
/**
|
|
9
7
|
* Maps a message type to a Google Generative AI chat author.
|
|
@@ -21,4 +19,4 @@ export declare function convertResponseContentToChatGenerationChunk(response: En
|
|
|
21
19
|
usageMetadata?: UsageMetadata | undefined;
|
|
22
20
|
index: number;
|
|
23
21
|
}): ChatGenerationChunk | null;
|
|
24
|
-
export declare function convertToGenerativeAITools(
|
|
22
|
+
export declare function convertToGenerativeAITools(tools: GoogleGenerativeAIToolType[]): GoogleGenerativeAIFunctionDeclarationsTool[];
|
package/dist/utils/common.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AIMessage, AIMessageChunk, ChatMessage, isBaseMessage, } from "@langchain/core/messages";
|
|
2
2
|
import { ChatGenerationChunk, } from "@langchain/core/outputs";
|
|
3
|
-
import {
|
|
4
|
-
import { isOpenAITool
|
|
3
|
+
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
4
|
+
import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
5
5
|
import { jsonSchemaToGeminiParameters, zodToGenerativeAIParameters, } from "./zod_to_genai_parameters.js";
|
|
6
6
|
export function getMessageAuthor(message) {
|
|
7
7
|
const type = message._getType();
|
|
@@ -237,31 +237,30 @@ export function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
|
237
237
|
generationInfo,
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
|
-
export function convertToGenerativeAITools(
|
|
241
|
-
if (
|
|
240
|
+
export function convertToGenerativeAITools(tools) {
|
|
241
|
+
if (tools.every((tool) => "functionDeclarations" in tool &&
|
|
242
242
|
Array.isArray(tool.functionDeclarations))) {
|
|
243
|
-
return
|
|
243
|
+
return tools;
|
|
244
244
|
}
|
|
245
245
|
return [
|
|
246
246
|
{
|
|
247
|
-
functionDeclarations:
|
|
248
|
-
if (
|
|
249
|
-
const jsonSchema = zodToGenerativeAIParameters(
|
|
247
|
+
functionDeclarations: tools.map((tool) => {
|
|
248
|
+
if (isLangChainTool(tool)) {
|
|
249
|
+
const jsonSchema = zodToGenerativeAIParameters(tool.schema);
|
|
250
250
|
return {
|
|
251
|
-
name:
|
|
252
|
-
description:
|
|
251
|
+
name: tool.name,
|
|
252
|
+
description: tool.description,
|
|
253
253
|
parameters: jsonSchema,
|
|
254
254
|
};
|
|
255
255
|
}
|
|
256
|
-
if (isOpenAITool(
|
|
256
|
+
if (isOpenAITool(tool)) {
|
|
257
257
|
return {
|
|
258
|
-
name:
|
|
259
|
-
description:
|
|
260
|
-
|
|
261
|
-
parameters: jsonSchemaToGeminiParameters(structuredTool.function.parameters),
|
|
258
|
+
name: tool.function.name,
|
|
259
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
260
|
+
parameters: jsonSchemaToGeminiParameters(tool.function.parameters),
|
|
262
261
|
};
|
|
263
262
|
}
|
|
264
|
-
return
|
|
263
|
+
return tool;
|
|
265
264
|
}),
|
|
266
265
|
},
|
|
267
266
|
];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-genai",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.25",
|
|
4
|
+
"description": "Google Generative AI integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=18"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-genai/",
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "yarn turbo:command build:internal --filter=@langchain/google-genai",
|
|
18
|
-
"build:internal": "yarn
|
|
18
|
+
"build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking",
|
|
19
19
|
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
|
|
20
20
|
"lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
|
|
21
21
|
"lint": "yarn lint:eslint && yarn lint:dpdm",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@google/generative-ai": "^0.7.0",
|
|
39
|
-
"@langchain/core": ">=0.2.
|
|
39
|
+
"@langchain/core": ">=0.2.21 <0.3.0",
|
|
40
40
|
"zod-to-json-schema": "^3.22.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@jest/globals": "^29.5.0",
|
|
44
|
-
"@langchain/scripts": "~0.0.
|
|
44
|
+
"@langchain/scripts": "~0.0.20",
|
|
45
45
|
"@langchain/standard-tests": "0.0.0",
|
|
46
46
|
"@swc/core": "^1.3.90",
|
|
47
47
|
"@swc/jest": "^0.2.29",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"jest": "^29.5.0",
|
|
61
61
|
"jest-environment-node": "^29.6.4",
|
|
62
62
|
"prettier": "^2.8.3",
|
|
63
|
-
"release-it": "^
|
|
63
|
+
"release-it": "^17.6.0",
|
|
64
64
|
"rollup": "^4.5.2",
|
|
65
65
|
"ts-jest": "^29.1.0",
|
|
66
66
|
"typescript": "<5.2.0",
|