initial commit: slides ready + upgraded
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
---
|
||||
layout: default
|
||||
---
|
||||
|
||||
# Binding Tools al Modelo
|
||||
|
||||
<div class="text-sm mt-8">
|
||||
|
||||
<v-click>
|
||||
|
||||
<div class="mb-6">
|
||||
|
||||
Puedes vincular tools directamente al modelo con `.bindTools()`
|
||||
|
||||
</div>
|
||||
|
||||
</v-click>
|
||||
|
||||
<v-click>
|
||||
|
||||
```typescript
|
||||
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
|
||||
```
|
||||
|
||||
</v-click>
|
||||
|
||||
</div>
|
||||
Reference in New Issue
Block a user