Class: PromptObjects::LLM::AnthropicAdapter
- Inherits:
-
Object
- Object
- PromptObjects::LLM::AnthropicAdapter
- Defined in:
- lib/prompt_objects/llm/anthropic_adapter.rb
Overview
Anthropic API adapter for LLM calls.
Constant Summary collapse
- DEFAULT_MODEL =
"claude-haiku-4-5"- DEFAULT_MAX_TOKENS =
4096
Instance Method Summary collapse
-
#chat(system:, messages:, tools: []) ⇒ Response
Make a chat completion request.
-
#initialize(api_key: nil, model: nil, max_tokens: nil) ⇒ AnthropicAdapter
constructor
A new instance of AnthropicAdapter.
Constructor Details
#initialize(api_key: nil, model: nil, max_tokens: nil) ⇒ AnthropicAdapter
Returns a new instance of AnthropicAdapter.
10 11 12 13 14 15 16 17 |
# File 'lib/prompt_objects/llm/anthropic_adapter.rb', line 10 def initialize(api_key: nil, model: nil, max_tokens: nil) @api_key = api_key || ENV.fetch("ANTHROPIC_API_KEY") do raise Error, "ANTHROPIC_API_KEY environment variable not set" end @model = model || DEFAULT_MODEL @max_tokens = max_tokens || DEFAULT_MAX_TOKENS @client = Anthropic::Client.new(api_key: @api_key) end |
Instance Method Details
#chat(system:, messages:, tools: []) ⇒ Response
Make a chat completion request.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/prompt_objects/llm/anthropic_adapter.rb', line 24 def chat(system:, messages:, tools: []) params = { model: @model, max_tokens: @max_tokens, system: system, messages: () } # Only include tools if we have any if tools.any? params[:tools] = convert_tools(tools) end raw_response = @client..create(**params) parse_response(raw_response) end |