Class: Clients::ClaudeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/clients/claude_client.rb

Overview

Claude API client for communicating with Anthropic’s Claude model

Defined Under Namespace

Classes: ConfigError, OverloadError, UnknownError

Instance Method Summary collapse

Constructor Details

#initializeClaudeClient

Returns a new instance of ClaudeClient.

Raises:



14
15
16
17
18
19
20
21
# File 'lib/clients/claude_client.rb', line 14

def initialize
  @config = Committer::Config.load

  return unless @config['api_key'].nil? || @config['api_key'].empty?

  raise ConfigError,
        "API key not configured. Run 'committer setup' and edit ~/.committer/config.yml to add your API key."
end

Instance Method Details

#post(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/clients/claude_client.rb', line 23

def post(message)
  body = {
    model: @config['model'],
    max_tokens: 4096,
    messages: [
      { role: 'user', content: message }
    ]
  }

  response = send_request(body)
  handle_error_response(response) if response['type'] == 'error'

  response
end