@langchain/google-genai 0.1.3 → 0.1.4
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
CHANGED
package/dist/chat_models.js
CHANGED
package/dist/utils/tools.cjs
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.convertToolsToGenAI = void 0;
|
|
4
4
|
const generative_ai_1 = require("@google/generative-ai");
|
|
5
5
|
const function_calling_1 = require("@langchain/core/utils/function_calling");
|
|
6
|
+
const base_1 = require("@langchain/core/language_models/base");
|
|
6
7
|
const common_js_1 = require("./common.cjs");
|
|
8
|
+
const zod_to_genai_parameters_js_1 = require("./zod_to_genai_parameters.cjs");
|
|
7
9
|
function convertToolsToGenAI(tools, extra) {
|
|
8
10
|
// Extract function declaration processing to a separate function
|
|
9
11
|
const genAITools = processTools(tools);
|
|
@@ -24,6 +26,15 @@ function processTools(tools) {
|
|
|
24
26
|
functionDeclarationTools.push(...convertedTool.functionDeclarations);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
29
|
+
else if ((0, base_1.isOpenAITool)(tool)) {
|
|
30
|
+
const { functionDeclarations } = convertOpenAIToolToGenAI(tool);
|
|
31
|
+
if (functionDeclarations) {
|
|
32
|
+
functionDeclarationTools.push(...functionDeclarations);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error("Failed to convert OpenAI structured tool to GenerativeAI tool");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
else {
|
|
28
39
|
genAITools.push(tool);
|
|
29
40
|
}
|
|
@@ -57,6 +68,17 @@ function processTools(tools) {
|
|
|
57
68
|
: []),
|
|
58
69
|
];
|
|
59
70
|
}
|
|
71
|
+
function convertOpenAIToolToGenAI(tool) {
|
|
72
|
+
return {
|
|
73
|
+
functionDeclarations: [
|
|
74
|
+
{
|
|
75
|
+
name: tool.function.name,
|
|
76
|
+
description: tool.function.description,
|
|
77
|
+
parameters: (0, zod_to_genai_parameters_js_1.removeAdditionalProperties)(tool.function.parameters),
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
};
|
|
81
|
+
}
|
|
60
82
|
function createToolConfig(genAITools, extra) {
|
|
61
83
|
if (!genAITools.length || !extra)
|
|
62
84
|
return undefined;
|
package/dist/utils/tools.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { FunctionCallingMode, } from "@google/generative-ai";
|
|
2
2
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
3
|
+
import { isOpenAITool, } from "@langchain/core/language_models/base";
|
|
3
4
|
import { convertToGenerativeAITools } from "./common.js";
|
|
5
|
+
import { removeAdditionalProperties } from "./zod_to_genai_parameters.js";
|
|
4
6
|
export function convertToolsToGenAI(tools, extra) {
|
|
5
7
|
// Extract function declaration processing to a separate function
|
|
6
8
|
const genAITools = processTools(tools);
|
|
@@ -20,6 +22,15 @@ function processTools(tools) {
|
|
|
20
22
|
functionDeclarationTools.push(...convertedTool.functionDeclarations);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
25
|
+
else if (isOpenAITool(tool)) {
|
|
26
|
+
const { functionDeclarations } = convertOpenAIToolToGenAI(tool);
|
|
27
|
+
if (functionDeclarations) {
|
|
28
|
+
functionDeclarationTools.push(...functionDeclarations);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error("Failed to convert OpenAI structured tool to GenerativeAI tool");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
23
34
|
else {
|
|
24
35
|
genAITools.push(tool);
|
|
25
36
|
}
|
|
@@ -53,6 +64,17 @@ function processTools(tools) {
|
|
|
53
64
|
: []),
|
|
54
65
|
];
|
|
55
66
|
}
|
|
67
|
+
function convertOpenAIToolToGenAI(tool) {
|
|
68
|
+
return {
|
|
69
|
+
functionDeclarations: [
|
|
70
|
+
{
|
|
71
|
+
name: tool.function.name,
|
|
72
|
+
description: tool.function.description,
|
|
73
|
+
parameters: removeAdditionalProperties(tool.function.parameters),
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
}
|
|
56
78
|
function createToolConfig(genAITools, extra) {
|
|
57
79
|
if (!genAITools.length || !extra)
|
|
58
80
|
return undefined;
|