@langchain/google-common 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/types.d.ts +14 -0
- package/dist/utils/common.cjs +34 -23
- package/dist/utils/common.js +34 -23
- package/dist/utils/gemini.cjs +12 -20
- package/dist/utils/gemini.js +12 -20
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -226,6 +226,20 @@ export interface GeminiContent {
|
|
|
226
226
|
}
|
|
227
227
|
export interface GeminiTool {
|
|
228
228
|
functionDeclarations?: GeminiFunctionDeclaration[];
|
|
229
|
+
googleSearchRetrieval?: GoogleSearchRetrieval;
|
|
230
|
+
retrieval?: VertexAIRetrieval;
|
|
231
|
+
}
|
|
232
|
+
export interface GoogleSearchRetrieval {
|
|
233
|
+
dynamicRetrievalConfig?: {
|
|
234
|
+
mode?: string;
|
|
235
|
+
dynamicThreshold?: number;
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
export interface VertexAIRetrieval {
|
|
239
|
+
vertexAiSearch: {
|
|
240
|
+
datastore: string;
|
|
241
|
+
};
|
|
242
|
+
disableAttribution?: boolean;
|
|
229
243
|
}
|
|
230
244
|
export interface GeminiFunctionDeclaration {
|
|
231
245
|
name: string;
|
package/dist/utils/common.cjs
CHANGED
|
@@ -38,31 +38,42 @@ function processToolChoice(toolChoice, allowedFunctionNames) {
|
|
|
38
38
|
throw new Error("Object inputs for tool_choice not supported.");
|
|
39
39
|
}
|
|
40
40
|
function convertToGeminiTools(tools) {
|
|
41
|
-
const geminiTools = [
|
|
42
|
-
|
|
43
|
-
functionDeclarations: [],
|
|
44
|
-
},
|
|
45
|
-
];
|
|
41
|
+
const geminiTools = [];
|
|
42
|
+
let functionDeclarationsIndex = -1;
|
|
46
43
|
tools.forEach((tool) => {
|
|
47
|
-
if ("
|
|
48
|
-
|
|
49
|
-
const funcs = tool.functionDeclarations;
|
|
50
|
-
geminiTools[0].functionDeclarations?.push(...funcs);
|
|
44
|
+
if ("googleSearchRetrieval" in tool || "retrieval" in tool) {
|
|
45
|
+
geminiTools.push(tool);
|
|
51
46
|
}
|
|
52
|
-
else
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
else {
|
|
48
|
+
if (functionDeclarationsIndex === -1) {
|
|
49
|
+
geminiTools.push({
|
|
50
|
+
functionDeclarations: [],
|
|
51
|
+
});
|
|
52
|
+
functionDeclarationsIndex = geminiTools.length - 1;
|
|
53
|
+
}
|
|
54
|
+
if ("functionDeclarations" in tool &&
|
|
55
|
+
Array.isArray(tool.functionDeclarations)) {
|
|
56
|
+
const funcs = tool.functionDeclarations;
|
|
57
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
58
|
+
}
|
|
59
|
+
else if ((0, function_calling_1.isLangChainTool)(tool)) {
|
|
60
|
+
const jsonSchema = (0, zod_to_gemini_parameters_js_1.zodToGeminiParameters)(tool.schema);
|
|
61
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
62
|
+
name: tool.name,
|
|
63
|
+
description: tool.description ?? `A function available to call.`,
|
|
64
|
+
parameters: jsonSchema,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if ((0, base_1.isOpenAITool)(tool)) {
|
|
68
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
69
|
+
name: tool.function.name,
|
|
70
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
71
|
+
parameters: (0, zod_to_gemini_parameters_js_1.jsonSchemaToGeminiParameters)(tool.function.parameters),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
76
|
+
}
|
|
66
77
|
}
|
|
67
78
|
});
|
|
68
79
|
return geminiTools;
|
package/dist/utils/common.js
CHANGED
|
@@ -34,31 +34,42 @@ function processToolChoice(toolChoice, allowedFunctionNames) {
|
|
|
34
34
|
throw new Error("Object inputs for tool_choice not supported.");
|
|
35
35
|
}
|
|
36
36
|
export function convertToGeminiTools(tools) {
|
|
37
|
-
const geminiTools = [
|
|
38
|
-
|
|
39
|
-
functionDeclarations: [],
|
|
40
|
-
},
|
|
41
|
-
];
|
|
37
|
+
const geminiTools = [];
|
|
38
|
+
let functionDeclarationsIndex = -1;
|
|
42
39
|
tools.forEach((tool) => {
|
|
43
|
-
if ("
|
|
44
|
-
|
|
45
|
-
const funcs = tool.functionDeclarations;
|
|
46
|
-
geminiTools[0].functionDeclarations?.push(...funcs);
|
|
40
|
+
if ("googleSearchRetrieval" in tool || "retrieval" in tool) {
|
|
41
|
+
geminiTools.push(tool);
|
|
47
42
|
}
|
|
48
|
-
else
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
else {
|
|
44
|
+
if (functionDeclarationsIndex === -1) {
|
|
45
|
+
geminiTools.push({
|
|
46
|
+
functionDeclarations: [],
|
|
47
|
+
});
|
|
48
|
+
functionDeclarationsIndex = geminiTools.length - 1;
|
|
49
|
+
}
|
|
50
|
+
if ("functionDeclarations" in tool &&
|
|
51
|
+
Array.isArray(tool.functionDeclarations)) {
|
|
52
|
+
const funcs = tool.functionDeclarations;
|
|
53
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
54
|
+
}
|
|
55
|
+
else if (isLangChainTool(tool)) {
|
|
56
|
+
const jsonSchema = zodToGeminiParameters(tool.schema);
|
|
57
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
58
|
+
name: tool.name,
|
|
59
|
+
description: tool.description ?? `A function available to call.`,
|
|
60
|
+
parameters: jsonSchema,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else if (isOpenAITool(tool)) {
|
|
64
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
65
|
+
name: tool.function.name,
|
|
66
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
67
|
+
parameters: jsonSchemaToGeminiParameters(tool.function.parameters),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
72
|
+
}
|
|
62
73
|
}
|
|
63
74
|
});
|
|
64
75
|
return geminiTools;
|
package/dist/utils/gemini.cjs
CHANGED
|
@@ -141,10 +141,10 @@ function getGeminiAPI(config) {
|
|
|
141
141
|
if (!url) {
|
|
142
142
|
throw new Error("Missing Image URL");
|
|
143
143
|
}
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
144
|
+
const mimeTypeAndData = extractMimeType(url);
|
|
145
|
+
if (mimeTypeAndData) {
|
|
146
146
|
return {
|
|
147
|
-
inlineData:
|
|
147
|
+
inlineData: mimeTypeAndData,
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
@@ -788,29 +788,21 @@ function getGeminiAPI(config) {
|
|
|
788
788
|
parameters: jsonSchema,
|
|
789
789
|
};
|
|
790
790
|
}
|
|
791
|
-
function structuredToolsToGeminiTools(tools) {
|
|
792
|
-
return [
|
|
793
|
-
{
|
|
794
|
-
functionDeclarations: tools.map(structuredToolToFunctionDeclaration),
|
|
795
|
-
},
|
|
796
|
-
];
|
|
797
|
-
}
|
|
798
791
|
function formatTools(parameters) {
|
|
799
792
|
const tools = parameters?.tools;
|
|
800
793
|
if (!tools || tools.length === 0) {
|
|
801
794
|
return [];
|
|
802
795
|
}
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
}
|
|
812
|
-
return tools;
|
|
796
|
+
// Group all LangChain tools into a single functionDeclarations array
|
|
797
|
+
const langChainTools = tools.filter(function_calling_1.isLangChainTool);
|
|
798
|
+
const otherTools = tools.filter((tool) => !(0, function_calling_1.isLangChainTool)(tool));
|
|
799
|
+
const result = [...otherTools];
|
|
800
|
+
if (langChainTools.length > 0) {
|
|
801
|
+
result.push({
|
|
802
|
+
functionDeclarations: langChainTools.map(structuredToolToFunctionDeclaration),
|
|
803
|
+
});
|
|
813
804
|
}
|
|
805
|
+
return result;
|
|
814
806
|
}
|
|
815
807
|
function formatToolConfig(parameters) {
|
|
816
808
|
if (!parameters.tool_choice || typeof parameters.tool_choice !== "string") {
|
package/dist/utils/gemini.js
CHANGED
|
@@ -136,10 +136,10 @@ export function getGeminiAPI(config) {
|
|
|
136
136
|
if (!url) {
|
|
137
137
|
throw new Error("Missing Image URL");
|
|
138
138
|
}
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
139
|
+
const mimeTypeAndData = extractMimeType(url);
|
|
140
|
+
if (mimeTypeAndData) {
|
|
141
141
|
return {
|
|
142
|
-
inlineData:
|
|
142
|
+
inlineData: mimeTypeAndData,
|
|
143
143
|
};
|
|
144
144
|
}
|
|
145
145
|
else {
|
|
@@ -783,29 +783,21 @@ export function getGeminiAPI(config) {
|
|
|
783
783
|
parameters: jsonSchema,
|
|
784
784
|
};
|
|
785
785
|
}
|
|
786
|
-
function structuredToolsToGeminiTools(tools) {
|
|
787
|
-
return [
|
|
788
|
-
{
|
|
789
|
-
functionDeclarations: tools.map(structuredToolToFunctionDeclaration),
|
|
790
|
-
},
|
|
791
|
-
];
|
|
792
|
-
}
|
|
793
786
|
function formatTools(parameters) {
|
|
794
787
|
const tools = parameters?.tools;
|
|
795
788
|
if (!tools || tools.length === 0) {
|
|
796
789
|
return [];
|
|
797
790
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
return tools;
|
|
791
|
+
// Group all LangChain tools into a single functionDeclarations array
|
|
792
|
+
const langChainTools = tools.filter(isLangChainTool);
|
|
793
|
+
const otherTools = tools.filter((tool) => !isLangChainTool(tool));
|
|
794
|
+
const result = [...otherTools];
|
|
795
|
+
if (langChainTools.length > 0) {
|
|
796
|
+
result.push({
|
|
797
|
+
functionDeclarations: langChainTools.map(structuredToolToFunctionDeclaration),
|
|
798
|
+
});
|
|
808
799
|
}
|
|
800
|
+
return result;
|
|
809
801
|
}
|
|
810
802
|
function formatToolConfig(parameters) {
|
|
811
803
|
if (!parameters.tool_choice || typeof parameters.tool_choice !== "string") {
|