Class: Crimson::Client::AnthropicAdapter
- Defined in:
- lib/crimson/client/anthropic_adapter.rb
Overview
Anthropic SDK client adapter supporting streaming, thinking mode, and tool use.
Instance Method Summary collapse
- #chat(messages:, tools: []) {|text_chunk, tool_event| ... } ⇒ Array(Message::Assistant, Hash, nil)
-
#initialize(config) ⇒ AnthropicAdapter
constructor
A new instance of AnthropicAdapter.
Constructor Details
#initialize(config) ⇒ AnthropicAdapter
Returns a new instance of AnthropicAdapter.
12 13 14 15 |
# File 'lib/crimson/client/anthropic_adapter.rb', line 12 def initialize(config) super @client = Anthropic::Client.new(api_key: config.api_key) end |
Instance Method Details
#chat(messages:, tools: []) {|text_chunk, tool_event| ... } ⇒ Array(Message::Assistant, Hash, nil)
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/crimson/client/anthropic_adapter.rb', line 21 def chat(messages:, tools: [], &stream_callback) system_msg, chat_msgs = () params = { model: @config.model, max_tokens: @config.max_tokens } params[:system] = system_msg if system_msg params[:messages] = chat_msgs params[:tools] = tools unless tools.empty? if @config.thinking_level && @config.thinking_level != "off" budget = thinking_budget(@config.thinking_level) params[:thinking] = { type: "enabled", budget_tokens: budget } params[:max_tokens] = [params[:max_tokens], budget * 2].max end if block_given? stream_chat(params, &stream_callback) else non_stream_chat(params) end end |