857 B
857 B
layout
| layout |
|---|
| default |
Binding Tools al Modelo
Puedes vincular tools directamente al modelo con .bindTools()
import { ChatOpenAI } from "@langchain/openai";
import { tool } from "@langchain/core/tools";
import { z } from "zod";
const weatherTool = tool(
async ({ location }) => `El tiempo en ${location} es soleado`,
{
name: "get_weather",
description: "Obtiene el tiempo de una ubicación",
schema: z.object({ location: z.string() }),
}
);
const model = new ChatOpenAI({ model: "gpt-4.1-mini" });
const modelWithTools = model.bindTools([weatherTool]);
const response = await modelWithTools.invoke("¿Qué tiempo hace en Madrid?");
console.log(response.tool_calls); // Tool que el LLM decidió usar