@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.
@@ -702,6 +702,7 @@ class ChatGoogleGenerativeAI extends chat_models_1.BaseChatModel {
702
702
  }
703
703
  const llm = this.bind({
704
704
  tools,
705
+ tool_choice: functionName,
705
706
  });
706
707
  if (!includeRaw) {
707
708
  return llm.pipe(outputParser).withConfig({
@@ -699,6 +699,7 @@ export class ChatGoogleGenerativeAI extends BaseChatModel {
699
699
  }
700
700
  const llm = this.bind({
701
701
  tools,
702
+ tool_choice: functionName,
702
703
  });
703
704
  if (!includeRaw) {
704
705
  return llm.pipe(outputParser).withConfig({
@@ -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;
@@ -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;
@@ -11,6 +11,9 @@ obj) {
11
11
  if ("additionalProperties" in newObj) {
12
12
  delete newObj.additionalProperties;
13
13
  }
14
+ if ("$schema" in newObj) {
15
+ delete newObj.$schema;
16
+ }
14
17
  for (const key in newObj) {
15
18
  if (key in newObj) {
16
19
  if (Array.isArray(newObj[key])) {
@@ -8,6 +8,9 @@ obj) {
8
8
  if ("additionalProperties" in newObj) {
9
9
  delete newObj.additionalProperties;
10
10
  }
11
+ if ("$schema" in newObj) {
12
+ delete newObj.$schema;
13
+ }
11
14
  for (const key in newObj) {
12
15
  if (key in newObj) {
13
16
  if (Array.isArray(newObj[key])) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/google-genai",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Google Generative AI integration for LangChain.js",
5
5
  "type": "module",
6
6
  "engines": {