-
Notifications
You must be signed in to change notification settings - Fork 6
Add Anthropic SDK integration #26
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
Open
jxnl
wants to merge
2
commits into
main
Choose a base branch
from
anthropic-sdk-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,53 @@ | ||
# Anthropic SDK Integration Notes | ||
|
||
This document contains information about integrating and testing the official Anthropic SDK with Instructor-rb. | ||
|
||
## Current Status | ||
|
||
- The OpenAI integration works correctly with all tests passing. | ||
- The Anthropic integration code has been updated to use the official Anthropic SDK (`anthropic-sdk-beta`) instead of `ruby-anthropic`. | ||
- The Anthropic tests are currently failing, likely due to mocking/stubbing issues. | ||
|
||
## Changes Made | ||
|
||
1. Updated the gemspec to use `anthropic-sdk-beta` (~> 0.1.0.pre.beta.6) instead of `ruby-anthropic` | ||
2. Updated imports in `lib/instructor.rb` to require 'anthropic' instead of 'ruby-anthropic' | ||
3. Modified the Anthropic patch implementation to match the new SDK's API: | ||
- Updated message creation to use the new tools parameter structure | ||
- Added the beta header for tools support | ||
- Updated the client creation and message sending process | ||
|
||
4. Updated the Response class to handle the new response format from the SDK: | ||
- Modified content and tool_calls methods to navigate the new structure | ||
- Updated the arguments method to extract input from tool calls | ||
|
||
## Test Failures | ||
|
||
The Anthropic tests are failing for several reasons: | ||
|
||
1. **Mocking/Stubbing Issues**: The Anthropic SDK uses a complex architecture that's difficult to mock completely. | ||
2. **VCR Configuration**: The VCR setup and the SDK's HTTP request mechanism don't interact well. | ||
3. **JSON Parsing Errors**: We're seeing issues with serializing/deserializing response objects when testing. | ||
|
||
## Recommendations | ||
|
||
1. **Focus on Manual Testing**: Ensure the code works with real API calls before focusing on test coverage. | ||
2. **Create New VCR Cassettes**: Record fresh VCR cassettes for the Anthropic tests with the new SDK. | ||
3. **Simplify Test Structure**: Consider more focused tests that isolate the integration points. | ||
|
||
## Next Steps | ||
|
||
1. Complete a manual end-to-end test of the Anthropic integration. | ||
2. Create a new test file specifically for the Anthropic SDK integration. | ||
3. Consider adding test helpers specifically for the Anthropic SDK structure. | ||
|
||
## Notes on The Anthropic SDK | ||
|
||
The Anthropic SDK has a different structure compared to the ruby-anthropic client: | ||
|
||
1. It uses a client instance with nested resources (e.g., `client.messages.create`) instead of direct methods. | ||
2. Configuration isn't global but per-client (passed at initialization). | ||
3. Response objects have a different structure with nested content blocks. | ||
4. The tools interface requires a specific beta header. | ||
|
||
The integration work to adapt to these differences has been done, but more thorough testing is needed. |
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
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.
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.
Avoid re-fetching the API key from
ENV
and instantiating a new client inside themessages
method. Consider using the instance's@api_key
(set during initialization) or simplyself
to preserve configuration.