Class: OmniAI::Anthropic::Client
- Inherits:
-
Client
- Object
- Client
- OmniAI::Anthropic::Client
- Defined in:
- lib/omniai/anthropic/client.rb
Overview
An Anthropic client implementation. Usage:
w/ ‘api_key“:
client = OmniAI::Anthropic::Client.new(api_key: '...')
w/ ENV:
ENV['ANTHROPIC_API_KEY'] = '...'
client = OmniAI::Anthropic::Client.new
w/ config:
OmniAI::Anthropic.configure do |config|
config.api_key = '...'
end
client = OmniAI::Anthropic::Client.new
Constant Summary collapse
- VERSION =
'v1'
Instance Method Summary collapse
- #chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion
- #connection ⇒ HTTP::Client
-
#initialize(api_key: OmniAI::Anthropic.config.api_key, host: OmniAI::Anthropic.config.host, version: OmniAI::Anthropic.config.version, logger: OmniAI::Anthropic.config.logger, timeout: OmniAI::Anthropic.config.timeout) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(api_key: OmniAI::Anthropic.config.api_key, host: OmniAI::Anthropic.config.host, version: OmniAI::Anthropic.config.version, logger: OmniAI::Anthropic.config.logger, timeout: OmniAI::Anthropic.config.timeout) ⇒ Client
Returns a new instance of Client.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omniai/anthropic/client.rb', line 30 def initialize( api_key: OmniAI::Anthropic.config.api_key, host: OmniAI::Anthropic.config.host, version: OmniAI::Anthropic.config.version, logger: OmniAI::Anthropic.config.logger, timeout: OmniAI::Anthropic.config.timeout ) raise(ArgumentError, %(ENV['ANTHROPIC_API_KEY'] must be defined or `api_key` must be passed)) if api_key.nil? super(api_key:, host:, logger:, timeout:) @host = host @version = version end |
Instance Method Details
#chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion
66 67 68 |
# File 'lib/omniai/anthropic/client.rb', line 66 def chat( = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil, &) Chat.process!(, model:, temperature:, format:, stream:, tools:, client: self, &) end |
#connection ⇒ HTTP::Client
46 47 48 49 50 51 |
# File 'lib/omniai/anthropic/client.rb', line 46 def connection @connection ||= super.headers({ 'x-api-key': @api_key, 'anthropic-version': @version, }.compact) end |