-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathscenario-error-in-tool.mjs
More file actions
41 lines (39 loc) · 1.19 KB
/
scenario-error-in-tool.mjs
File metadata and controls
41 lines (39 loc) · 1.19 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
import * as Sentry from '@sentry/node';
import { generateText, tool } from 'ai';
import { MockLanguageModelV3 } from 'ai/test';
import { z } from 'zod';
async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
await generateText({
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'tool-calls', raw: 'tool_calls' },
usage: {
inputTokens: { total: 15, noCache: 15, cached: 0 },
outputTokens: { total: 25, noCache: 25, cached: 0 },
totalTokens: { total: 40, noCache: 40, cached: 0 },
},
content: [
{
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
warnings: [],
}),
}),
tools: {
getWeather: tool({
inputSchema: z.object({ location: z.string() }),
execute: async () => {
throw new Error('Error in tool');
},
}),
},
prompt: 'What is the weather in San Francisco?',
});
});
}
run();