Class: LLM::Clients::Anthropic

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/llm/clients/anthropic.rb,
lib/llm/clients/anthropic/response.rb

Defined Under Namespace

Classes: Response

Instance Method Summary collapse

Constructor Details

#initialize(llm:) ⇒ Anthropic

Returns a new instance of Anthropic.



11
12
13
# File 'lib/llm/clients/anthropic.rb', line 11

def initialize(llm:)
  @llm = llm
end

Instance Method Details

#chat(messages, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/llm/clients/anthropic.rb', line 15

def chat(messages, options = {})
  request = payload(messages, options)

  return chat_streaming(request, options[:on_message], options[:on_complete]) if options[:stream]

  resp = post_url("/v1/messages", body: request.to_json)

  Response.new(resp).to_normalized_response
end