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, beta: OmniAI::Anthropic.config.beta, 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, beta: OmniAI::Anthropic.config.beta, logger: OmniAI::Anthropic.config.logger, timeout: OmniAI::Anthropic.config.timeout) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omniai/anthropic/client.rb', line 31 def initialize( api_key: OmniAI::Anthropic.config.api_key, host: OmniAI::Anthropic.config.host, version: OmniAI::Anthropic.config.version, beta: OmniAI::Anthropic.config.beta, 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 @beta = beta end |
Instance Method Details
#chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion
70 71 72 |
# File 'lib/omniai/anthropic/client.rb', line 70 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
49 50 51 52 53 54 55 |
# File 'lib/omniai/anthropic/client.rb', line 49 def connection @connection ||= super.headers({ 'x-api-key': @api_key, 'anthropic-version': @version, 'anthropic-beta': @beta, }.compact) end |