Skip to content

Commit

Permalink
only use oai type for tools in wso base implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jun 12, 2024
1 parent f9e7cd0 commit ffedf9a
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions langchain-core/src/language_models/chat_models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";
import {
AIMessage,
type BaseMessage,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -778,6 +779,7 @@ export abstract class BaseChatModel<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const schema: z.ZodType<RunOutput> | Record<string, any> = 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") {
Expand All @@ -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<any, any, any, any>;

async _call(_input: z.infer<typeof this.schema>): Promise<string> {
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",
Expand Down

0 comments on commit ffedf9a

Please sign in to comment.