Class: Githuh::LLM::Anthropic

Inherits:
Base
  • Object
show all
Defined in:
lib/githuh/llm/anthropic.rb

Constant Summary collapse

ENDPOINT =
URI('https://api.anthropic.com/v1/messages').freeze
MODEL =
'claude-haiku-4-5-20251001'
MAX_TOKENS =
800
BAR_COLOR =
:yellow

Constants inherited from Base

Base::PROMPT, Base::README_CHAR_LIMIT, Base::REQUEST_TIMEOUT

Instance Attribute Summary

Attributes inherited from Base

#api_key, #name

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Githuh::LLM::Base

Instance Method Details

#summarize(readme) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/githuh/llm/anthropic.rb', line 13

def summarize(readme)
  headers = {
    'x-api-key' => api_key,
    'anthropic-version' => '2023-06-01'
  }
  body = {
    model:      MODEL,
    max_tokens: MAX_TOKENS,
    messages:   [{ role: 'user', content: prompt_for(readme) }]
  }

  payload = parse!(post_json(ENDPOINT, headers, body))
  payload.dig('content', 0, 'text').to_s.strip
end