Skip to content

Commit 63e754e

Browse files
koicsergiobayona
andauthored
Support ruby-anthropic gem (#951)
This PR adds support for ruby-anthropic gem, which was renamed from anthropic gem. > This gem has been renamed from `anthropic` to `ruby-anthropic`, to make way for > the new [official Anthropic Ruby SDK](https://github.com/anthropics/anthropic-sdk-ruby) > If you wish to keep using this gem, you just need to update your Gemfile from `anthropic` to > `ruby-anthropic` and version `0.4.2` or greater. > No other changes are needed and it will continue to work as normal. https://github.com/alexrudall/ruby-anthropic/blob/v0.4.2/README.md So, the anthropic gem was renamed to ruby-anthropic starting from version 0.4.2. If user is still using version 0.4.1 or earlier of the anthropic gem, the implementation falls back to anthropic instead of treating it as a load error. The development dependency has been updated to use the new ruby-anthropic gem instead of the old anthropic gem. Co-authored-by: Sergio Bayona <[email protected]>
1 parent 5b058d0 commit 63e754e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ GEM
4646
public_suffix (>= 2.0.2, < 7.0)
4747
afm (0.2.2)
4848
ai21 (0.2.1)
49-
anthropic (0.3.2)
50-
event_stream_parser (>= 0.3.0, < 2.0.0)
51-
faraday (>= 1)
52-
faraday-multipart (>= 1)
5349
ast (2.4.2)
5450
aws-eventstream (1.3.0)
5551
aws-partitions (1.992.0)
@@ -372,6 +368,10 @@ GEM
372368
rubocop-performance (1.21.1)
373369
rubocop (>= 1.48.1, < 2.0)
374370
rubocop-ast (>= 1.31.1, < 2.0)
371+
ruby-anthropic (0.4.2)
372+
event_stream_parser (>= 0.3.0, < 2.0.0)
373+
faraday (>= 1)
374+
faraday-multipart (>= 1)
375375
ruby-next (1.0.3)
376376
paco (~> 0.2)
377377
require-hooks (~> 0.2)
@@ -456,7 +456,6 @@ PLATFORMS
456456

457457
DEPENDENCIES
458458
ai21 (~> 0.2.1)
459-
anthropic (~> 0.3)
460459
aws-sdk-bedrockruntime (~> 1.1)
461460
chroma-db (~> 0.6.0)
462461
cohere-ruby (~> 0.9.10)
@@ -490,6 +489,7 @@ DEPENDENCIES
490489
roo-xls (~> 1.2.0)
491490
rspec (~> 3.0)
492491
rubocop
492+
ruby-anthropic (~> 0.4)
493493
ruby-openai (~> 7.1.0)
494494
safe_ruby (~> 1.0.4)
495495
sequel (~> 5.87.0)

langchain.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Gem::Specification.new do |spec|
4444

4545
# optional dependencies
4646
spec.add_development_dependency "ai21", "~> 0.2.1"
47-
spec.add_development_dependency "anthropic", "~> 0.3"
47+
spec.add_development_dependency "ruby-anthropic", "~> 0.4"
4848
spec.add_development_dependency "aws-sdk-bedrockruntime", "~> 1.1"
4949
spec.add_development_dependency "chroma-db", "~> 0.6.0"
5050
spec.add_development_dependency "cohere-ruby", "~> 0.9.10"

lib/langchain/llm/anthropic.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ class Anthropic < Base
2525
# @param default_options [Hash] Default options to use on every call to LLM, e.g.: { temperature:, completion_model:, chat_model:, max_tokens: }
2626
# @return [Langchain::LLM::Anthropic] Langchain::LLM::Anthropic instance
2727
def initialize(api_key:, llm_options: {}, default_options: {})
28-
depends_on "anthropic"
28+
begin
29+
depends_on "ruby-anthropic", req: "anthropic"
30+
rescue Langchain::DependencyHelper::LoadError
31+
# Falls back to the older `anthropic` gem if `ruby-anthropic` gem cannot be loaded.
32+
depends_on "anthropic"
33+
end
2934

3035
@client = ::Anthropic::Client.new(access_token: api_key, **llm_options)
3136
@defaults = DEFAULTS.merge(default_options)

0 commit comments

Comments
 (0)