@langchain/google-genai 0.0.20 → 0.0.22
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 +3 -3
- package/dist/utils/common.cjs +14 -1
- package/dist/utils/common.d.ts +3 -1
- package/dist/utils/common.js +15 -2
- package/dist/utils/zod_to_genai_parameters.cjs +12 -1
- package/dist/utils/zod_to_genai_parameters.d.ts +1 -0
- package/dist/utils/zod_to_genai_parameters.js +10 -0
- package/package.json +2 -2
package/dist/chat_models.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ 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, LangSmithParams, type BaseChatModelParams } from "@langchain/core/language_models/chat_models";
|
|
6
|
-
import { BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions } from "@langchain/core/language_models/base";
|
|
6
|
+
import { BaseLanguageModelCallOptions, BaseLanguageModelInput, StructuredOutputMethodOptions, ToolDefinition } from "@langchain/core/language_models/base";
|
|
7
7
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
8
|
-
import { Runnable } from "@langchain/core/runnables";
|
|
8
|
+
import { Runnable, RunnableToolLike } from "@langchain/core/runnables";
|
|
9
9
|
import type { z } from "zod";
|
|
10
10
|
export type BaseMessageExamplePair = {
|
|
11
11
|
input: BaseMessage;
|
|
@@ -160,7 +160,7 @@ export declare class ChatGoogleGenerativeAI extends BaseChatModel<GoogleGenerati
|
|
|
160
160
|
getLsParams(options: this["ParsedCallOptions"]): LangSmithParams;
|
|
161
161
|
_combineLLMOutput(): never[];
|
|
162
162
|
_llmType(): string;
|
|
163
|
-
bindTools(tools: (StructuredToolInterface | Record<string, unknown>)[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
|
|
163
|
+
bindTools(tools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition | RunnableToolLike)[], kwargs?: Partial<GoogleGenerativeAIChatCallOptions>): Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>;
|
|
164
164
|
invocationParams(options?: this["ParsedCallOptions"]): Omit<GenerateContentRequest, "contents">;
|
|
165
165
|
_generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
|
|
166
166
|
_streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
|
package/dist/utils/common.cjs
CHANGED
|
@@ -4,6 +4,7 @@ exports.convertToGenerativeAITools = exports.convertResponseContentToChatGenerat
|
|
|
4
4
|
const messages_1 = require("@langchain/core/messages");
|
|
5
5
|
const outputs_1 = require("@langchain/core/outputs");
|
|
6
6
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
7
|
+
const base_1 = require("@langchain/core/language_models/base");
|
|
7
8
|
const zod_to_genai_parameters_js_1 = require("./zod_to_genai_parameters.cjs");
|
|
8
9
|
function getMessageAuthor(message) {
|
|
9
10
|
const type = message._getType();
|
|
@@ -197,7 +198,10 @@ function mapGenerateContentResultToChatResult(response, extra) {
|
|
|
197
198
|
text,
|
|
198
199
|
message: new messages_1.AIMessage({
|
|
199
200
|
content: text,
|
|
200
|
-
tool_calls: functionCalls
|
|
201
|
+
tool_calls: functionCalls?.map((fc) => ({
|
|
202
|
+
...fc,
|
|
203
|
+
type: "tool_call",
|
|
204
|
+
})),
|
|
201
205
|
additional_kwargs: {
|
|
202
206
|
...generationInfo,
|
|
203
207
|
},
|
|
@@ -224,6 +228,7 @@ function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
|
224
228
|
...fc,
|
|
225
229
|
args: JSON.stringify(fc.args),
|
|
226
230
|
index: extra.index,
|
|
231
|
+
type: "tool_call_chunk",
|
|
227
232
|
})));
|
|
228
233
|
}
|
|
229
234
|
return new outputs_1.ChatGenerationChunk({
|
|
@@ -257,6 +262,14 @@ function convertToGenerativeAITools(structuredTools) {
|
|
|
257
262
|
parameters: jsonSchema,
|
|
258
263
|
};
|
|
259
264
|
}
|
|
265
|
+
if ((0, base_1.isOpenAITool)(structuredTool)) {
|
|
266
|
+
return {
|
|
267
|
+
name: structuredTool.function.name,
|
|
268
|
+
description: structuredTool.function.description ??
|
|
269
|
+
`A function available to call.`,
|
|
270
|
+
parameters: (0, zod_to_genai_parameters_js_1.jsonSchemaToGeminiParameters)(structuredTool.function.parameters),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
260
273
|
return structuredTool;
|
|
261
274
|
}),
|
|
262
275
|
},
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { EnhancedGenerateContentResponse, Content, Part, type FunctionDeclaratio
|
|
|
2
2
|
import { BaseMessage, UsageMetadata } from "@langchain/core/messages";
|
|
3
3
|
import { ChatGenerationChunk, ChatResult } from "@langchain/core/outputs";
|
|
4
4
|
import { StructuredToolInterface } from "@langchain/core/tools";
|
|
5
|
+
import { ToolDefinition } from "@langchain/core/language_models/base";
|
|
6
|
+
import { RunnableToolLike } from "@langchain/core/runnables";
|
|
5
7
|
export declare function getMessageAuthor(message: BaseMessage): string;
|
|
6
8
|
/**
|
|
7
9
|
* Maps a message type to a Google Generative AI chat author.
|
|
@@ -19,4 +21,4 @@ export declare function convertResponseContentToChatGenerationChunk(response: En
|
|
|
19
21
|
usageMetadata?: UsageMetadata | undefined;
|
|
20
22
|
index: number;
|
|
21
23
|
}): ChatGenerationChunk | null;
|
|
22
|
-
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown>)[]): GoogleGenerativeAIFunctionDeclarationsTool[];
|
|
24
|
+
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition | RunnableToolLike)[]): GoogleGenerativeAIFunctionDeclarationsTool[];
|
package/dist/utils/common.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AIMessage, AIMessageChunk, ChatMessage, isBaseMessage, } from "@langchain/core/messages";
|
|
2
2
|
import { ChatGenerationChunk, } from "@langchain/core/outputs";
|
|
3
3
|
import { isStructuredTool } from "@langchain/core/utils/function_calling";
|
|
4
|
-
import {
|
|
4
|
+
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
5
|
+
import { jsonSchemaToGeminiParameters, zodToGenerativeAIParameters, } from "./zod_to_genai_parameters.js";
|
|
5
6
|
export function getMessageAuthor(message) {
|
|
6
7
|
const type = message._getType();
|
|
7
8
|
if (ChatMessage.isInstance(message)) {
|
|
@@ -190,7 +191,10 @@ export function mapGenerateContentResultToChatResult(response, extra) {
|
|
|
190
191
|
text,
|
|
191
192
|
message: new AIMessage({
|
|
192
193
|
content: text,
|
|
193
|
-
tool_calls: functionCalls
|
|
194
|
+
tool_calls: functionCalls?.map((fc) => ({
|
|
195
|
+
...fc,
|
|
196
|
+
type: "tool_call",
|
|
197
|
+
})),
|
|
194
198
|
additional_kwargs: {
|
|
195
199
|
...generationInfo,
|
|
196
200
|
},
|
|
@@ -216,6 +220,7 @@ export function convertResponseContentToChatGenerationChunk(response, extra) {
|
|
|
216
220
|
...fc,
|
|
217
221
|
args: JSON.stringify(fc.args),
|
|
218
222
|
index: extra.index,
|
|
223
|
+
type: "tool_call_chunk",
|
|
219
224
|
})));
|
|
220
225
|
}
|
|
221
226
|
return new ChatGenerationChunk({
|
|
@@ -248,6 +253,14 @@ export function convertToGenerativeAITools(structuredTools) {
|
|
|
248
253
|
parameters: jsonSchema,
|
|
249
254
|
};
|
|
250
255
|
}
|
|
256
|
+
if (isOpenAITool(structuredTool)) {
|
|
257
|
+
return {
|
|
258
|
+
name: structuredTool.function.name,
|
|
259
|
+
description: structuredTool.function.description ??
|
|
260
|
+
`A function available to call.`,
|
|
261
|
+
parameters: jsonSchemaToGeminiParameters(structuredTool.function.parameters),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
251
264
|
return structuredTool;
|
|
252
265
|
}),
|
|
253
266
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.zodToGenerativeAIParameters = exports.removeAdditionalProperties = void 0;
|
|
4
|
+
exports.jsonSchemaToGeminiParameters = exports.zodToGenerativeAIParameters = exports.removeAdditionalProperties = void 0;
|
|
5
5
|
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
6
6
|
function removeAdditionalProperties(
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -37,3 +37,14 @@ zodObj) {
|
|
|
37
37
|
return rest;
|
|
38
38
|
}
|
|
39
39
|
exports.zodToGenerativeAIParameters = zodToGenerativeAIParameters;
|
|
40
|
+
function jsonSchemaToGeminiParameters(
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
schema) {
|
|
43
|
+
// Gemini doesn't accept either the $schema or additionalProperties
|
|
44
|
+
// attributes, so we need to explicitly remove them.
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
const jsonSchema = removeAdditionalProperties(schema);
|
|
47
|
+
const { $schema, ...rest } = jsonSchema;
|
|
48
|
+
return rest;
|
|
49
|
+
}
|
|
50
|
+
exports.jsonSchemaToGeminiParameters = jsonSchemaToGeminiParameters;
|
|
@@ -10,3 +10,4 @@ export interface GenerativeAIJsonSchemaDirty extends GenerativeAIJsonSchema {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function removeAdditionalProperties(obj: Record<string, any>): GenerativeAIJsonSchema;
|
|
12
12
|
export declare function zodToGenerativeAIParameters(zodObj: z.ZodType<any>): GenerativeAIFunctionDeclarationSchema;
|
|
13
|
+
export declare function jsonSchemaToGeminiParameters(schema: Record<string, any>): GenerativeAIFunctionDeclarationSchema;
|
|
@@ -32,3 +32,13 @@ zodObj) {
|
|
|
32
32
|
const { $schema, ...rest } = jsonSchema;
|
|
33
33
|
return rest;
|
|
34
34
|
}
|
|
35
|
+
export function jsonSchemaToGeminiParameters(
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
schema) {
|
|
38
|
+
// Gemini doesn't accept either the $schema or additionalProperties
|
|
39
|
+
// attributes, so we need to explicitly remove them.
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
const jsonSchema = removeAdditionalProperties(schema);
|
|
42
|
+
const { $schema, ...rest } = jsonSchema;
|
|
43
|
+
return rest;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google-genai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "Sample integration for LangChain.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -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.16 <0.3.0",
|
|
40
40
|
"zod-to-json-schema": "^3.22.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|