-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1b743f
commit 5bcaddb
Showing
12 changed files
with
749 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
configured_endpoints: 2 | ||
configured_endpoints: 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env -S npm run tsn -T | ||
|
||
import Anthropic from '@anthropic-ai/sdk'; | ||
import assert from 'node:assert'; | ||
|
||
const client = new Anthropic(); // gets API Key from environment variable ANTHROPIC_API_KEY | ||
|
||
async function main() { | ||
const userMessage: Anthropic.Beta.Tools.ToolsBetaMessageParam = { | ||
role: 'user', | ||
content: 'What is the weather in SF?', | ||
}; | ||
const tools: Anthropic.Beta.Tools.Tool[] = [ | ||
{ | ||
name: 'get_weather', | ||
description: 'Get the weather for a specific location', | ||
input_schema: { | ||
type: 'object', | ||
properties: { location: { type: 'string' } }, | ||
}, | ||
}, | ||
]; | ||
|
||
const message = await client.beta.tools.messages.create({ | ||
model: 'claude-3-opus-20240229', | ||
max_tokens: 1024, | ||
messages: [userMessage], | ||
tools, | ||
}); | ||
console.log('Initial response:'); | ||
console.dir(message, { depth: 4 }); | ||
|
||
assert(message.stop_reason === 'tool_use'); | ||
|
||
const tool = message.content.find( | ||
(content): content is Anthropic.Beta.Tools.ToolUseBlock => content.type === 'tool_use', | ||
); | ||
assert(tool); | ||
|
||
const result = await client.beta.tools.messages.create({ | ||
model: 'claude-3-opus-20240229', | ||
max_tokens: 1024, | ||
messages: [ | ||
userMessage, | ||
{ role: message.role, content: message.content }, | ||
{ | ||
role: 'user', | ||
content: [ | ||
{ | ||
type: 'tool_result', | ||
tool_use_id: tool.id, | ||
content: [{ type: 'text', text: 'The weather is 73f' }], | ||
}, | ||
], | ||
}, | ||
], | ||
tools, | ||
}); | ||
console.log('\nFinal response'); | ||
console.dir(result, { depth: 4 }); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
import { APIResource } from '@anthropic-ai/sdk/resource'; | ||
import * as ToolsAPI from '@anthropic-ai/sdk/resources/beta/tools/tools'; | ||
|
||
export class Beta extends APIResource { | ||
tools: ToolsAPI.Tools = new ToolsAPI.Tools(this._client); | ||
} | ||
|
||
export namespace Beta { | ||
export import Tools = ToolsAPI.Tools; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
export { Beta } from './beta'; | ||
export { Tools } from './tools/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. | ||
|
||
export { | ||
Tool, | ||
ToolResultBlockParam, | ||
ToolUseBlock, | ||
ToolUseBlockParam, | ||
ToolsBetaContentBlock, | ||
ToolsBetaMessage, | ||
ToolsBetaMessageParam, | ||
MessageCreateParams, | ||
MessageCreateParamsNonStreaming, | ||
MessageCreateParamsStreaming, | ||
Messages, | ||
} from './messages'; | ||
export { Tools } from './tools'; |
Oops, something went wrong.