Skip to content

Commit 33e7bde

Browse files
committed
Replace “toolTask” with “ai.tool” in the Streams page example
1 parent d0530bf commit 33e7bde

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

docs/realtime/streams.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,21 +379,22 @@ function MyComponent({ runId, publicAccessToken }: { runId: string; publicAccess
379379
}
380380
```
381381

382-
### Using `toolTask`
382+
### Using `ai.tool`
383383

384-
As you can see above, we defined a tool which will be used in the `aiStreamingWithTools` task. You can also define a Trigger.dev task that can be used as a tool, and will automatically be invoked with `triggerAndWait` when the tool is called. This is done using the `toolTask` function:
384+
As you can see above, we defined a tool which will be used in the `aiStreamingWithTools` task. You can also define a Trigger.dev task that can be used as a tool, and will automatically be invoked with `triggerAndWait` when the tool is called. This is done using the `ai.tool` function:
385385

386386
```ts
387387
import { openai } from "@ai-sdk/openai";
388-
import { logger, metadata, runs, schemaTask, toolTask } from "@trigger.dev/sdk/v3";
388+
import { ai } from "@trigger.dev/sdk/ai";
389+
import { logger, metadata, runs, schemaTask } from "@trigger.dev/sdk/v3";
389390
import { streamText, tool, type TextStreamPart } from "ai";
390391
import { z } from "zod";
391392

392-
export const getWeather = toolTask({
393+
export const getWeatherTask = schemaTask({
393394
id: "get-weather",
394395
description: "Get the weather for a location",
395-
// Define the parameters for the tool, which becomes the task payload
396-
parameters: z.object({
396+
// Define the schema for the task payload
397+
schema: z.object({
397398
location: z.string(),
398399
}),
399400
run: async ({ location }) => {
@@ -405,9 +406,11 @@ export const getWeather = toolTask({
405406
},
406407
});
407408

409+
export const getWeatherTool = ai.tool(getWeatherTask);
410+
408411
export type STREAMS = {
409412
// Give the stream a type of TextStreamPart along with the tools
410-
openai: TextStreamPart<{ getWeather: typeof getWeather.tool }>;
413+
openai: TextStreamPart<{ getWeather: typeof getWeatherTool }>;
411414
};
412415

413416
export const aiStreamingWithTools = schemaTask({
@@ -428,7 +431,7 @@ export const aiStreamingWithTools = schemaTask({
428431
model: openai(model),
429432
prompt,
430433
tools: {
431-
getWeather: getWeather.tool, // pass weatherTask.tool as a tool
434+
getWeather: getWeatherTool, // pass getWeatherTool as a tool
432435
},
433436
maxSteps: 5, // Allow streamText to repeatedly call the model
434437
});

0 commit comments

Comments
 (0)