@langchain/google-genai 0.0.24 → 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.d.ts +6 -6
- 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 +4 -4
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
5
|
import { BaseChatModel, type BaseChatModelCallOptions, type LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
|
-
import { BaseLanguageModelInput, StructuredOutputMethodOptions
|
|
7
|
-
import {
|
|
8
|
-
import { Runnable, RunnableToolLike } from "@langchain/core/runnables";
|
|
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
14
|
export interface GoogleGenerativeAIChatCallOptions extends BaseChatModelCallOptions {
|
|
15
|
-
tools?:
|
|
15
|
+
tools?: GoogleGenerativeAIToolType[];
|
|
16
16
|
/**
|
|
17
17
|
* Whether or not to include usage data, like token counts
|
|
18
18
|
* in the streamed response chunks.
|
|
@@ -164,7 +164,7 @@ export declare class ChatGoogleGenerativeAI extends BaseChatModel<GoogleGenerati
|
|
|
164
164
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
165
165
|
_combineLLMOutput(): never[];
|
|
166
166
|
_llmType(): string;
|
|
167
|
-
bindTools(tools:
|
|
167
|
+
bindTools(tools: GoogleGenerativeAIToolType[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
|
|
168
168
|
invocationParams(options?: this["ParsedCallOptions"]): Omit<GenerateContentRequest, "contents">;
|
|
169
169
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
170
170
|
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
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"
|
|
@@ -36,7 +36,7 @@
|
|
|
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": {
|
|
@@ -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",
|