|
| 1 | +import { z } from "zod"; |
| 2 | +import { DynamicStructuredTool } from "@langchain/core/tools"; |
1 | 3 | import { ChatMistralAI } from "../chat_models.js";
|
2 | 4 | import {
|
3 | 5 | _isValidMistralToolCallId,
|
@@ -30,6 +32,55 @@ describe("Mistral Tool Call ID Conversion", () => {
|
30 | 32 | });
|
31 | 33 | });
|
32 | 34 |
|
| 35 | +test("Tool conversion handles both Zod schemas and JSON schemas", () => { |
| 36 | + const model = new ChatMistralAI({ apiKey: "test" }); |
| 37 | + const zodTool = { |
| 38 | + name: "zodTool", |
| 39 | + description: "A tool with Zod schema", |
| 40 | + schema: z.object({ |
| 41 | + input: z.string().describe("Input parameter"), |
| 42 | + }), |
| 43 | + }; |
| 44 | + const jsonSchemaTool = { |
| 45 | + name: "jsonSchemaTool", |
| 46 | + description: "A tool with JSON schema", |
| 47 | + schema: { |
| 48 | + type: "object", |
| 49 | + properties: { |
| 50 | + input: { |
| 51 | + type: "string", |
| 52 | + description: "Input parameter" |
| 53 | + } |
| 54 | + }, |
| 55 | + required: ["input"] |
| 56 | + }, |
| 57 | + }; |
| 58 | + |
| 59 | + expect(() => { |
| 60 | + const modelWithTools = model.bindTools([zodTool, jsonSchemaTool]); |
| 61 | + expect(modelWithTools).toBeDefined(); |
| 62 | + }).not.toThrow(); |
| 63 | + |
| 64 | + const mcpLikeTool = new DynamicStructuredTool({ |
| 65 | + name: "mcpLikeTool", |
| 66 | + description: "Tool similar to MCP tools", |
| 67 | + schema: { |
| 68 | + type: "object", |
| 69 | + properties: { |
| 70 | + city: { type: "string" }, |
| 71 | + }, |
| 72 | + required: ["city"], |
| 73 | + }, |
| 74 | + func: async () => "test result", |
| 75 | + }); |
| 76 | + |
| 77 | + // This should also not throw an error |
| 78 | + expect(() => { |
| 79 | + const modelWithMcpTool = model.bindTools([mcpLikeTool]); |
| 80 | + expect(modelWithMcpTool).toBeDefined(); |
| 81 | + }).not.toThrow(); |
| 82 | +}); |
| 83 | + |
33 | 84 | test("Serialization", () => {
|
34 | 85 | const model = new ChatMistralAI({
|
35 | 86 | apiKey: "foo",
|
|
0 commit comments