From ffedf9a8eaba67d852a6bece713b49b4c174e90d Mon Sep 17 00:00:00 2001 From: bracesproul Date: Wed, 12 Jun 2024 13:31:03 -0700 Subject: [PATCH] only use oai type for tools in wso base implementation --- .../src/language_models/chat_models.ts | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/langchain-core/src/language_models/chat_models.ts b/langchain-core/src/language_models/chat_models.ts index c7c75d23f391..25b0a1467245 100644 --- a/langchain-core/src/language_models/chat_models.ts +++ b/langchain-core/src/language_models/chat_models.ts @@ -1,4 +1,5 @@ import { z } from "zod"; +import { zodToJsonSchema } from "zod-to-json-schema"; import { AIMessage, type BaseMessage, @@ -32,7 +33,7 @@ import { } from "../callbacks/manager.js"; import type { RunnableConfig } from "../runnables/config.js"; import type { BaseCache } from "../caches.js"; -import { StructuredTool, StructuredToolInterface } from "../tools.js"; +import { StructuredToolInterface } from "../tools.js"; import { Runnable, RunnableLambda, @@ -778,6 +779,7 @@ export abstract class BaseChatModel< // eslint-disable-next-line @typescript-eslint/no-explicit-any const schema: z.ZodType | Record = outputSchema; const name = config?.name; + const description = schema.description ?? "A function available to call."; const method = config?.method; const includeRaw = config?.includeRaw; if (method === "jsonMode") { @@ -787,25 +789,22 @@ export abstract class BaseChatModel< } let functionName = name ?? "extract"; - let tools: StructuredTool[] | ToolDefinition[]; + let tools: ToolDefinition[]; if (isZodSchema(schema)) { - class Tool extends StructuredTool { - name = functionName; - - description = schema.description ?? "A function available to call."; - - schema = schema as z.ZodObject; - - async _call(_input: z.infer): Promise { - throw new Error("Not implemented."); - } - } - tools = [new Tool()]; + tools = [ + { + type: "function", + function: { + name: functionName, + description, + parameters: zodToJsonSchema(schema), + }, + }, + ]; } else { if ("name" in schema) { functionName = schema.name; } - const description = schema.description ?? "A function available to call."; tools = [ { type: "function",