@langchain/google-genai 0.0.20 → 0.0.21
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 +2 -2
- package/dist/utils/common.cjs +9 -0
- package/dist/utils/common.d.ts +2 -1
- package/dist/utils/common.js +10 -1
- 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,7 +3,7 @@ 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
8
|
import { Runnable } from "@langchain/core/runnables";
|
|
9
9
|
import type { z } from "zod";
|
|
@@ -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)[], 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();
|
|
@@ -257,6 +258,14 @@ function convertToGenerativeAITools(structuredTools) {
|
|
|
257
258
|
parameters: jsonSchema,
|
|
258
259
|
};
|
|
259
260
|
}
|
|
261
|
+
if ((0, base_1.isOpenAITool)(structuredTool)) {
|
|
262
|
+
return {
|
|
263
|
+
name: structuredTool.function.name,
|
|
264
|
+
description: structuredTool.function.description ??
|
|
265
|
+
`A function available to call.`,
|
|
266
|
+
parameters: (0, zod_to_genai_parameters_js_1.jsonSchemaToGeminiParameters)(structuredTool.function.parameters),
|
|
267
|
+
};
|
|
268
|
+
}
|
|
260
269
|
return structuredTool;
|
|
261
270
|
}),
|
|
262
271
|
},
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ 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";
|
|
5
6
|
export declare function getMessageAuthor(message: BaseMessage): string;
|
|
6
7
|
/**
|
|
7
8
|
* Maps a message type to a Google Generative AI chat author.
|
|
@@ -19,4 +20,4 @@ export declare function convertResponseContentToChatGenerationChunk(response: En
|
|
|
19
20
|
usageMetadata?: UsageMetadata | undefined;
|
|
20
21
|
index: number;
|
|
21
22
|
}): ChatGenerationChunk | null;
|
|
22
|
-
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown>)[]): GoogleGenerativeAIFunctionDeclarationsTool[];
|
|
23
|
+
export declare function convertToGenerativeAITools(structuredTools: (StructuredToolInterface | Record<string, unknown> | ToolDefinition)[]): 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)) {
|
|
@@ -248,6 +249,14 @@ export function convertToGenerativeAITools(structuredTools) {
|
|
|
248
249
|
parameters: jsonSchema,
|
|
249
250
|
};
|
|
250
251
|
}
|
|
252
|
+
if (isOpenAITool(structuredTool)) {
|
|
253
|
+
return {
|
|
254
|
+
name: structuredTool.function.name,
|
|
255
|
+
description: structuredTool.function.description ??
|
|
256
|
+
`A function available to call.`,
|
|
257
|
+
parameters: jsonSchemaToGeminiParameters(structuredTool.function.parameters),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
251
260
|
return structuredTool;
|
|
252
261
|
}),
|
|
253
262
|
},
|
|
@@ -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.21",
|
|
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.9 <0.3.0",
|
|
40
40
|
"zod-to-json-schema": "^3.22.4"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|