Open
Conversation
- Bump Go version to 1.22.0 and update toolchain. - Add new dependency: `github.com/anthropics/anthropic-sdk-go` v0.2.0-alpha.8. - Update existing dependencies: `golang.org/x/net` to v0.27.0 and `github.com/stretchr/testify` to v1.9.0. - Refactor Anthropic client initialization to use API key from environment variable. - Change method calls from `Generate` to `Chat` for improved functionality. - Remove deprecated `api.go` and `formatter.go` files; introduce new `common.go` and `function.go` for better structure. - Enhance message handling and tool integration in the Anthropic client.
- Add support for response format (JSON/text) - Implement caching mechanism for responses - Add usage metadata tracking - Introduce new methods for configuration (WithResponseFormat, SetStop) - Improve error handling and logging - Refactor Generate method with more robust generation process
- Improve streaming response handling in `stream` method - Enhance message content processing in `threadToChatCompletionMessages` - Add support for multi-content messages (text and images) - Optimize tool choice and tools parameter handling - Remove redundant token tracking and simplify streaming logic
Clean up unused constants related to stream delta types, simplifying the Anthropic client configuration
henomis
reviewed
Mar 15, 2025
henomis
reviewed
Mar 15, 2025
llm/anthropic/anthropic.go
Outdated
| } else { | ||
| err = o.generate(ctx, t, chatRequest) | ||
| // NewAnthropic creates a new Anthropic instance with explicit API key. | ||
| func NewAnthropic(apiKey string) *Anthropic { |
Owner
There was a problem hiding this comment.
Please implement a WithKey method here
Author
There was a problem hiding this comment.
I am not 100% sure about my implementation here.
henomis
reviewed
Mar 15, 2025
henomis
reviewed
Mar 15, 2025
henomis
reviewed
Mar 15, 2025
henomis
reviewed
Mar 15, 2025
|
|
||
| func main() { | ||
| anthropicllm := anthropic.New().WithModel("claude-3-opus-20240229") | ||
| anthropicllm := anthropic.NewAnthropic(os.Getenv("ANTHROPIC_API_KEY")).WithModel(anthropic.ModelClaude_3_Opus_20240229) |
Owner
There was a problem hiding this comment.
Please provide some examples showing tools/functions usage like the ones here:https://github.com/henomis/lingoose/tree/main/examples/llm/openai/tools
Same for the response format like the one here https://github.com/henomis/lingoose/tree/main/examples/llm/openai/response_format
henomis
requested changes
Mar 15, 2025
Owner
henomis
left a comment
There was a problem hiding this comment.
Left some comments, just a quick review, need to go deeper, Great job!
Author
|
I will work on this coming week. |
- Remove deprecated NewAnthropic method and replace it with a simplified New method that retrieves the API key from the environment. - Update example usages in the `stream`, `multimodal`, and `voyage` examples to use the new client initialization and method calls. - Change method calls from `Chat` to `Generate` for improved functionality and consistency across examples. - Clean up unused imports and improve overall code clarity. Ran existing examples to confirm they are still working. Will implement new examples as requested this week.
henomis
reviewed
Mar 16, 2025
| EOS = "\x00" | ||
| ) | ||
| // WithKey returns a new Anthropic instance with the given API key. | ||
| func WithKey(key string) *Anthropic { |
Owner
There was a problem hiding this comment.
Suggested change
| func WithKey(key string) *Anthropic { | |
| func (a *Anthropic) WithKey(key string) *Anthropic { |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request Template
Description
This PR enhances the Anthropic integration to make it more aligned with the OpenAI implementation. The changes include adding proper streaming support, implementing multimodal capabilities, improving error handling, and ensuring consistent behavior between the two LLM implementations.
Specifically, this PR addresses:
streammethod to correctly handle streaming responses and properly accumulate text contenttool_choiceparameter in thebuildChatCompletionRequestmethodErrAnthropicChatfor consistent error reportingthreadToChatCompletionMessagesfunctionFixes #225
Type of change
How Has This Been Tested?
The changes have been tested using the example code provided in the repository:
examples/llm/antropic/stream/main.go) - Verified that streaming responses are correctly displayedexamples/llm/antropic/multimodal/main.go) - Verified that image content is correctly processed and describedChecklist: