Class: Vercon::Claude

Inherits:
Object
  • Object
show all
Defined in:
lib/vercon/claude.rb

Constant Summary collapse

BASE_URL =
"https://api.anthropic.com"

Instance Method Summary collapse

Constructor Details

#initializeClaude

Returns a new instance of Claude.



9
10
11
12
13
14
# File 'lib/vercon/claude.rb', line 9

def initialize
  config = Vercon::Config.new

  @api_token = config.claude_token
  @claude_model = config.claude_model
end

Instance Method Details

#submit(model: nil, system: nil, max_tokens: 4096, temperature: 0.2, stop_sequences: nil, user: nil, messages: nil, tools: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vercon/claude.rb', line 16

def submit(model: nil, system: nil, max_tokens: 4096, temperature: 0.2, stop_sequences: nil, user: nil, # rubocop:disable Metrics/ParameterLists
  messages: nil, tools: nil)
  body = {
    model: model || @claude_model,
    system: system,
    max_tokens: max_tokens,
    temperature: temperature,
    stop_sequences: stop_sequences,
    messages: messages || [{role: "user", content: user}],
    tools: tools
  }.reject { |_, v| v.nil? || ["", [], {}].include?(v) }

  client.post("/v1/messages", body: body.to_json).then { |res| prepare_response(res.json) }
end