Class: Layered::Assistant::Clients::Anthropic

Inherits:
Base
  • Object
show all
Defined in:
app/services/layered/assistant/clients/anthropic.rb

Instance Method Summary collapse

Methods inherited from Base

for, #initialize

Constructor Details

This class inherits a constructor from Layered::Assistant::Clients::Base

Instance Method Details

#chat(messages:, model:, stream_proc:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/layered/assistant/clients/anthropic.rb', line 5

def chat(messages:, model:, stream_proc:)
  formatted = MessagesService.new.format(messages, provider: @provider)

  parameters = {
    model: model,
    messages: formatted[:messages],
    max_tokens: 8192,
    stream: stream_proc
  }
  parameters[:system] = formatted[:system] if formatted[:system].present?

  ::Anthropic::Client.new(
    access_token: @api_key,
    log_errors: Layered::Assistant.log_errors,
    request_timeout: Layered::Assistant.api_request_timeout
  ).messages(parameters: parameters)
end