@langchain/google-genai 0.2.18 → 1.0.0
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/CHANGELOG.md +11 -0
- package/LICENSE +6 -6
- package/README.md +8 -8
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/chat_models.cjs +667 -847
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +556 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +171 -157
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +665 -842
- package/dist/chat_models.js.map +1 -0
- package/dist/embeddings.cjs +97 -151
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +104 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +76 -70
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +93 -144
- package/dist/embeddings.js.map +1 -0
- package/dist/index.cjs +5 -18
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -2
- package/dist/output_parsers.cjs +47 -75
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.js +47 -72
- package/dist/output_parsers.js.map +1 -0
- package/dist/types.d.cts +8 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/common.cjs +356 -549
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.js +357 -545
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/tools.cjs +65 -102
- package/dist/utils/tools.cjs.map +1 -0
- package/dist/utils/tools.js +64 -99
- package/dist/utils/tools.js.map +1 -0
- package/dist/utils/zod_to_genai_parameters.cjs +31 -49
- package/dist/utils/zod_to_genai_parameters.cjs.map +1 -0
- package/dist/utils/zod_to_genai_parameters.js +29 -45
- package/dist/utils/zod_to_genai_parameters.js.map +1 -0
- package/package.json +42 -51
- package/dist/output_parsers.d.ts +0 -20
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -1
- package/dist/utils/common.d.ts +0 -22
- package/dist/utils/tools.d.ts +0 -10
- package/dist/utils/zod_to_genai_parameters.d.ts +0 -14
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/dist/output_parsers.js
CHANGED
|
@@ -1,72 +1,47 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);
|
|
50
|
-
if (zodParsedResult.success) {
|
|
51
|
-
return zodParsedResult.data;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
throw new OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, JSON.stringify(result, null, 2));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async parseResult(generations) {
|
|
58
|
-
const tools = generations.flatMap((generation) => {
|
|
59
|
-
const { message } = generation;
|
|
60
|
-
if (!("tool_calls" in message) || !Array.isArray(message.tool_calls)) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
return message.tool_calls;
|
|
64
|
-
});
|
|
65
|
-
if (tools[0] === undefined) {
|
|
66
|
-
throw new Error("No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.");
|
|
67
|
-
}
|
|
68
|
-
const [tool] = tools;
|
|
69
|
-
const validatedResult = await this._validateResult(tool.args);
|
|
70
|
-
return validatedResult;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
import { interopSafeParseAsync } from "@langchain/core/utils/types";
|
|
2
|
+
import { BaseLLMOutputParser, OutputParserException } from "@langchain/core/output_parsers";
|
|
3
|
+
|
|
4
|
+
//#region src/output_parsers.ts
|
|
5
|
+
var GoogleGenerativeAIToolsOutputParser = class extends BaseLLMOutputParser {
|
|
6
|
+
static lc_name() {
|
|
7
|
+
return "GoogleGenerativeAIToolsOutputParser";
|
|
8
|
+
}
|
|
9
|
+
lc_namespace = [
|
|
10
|
+
"langchain",
|
|
11
|
+
"google_genai",
|
|
12
|
+
"output_parsers"
|
|
13
|
+
];
|
|
14
|
+
returnId = false;
|
|
15
|
+
/** The type of tool calls to return. */
|
|
16
|
+
keyName;
|
|
17
|
+
/** Whether to return only the first tool call. */
|
|
18
|
+
returnSingle = false;
|
|
19
|
+
zodSchema;
|
|
20
|
+
constructor(params) {
|
|
21
|
+
super(params);
|
|
22
|
+
this.keyName = params.keyName;
|
|
23
|
+
this.returnSingle = params.returnSingle ?? this.returnSingle;
|
|
24
|
+
this.zodSchema = params.zodSchema;
|
|
25
|
+
}
|
|
26
|
+
async _validateResult(result) {
|
|
27
|
+
if (this.zodSchema === void 0) return result;
|
|
28
|
+
const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);
|
|
29
|
+
if (zodParsedResult.success) return zodParsedResult.data;
|
|
30
|
+
else throw new OutputParserException(`Failed to parse. Text: "${JSON.stringify(result, null, 2)}". Error: ${JSON.stringify(zodParsedResult.error.issues)}`, JSON.stringify(result, null, 2));
|
|
31
|
+
}
|
|
32
|
+
async parseResult(generations) {
|
|
33
|
+
const tools = generations.flatMap((generation) => {
|
|
34
|
+
const { message } = generation;
|
|
35
|
+
if (!("tool_calls" in message) || !Array.isArray(message.tool_calls)) return [];
|
|
36
|
+
return message.tool_calls;
|
|
37
|
+
});
|
|
38
|
+
if (tools[0] === void 0) throw new Error("No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.");
|
|
39
|
+
const [tool] = tools;
|
|
40
|
+
const validatedResult = await this._validateResult(tool.args);
|
|
41
|
+
return validatedResult;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { GoogleGenerativeAIToolsOutputParser };
|
|
47
|
+
//# sourceMappingURL=output_parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output_parsers.js","names":["params: GoogleGenerativeAIToolsOutputParserParams<T>","result: unknown","generations: ChatGeneration[]"],"sources":["../src/output_parsers.ts"],"sourcesContent":["import {\n BaseLLMOutputParser,\n OutputParserException,\n} from \"@langchain/core/output_parsers\";\nimport { ChatGeneration } from \"@langchain/core/outputs\";\nimport { ToolCall } from \"@langchain/core/messages/tool\";\nimport {\n InteropZodType,\n interopSafeParseAsync,\n} from \"@langchain/core/utils/types\";\nimport { JsonOutputKeyToolsParserParamsInterop } from \"@langchain/core/output_parsers/openai_tools\";\n\ninterface GoogleGenerativeAIToolsOutputParserParams<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any>\n> extends JsonOutputKeyToolsParserParamsInterop<T> {}\n\nexport class GoogleGenerativeAIToolsOutputParser<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T extends Record<string, any> = Record<string, any>\n> extends BaseLLMOutputParser<T> {\n static lc_name() {\n return \"GoogleGenerativeAIToolsOutputParser\";\n }\n\n lc_namespace = [\"langchain\", \"google_genai\", \"output_parsers\"];\n\n returnId = false;\n\n /** The type of tool calls to return. */\n keyName: string;\n\n /** Whether to return only the first tool call. */\n returnSingle = false;\n\n zodSchema?: InteropZodType<T>;\n\n constructor(params: GoogleGenerativeAIToolsOutputParserParams<T>) {\n super(params);\n this.keyName = params.keyName;\n this.returnSingle = params.returnSingle ?? this.returnSingle;\n this.zodSchema = params.zodSchema;\n }\n\n protected async _validateResult(result: unknown): Promise<T> {\n if (this.zodSchema === undefined) {\n return result as T;\n }\n const zodParsedResult = await interopSafeParseAsync(this.zodSchema, result);\n if (zodParsedResult.success) {\n return zodParsedResult.data;\n } else {\n throw new OutputParserException(\n `Failed to parse. Text: \"${JSON.stringify(\n result,\n null,\n 2\n )}\". Error: ${JSON.stringify(zodParsedResult.error.issues)}`,\n JSON.stringify(result, null, 2)\n );\n }\n }\n\n async parseResult(generations: ChatGeneration[]): Promise<T> {\n const tools = generations.flatMap((generation) => {\n const { message } = generation;\n if (!(\"tool_calls\" in message) || !Array.isArray(message.tool_calls)) {\n return [];\n }\n return message.tool_calls as ToolCall[];\n });\n if (tools[0] === undefined) {\n throw new Error(\n \"No parseable tool calls provided to GoogleGenerativeAIToolsOutputParser.\"\n );\n }\n const [tool] = tools;\n const validatedResult = await this._validateResult(tool.args);\n return validatedResult;\n }\n}\n"],"mappings":";;;;AAiBA,IAAa,sCAAb,cAGU,oBAAuB;CAC/B,OAAO,UAAU;AACf,SAAO;CACR;CAED,eAAe;EAAC;EAAa;EAAgB;CAAiB;CAE9D,WAAW;;CAGX;;CAGA,eAAe;CAEf;CAEA,YAAYA,QAAsD;EAChE,MAAM,OAAO;EACb,KAAK,UAAU,OAAO;EACtB,KAAK,eAAe,OAAO,gBAAgB,KAAK;EAChD,KAAK,YAAY,OAAO;CACzB;CAED,MAAgB,gBAAgBC,QAA6B;AAC3D,MAAI,KAAK,cAAc,OACrB,QAAO;EAET,MAAM,kBAAkB,MAAM,sBAAsB,KAAK,WAAW,OAAO;AAC3E,MAAI,gBAAgB,QAClB,QAAO,gBAAgB;MAEvB,OAAM,IAAI,sBACR,CAAC,wBAAwB,EAAE,KAAK,UAC9B,QACA,MACA,EACD,CAAC,UAAU,EAAE,KAAK,UAAU,gBAAgB,MAAM,OAAO,EAAE,EAC5D,KAAK,UAAU,QAAQ,MAAM,EAAE;CAGpC;CAED,MAAM,YAAYC,aAA2C;EAC3D,MAAM,QAAQ,YAAY,QAAQ,CAAC,eAAe;GAChD,MAAM,EAAE,SAAS,GAAG;AACpB,OAAI,EAAE,gBAAgB,YAAY,CAAC,MAAM,QAAQ,QAAQ,WAAW,CAClE,QAAO,CAAE;AAEX,UAAO,QAAQ;EAChB,EAAC;AACF,MAAI,MAAM,OAAO,OACf,OAAM,IAAI,MACR;EAGJ,MAAM,CAAC,KAAK,GAAG;EACf,MAAM,kBAAkB,MAAM,KAAK,gBAAgB,KAAK,KAAK;AAC7D,SAAO;CACR;AACF"}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CodeExecutionTool, FunctionDeclarationsTool, GoogleSearchRetrievalTool } from "@google/generative-ai";
|
|
2
|
+
import { BindToolsInput } from "@langchain/core/language_models/chat_models";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type GoogleGenerativeAIToolType = BindToolsInput | FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { GoogleGenerativeAIToolType };
|
|
8
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":["CodeExecutionTool","FunctionDeclarationsTool","GoogleGenerativeAIFunctionDeclarationsTool","GoogleSearchRetrievalTool","BindToolsInput","GoogleGenerativeAIToolType"],"sources":["../src/types.d.ts"],"sourcesContent":["import { CodeExecutionTool, FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, GoogleSearchRetrievalTool } from \"@google/generative-ai\";\nimport { BindToolsInput } from \"@langchain/core/language_models/chat_models\";\nexport type GoogleGenerativeAIToolType = BindToolsInput | GoogleGenerativeAIFunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;\n"],"mappings":";;;;KAEYK,0BAAAA,GAA6BD,iBAAiBF,2BAA6CF,oBAAoBG"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import { CodeExecutionTool, FunctionDeclarationsTool
|
|
1
|
+
import { CodeExecutionTool, FunctionDeclarationsTool, GoogleSearchRetrievalTool } from "@google/generative-ai";
|
|
2
2
|
import { BindToolsInput } from "@langchain/core/language_models/chat_models";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type GoogleGenerativeAIToolType = BindToolsInput | FunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { GoogleGenerativeAIToolType };
|
|
8
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":["CodeExecutionTool","FunctionDeclarationsTool","GoogleGenerativeAIFunctionDeclarationsTool","GoogleSearchRetrievalTool","BindToolsInput","GoogleGenerativeAIToolType"],"sources":["../src/types.d.ts"],"sourcesContent":["import { CodeExecutionTool, FunctionDeclarationsTool as GoogleGenerativeAIFunctionDeclarationsTool, GoogleSearchRetrievalTool } from \"@google/generative-ai\";\nimport { BindToolsInput } from \"@langchain/core/language_models/chat_models\";\nexport type GoogleGenerativeAIToolType = BindToolsInput | GoogleGenerativeAIFunctionDeclarationsTool | CodeExecutionTool | GoogleSearchRetrievalTool;\n"],"mappings":";;;;KAEYK,0BAAAA,GAA6BD,iBAAiBF,2BAA6CF,oBAAoBG"}
|