Class: LlmGateway::Clients::Anthropic
Constant Summary
collapse
- CLAUDE_CODE_VERSION =
"2.1.2"
- DEFAULT_MODEL =
"claude-3-7-sonnet-20250219"
Instance Attribute Summary
Attributes inherited from BaseClient
#api_key, #base_endpoint
Instance Method Summary
collapse
Methods inherited from BaseClient
#get, #post, #post_file, #post_stream
Constructor Details
#initialize(api_key: ENV["ANTHROPIC_API_KEY"]) ⇒ Anthropic
Returns a new instance of Anthropic.
14
15
16
17
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 14
def initialize(api_key: ENV["ANTHROPIC_API_KEY"])
@base_endpoint = "https://api.anthropic.com/v1"
super(api_key: api_key)
end
|
Instance Method Details
#chat(messages, **kwargs) ⇒ Object
19
20
21
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 19
def chat(messages, **kwargs)
post("messages", build_body(messages, **kwargs))
end
|
#download_file(file_id) ⇒ Object
38
39
40
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 38
def download_file(file_id)
get("files/#{file_id}/content")
end
|
#get_oauth_access_token(access_token:, refresh_token:, expires_at:, &block) ⇒ Object
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 27
def get_oauth_access_token(access_token:, refresh_token:, expires_at:, &block)
token_manager = LlmGateway::Clients::ClaudeCode::TokenManager.new(
access_token: access_token,
refresh_token: refresh_token,
expires_at: expires_at
)
token_manager.on_token_refresh = block if block_given?
token_manager.ensure_valid_token
token_manager.access_token
end
|
#stream(messages, **kwargs, &block) ⇒ Object
23
24
25
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 23
def stream(messages, **kwargs, &block)
post_stream("messages", build_body(messages, **kwargs), &block)
end
|
#upload_file(filename, content, mime_type = "application/octet-stream") ⇒ Object
42
43
44
|
# File 'lib/llm_gateway/clients/anthropic.rb', line 42
def upload_file(filename, content, mime_type = "application/octet-stream")
post_file("files", content, filename, mime_type: mime_type)
end
|