-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathtools-helpers-json-schema.ts
More file actions
executable file
·44 lines (39 loc) · 1.1 KB
/
tools-helpers-json-schema.ts
File metadata and controls
executable file
·44 lines (39 loc) · 1.1 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
#!/usr/bin/env -S npm run tsn -T
import Anthropic from '@anthropic-ai/sdk';
import { betaTool } from '@anthropic-ai/sdk/helpers/beta/json-schema';
const client = new Anthropic();
async function main() {
const message = await client.beta.messages.toolRunner({
messages: [
{
role: 'user',
content: `What is the weather in SF?`,
},
],
tools: [
betaTool({
name: 'getWeather',
description: 'Get the weather at a specific location',
inputSchema: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
},
required: ['location'],
},
run: ({ location }) => {
return `The weather is foggy with a temperature of 20°C in ${location}.`;
},
}),
],
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
// the maximum number of iterations to run the tool
max_iterations: 10,
});
console.log('Final response:', message.content);
}
main();