Class: RCrewAI::LLMClients::Anthropic
- Defined in:
- lib/rcrewai/llm_clients/anthropic.rb
Constant Summary collapse
- BASE_URL =
'https://api.anthropic.com/v1'- API_VERSION =
'2023-06-01'- STOP_REASON_MAP =
{ 'tool_use' => :tool_calls, 'end_turn' => :stop, 'stop_sequence' => :stop, 'max_tokens' => :length }.freeze
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
-
#initialize(config = RCrewAI.configuration) ⇒ Anthropic
constructor
A new instance of Anthropic.
- #models ⇒ Object
-
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument.
Methods inherited from Base
Constructor Details
#initialize(config = RCrewAI.configuration) ⇒ Anthropic
Returns a new instance of Anthropic.
24 25 26 27 |
# File 'lib/rcrewai/llm_clients/anthropic.rb', line 24 def initialize(config = RCrewAI.configuration) super @base_url = BASE_URL end |
Instance Method Details
#chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rcrewai/llm_clients/anthropic.rb', line 29 def chat(messages:, tools: nil, tool_choice: :auto, stream: nil, **) = () non_system = .reject { |m| m.is_a?(Hash) && m[:role] == 'system' } payload = { model: config.model, messages: (non_system), max_tokens: [:max_tokens] || config.max_tokens || 1000, temperature: [:temperature] || config.temperature }.compact if payload[:system] = if [:cache_system] [{ type: 'text', text: , cache_control: { type: 'ephemeral' } }] else end end if tools && !tools.empty? payload[:tools] = ProviderSchema.for_many(:anthropic, tools) payload[:tool_choice] = { type: tool_choice.to_s } if tool_choice != :auto && tool_choice.is_a?(Symbol) end payload[:top_p] = [:top_p] if [:top_p] payload[:top_k] = [:top_k] if [:top_k] payload[:stop_sequences] = [:stop_sequences] if [:stop_sequences] if stream payload[:stream] = true stream_chat(payload, stream) else plain_chat(payload) end end |
#models ⇒ Object
70 71 72 73 74 75 |
# File 'lib/rcrewai/llm_clients/anthropic.rb', line 70 def models %w[ claude-opus-4-7 claude-sonnet-4-6 claude-haiku-4-5 claude-3-5-sonnet-20241022 claude-3-haiku-20240307 ] end |
#supports_native_tools?(model: config.model) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument
66 67 68 |
# File 'lib/rcrewai/llm_clients/anthropic.rb', line 66 def supports_native_tools?(model: config.model) # rubocop:disable Lint/UnusedMethodArgument true end |