Class: RubyCanUseLLM::Providers::Anthropic

Inherits:
Base
  • Object
show all
Defined in:
lib/rubycanusellm/providers/anthropic.rb

Constant Summary collapse

API_URL =
"https://api.anthropic.com/v1/messages"

Instance Method Summary collapse

Methods inherited from Base

#embed, #initialize

Constructor Details

This class inherits a constructor from RubyCanUseLLM::Providers::Base

Instance Method Details

#chat(messages, **options, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubycanusellm/providers/anthropic.rb', line 12

def chat(messages, **options, &block)
  system, user_messages = extract_system(messages)
  if options[:stream] && block
    body = build_body(system, user_messages, options.except(:stream)).merge(stream: true)
    stream_request(body, &block)
  else
    body = build_body(system, user_messages, options)
    response = request(body)
    parse_response(response)
  end
end