Class: Ace::LLM::Organisms::AnthropicClient

Inherits:
BaseClient
  • Object
show all
Defined in:
lib/ace/llm/organisms/anthropic_client.rb

Overview

AnthropicClient handles interactions with Anthropic’s Claude API

Constant Summary collapse

API_BASE_URL =
"https://api.anthropic.com"
DEFAULT_MODEL =
"claude-3-5-sonnet-20241022"
API_VERSION =
"2023-06-01"
GENERATION_KEYS =

Generation parameters to include in API request (max_tokens handled separately as required)

%i[temperature top_p top_k].freeze
DEFAULT_GENERATION_CONFIG =
{
  temperature: 0.7,
  max_tokens: 4096,  # Anthropic requires max_tokens
  top_p: nil,
  top_k: nil
}.freeze

Constants inherited from BaseClient

BaseClient::DEFAULT_SYSTEM_PROMPT_SEPARATOR

Instance Attribute Summary

Attributes inherited from BaseClient

#api_key, #base_url, #generation_config, #http_client, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClient

#initialize, #needs_credentials?, #provider_name

Constructor Details

This class inherits a constructor from Ace::LLM::Organisms::BaseClient

Class Method Details

.provider_nameString

Get the provider name

Returns:

  • (String)

    Provider name



26
27
28
# File 'lib/ace/llm/organisms/anthropic_client.rb', line 26

def self.provider_name
  "anthropic"
end

Instance Method Details

#generate(messages, **options) ⇒ Hash

Generate a response from Anthropic’s Claude

Parameters:

  • messages (Array<Hash>, String)

    Messages or prompt

  • options (Hash)

    Generation options

Returns:

  • (Hash)

    Response with text and metadata



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ace/llm/organisms/anthropic_client.rb', line 34

def generate(messages, **options)
  messages_array = build_messages(messages)
  generation_params = extract_generation_options(options)

  request_body = build_request_body(messages_array, generation_params)
  response = make_api_request(request_body)

  parse_response(response)
rescue => e
  handle_api_error(e)
end