Class: Soka::LLMs::Anthropic

Inherits:
Base
  • Object
show all
Defined in:
lib/soka/llms/anthropic.rb

Overview

Anthropic (Claude) LLM provider implementation

Constant Summary collapse

ENV_KEY =
'ANTHROPIC_API_KEY'

Instance Attribute Summary

Attributes inherited from Base

#api_key, #model, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize, #streaming_chat, #supports_streaming?

Constructor Details

This class inherits a constructor from Soka::LLMs::Base

Instance Method Details

#chat(messages, **params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/soka/llms/anthropic.rb', line 9

def chat(messages, **params)
  request_params = build_request_params(messages, params)

  response = connection.post do |req|
    req.url '/v1/messages'
    req.headers['x-api-key'] = api_key
    req.headers['anthropic-version'] = options[:anthropic_version]
    req.body = request_params
  end

  parse_response(response)
rescue Faraday::Error => e
  handle_error(e)
end