Class: LlmGateway::Adapters::Claude::Client
Instance Attribute Summary
Attributes inherited from BaseClient
#api_key, #base_endpoint, #model_key
Instance Method Summary
collapse
Methods inherited from BaseClient
#get, #post, #post_file
Constructor Details
#initialize(model_key: "claude-3-7-sonnet-20250219", api_key: ENV["ANTHROPIC_API_KEY"]) ⇒ Client
Returns a new instance of Client.
9
10
11
12
|
# File 'lib/llm_gateway/adapters/claude/client.rb', line 9
def initialize(model_key: "claude-3-7-sonnet-20250219", api_key: ENV["ANTHROPIC_API_KEY"])
@base_endpoint = "https://api.anthropic.com/v1"
super(model_key: model_key, api_key: api_key)
end
|
Instance Method Details
#chat(messages, response_format: { type: "text" }, tools: nil, system: [], max_completion_tokens: 4096) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/llm_gateway/adapters/claude/client.rb', line 14
def chat(messages, response_format: { type: "text" }, tools: nil, system: [], max_completion_tokens: 4096)
body = {
model: model_key,
max_tokens: max_completion_tokens,
messages: messages
}
body.merge!(tools: tools) if LlmGateway::Utils.present?(tools)
body.merge!(system: system) if LlmGateway::Utils.present?(system)
post("messages", body)
end
|
#download_file(file_id) ⇒ Object
27
28
29
|
# File 'lib/llm_gateway/adapters/claude/client.rb', line 27
def download_file(file_id)
get("files/#{file_id}/content")
end
|
#upload_file(filename, content, mime_type = "application/octet-stream") ⇒ Object
31
32
33
|
# File 'lib/llm_gateway/adapters/claude/client.rb', line 31
def upload_file(filename, content, mime_type = "application/octet-stream")
post_file("files", content, filename, mime_type: mime_type)
end
|