-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvercel.ts
More file actions
57 lines (53 loc) · 1.42 KB
/
vercel.ts
File metadata and controls
57 lines (53 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import "dotenv-flow/config"
import { stepCountIs, streamText, tool } from "ai"
import { langtail } from "../src/vercel-ai"
import { z } from "zod/v4"
async function main() {
const result = streamText({
model: langtail("vtip"),
messages: [
{
role: "user",
content: "What is the weather in Tokyo?",
},
],
stopWhen: stepCountIs(5),
onStepFinish: (step) => {
console.log(step.content)
},
tools: {
weather: tool({
description: "Get the weather in a location",
inputSchema: z.object({
location: z.string().describe("The location to get the weather for"),
}),
async execute({ location }) {
return {
type: "image",
data: "https://stickerapp.co.uk/cdn-assets/images/stickers/608t.png",
}
},
// map to tool result content for LLM consumption:
toModelOutput(result) {
return {
type: "content",
value:
typeof result === "string"
? [{ type: "text", text: result }]
: [
{
type: "media",
data: result.data,
mediaType: "image/png",
},
],
}
},
}),
},
})
for await (const chunk of result.fullStream) {
console.log("chunk", chunk)
}
}
main()