-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add Anthropic Claude integration #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+181
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0dbbd49
build(deps): add @anthropic-ai/sdk as optional peer dependency
ryoppippi 7ced47d
feat(tool): add toAnthropic() method for Anthropic Claude integration
ryoppippi 4681f9e
test(tool): add tests for toAnthropic() conversion methods
ryoppippi b4ea0c5
feat(example): add Anthropic Claude integration example
ryoppippi a00e8a3
chore(test): format tool.test.ts
ryoppippi 666f246
Apply suggestion from @glebedel
glebedel bfc0a68
Apply suggestion from @glebedel
glebedel 82064e0
Merge branch 'main' into feat/anthropic-integration
ryoppippi b4cc8f9
Merge branch 'main' into feat/anthropic-integration
ryoppippi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| /** | ||
| * This example shows how to use StackOne tools with Anthropic Claude. | ||
| */ | ||
|
|
||
| import assert from 'node:assert'; | ||
| import process from 'node:process'; | ||
| import Anthropic from '@anthropic-ai/sdk'; | ||
| import { StackOneToolSet } from '@stackone/ai'; | ||
|
|
||
| const apiKey = process.env.STACKONE_API_KEY; | ||
| if (!apiKey) { | ||
| console.error('STACKONE_API_KEY environment variable is required'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Replace with your actual account ID from StackOne dashboard | ||
| const accountId = 'your-hris-account-id'; | ||
|
|
||
| const anthropicIntegration = async (): Promise<void> => { | ||
| // Initialise StackOne | ||
| const toolset = new StackOneToolSet({ | ||
| accountId, | ||
| baseUrl: process.env.STACKONE_BASE_URL ?? 'https://api.stackone.com', | ||
| }); | ||
|
|
||
| // Filter for any relevant tools | ||
| const tools = await toolset.fetchTools({ | ||
| actions: ['*_list_*', '*_search_*'], | ||
| }); | ||
| const anthropicTools = tools.toAnthropic(); | ||
|
|
||
| // Initialise Anthropic client | ||
| const anthropic = new Anthropic(); | ||
|
|
||
| // Create a message with tool calls | ||
| const response = await anthropic.messages.create({ | ||
| model: 'claude-haiku-4-5-20241022', | ||
| max_tokens: 1024, | ||
| system: 'You are a helpful assistant that can access tools.', | ||
| messages: [ | ||
| { | ||
| role: 'user', | ||
| content: 'What is the employee with id: c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA phone number?', | ||
| }, | ||
| ], | ||
| tools: anthropicTools, | ||
| }); | ||
|
|
||
| // Verify the response contains tool use | ||
| assert(response.content.length > 0, 'Expected at least one content block in the response'); | ||
|
|
||
| const toolUseBlock = response.content.find((block) => block.type === 'tool_use'); | ||
| assert(toolUseBlock !== undefined, 'Expected a tool_use block in the response'); | ||
| assert(toolUseBlock.type === 'tool_use', 'Expected block to be tool_use type'); | ||
| assert(toolUseBlock.name === 'hris_get_employee', 'Expected tool call to be hris_get_employee'); | ||
|
|
||
| // Verify the input contains the expected fields | ||
| const input = toolUseBlock.input as Record<string, unknown>; | ||
| assert(input.id === 'c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA', 'Expected id to match the query'); | ||
| }; | ||
|
|
||
| // Run the example | ||
| await anthropicIntegration(); | ||
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model name
claude-haiku-4-5-20241022appears to be incorrect. Based on Anthropic's model naming conventions, this should likely beclaude-3-5-haiku-20241022(Claude 3.5 Haiku from October 2024). There is no publicly documented Claude 4 or Claude 4.5 model as of the knowledge cutoff.