Skip to content

Commit

Permalink
docs: Clarify tool creation process in structured outputs documentati…
Browse files Browse the repository at this point in the history
…on (#7578)

Co-authored-by: Sahar Shemesh <sahar.shemesh@zoominfo.com>
Co-authored-by: jacoblee93 <jacoblee93@gmail.com>
  • Loading branch information
3 people authored Jan 25, 2025
1 parent 86fa0d5 commit 7326a63
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/core_docs/docs/concepts/structured_outputs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Several more powerful methods that utilizes native features in the model provide

Many [model providers support](/docs/integrations/chat/) tool calling, a concept discussed in more detail in our [tool calling guide](/docs/concepts/tool_calling/).
In short, tool calling involves binding a tool to a model and, when appropriate, the model can _decide_ to call this tool and ensure its response conforms to the tool's schema.
With this in mind, the central concept is straightforward: _simply bind our schema to a model as a tool!_
With this in mind, the central concept is straightforward: _create a tool with our schema and bind it to the model!_
Here is an example using the `ResponseFormatter` schema defined above:

```typescript
Expand All @@ -90,8 +90,14 @@ const model = new ChatOpenAI({
temperature: 0,
});

// Bind ResponseFormatter schema as a tool to the model
const modelWithTools = model.bindTools([ResponseFormatter]);
// Create a tool with ResponseFormatter as its schema.
const responseFormatterTool = tool(async () => {}, {
name: "responseFormatter",
schema: ResponseFormatter,
});

// Bind the created tool to the model
const modelWithTools = model.bindTools([responseFormatterTool]);

// Invoke the model
const aiMsg = await modelWithTools.invoke(
Expand Down

0 comments on commit 7326a63

Please sign in to comment.