Class: OmniAI::Client
- Inherits:
-
Object
- Object
- OmniAI::Client
- Defined in:
- lib/omniai/client.rb
Overview
Instance Attribute Summary collapse
Class Method Summary collapse
-
.anthropic ⇒ Class<OmniAI::Client>
Initialize a client for Anthropic.
-
.deepseek ⇒ Class<OmniAI::Client>
Initialize a client for DeepSeek.
-
.find(provider:) ⇒ OmniAI::Client
Initialize a client by provider (e.g. ‘openai’).
-
.google ⇒ Class<OmniAI::Client>
Lookup the ‘OmniAI::Google::Client“.
-
.mistral ⇒ Class<OmniAI::Client>
Initialize a client for Mistral.
-
.openai ⇒ Class<OmniAI::Client>
Initialize a client for OpenAI.
Instance Method Summary collapse
- #chat(messages = nil, model:, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Response
- #connection ⇒ HTTP::Client
- #embed(input, model:) ⇒ OmniAI::Embed::Embedding
-
#initialize(api_key: nil, logger: nil, host: nil, timeout: nil) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ String
- #masked_api_key ⇒ String
- #speak(input, model:, voice:, speed: nil, format: nil) {|output| ... } ⇒ Tempfile
- #transcribe(io, model:, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ OmniAI::Transcribe::Transcription
Constructor Details
#initialize(api_key: nil, logger: nil, host: nil, timeout: nil) ⇒ Client
Returns a new instance of Client.
120 121 122 123 124 125 |
# File 'lib/omniai/client.rb', line 120 def initialize(api_key: nil, logger: nil, host: nil, timeout: nil) @api_key = api_key @host = host @logger = logger @timeout = timeout end |
Instance Attribute Details
#api_key ⇒ String?
21 22 23 |
# File 'lib/omniai/client.rb', line 21 def api_key @api_key end |
#host ⇒ String?
29 30 31 |
# File 'lib/omniai/client.rb', line 29 def host @host end |
#logger ⇒ Logger?
25 26 27 |
# File 'lib/omniai/client.rb', line 25 def logger @logger end |
#timeout ⇒ Integer?
33 34 35 |
# File 'lib/omniai/client.rb', line 33 def timeout @timeout end |
Class Method Details
.anthropic ⇒ Class<OmniAI::Client>
Initialize a client for Anthropic. This method requires the provider if it is undefined.
40 41 42 43 44 45 |
# File 'lib/omniai/client.rb', line 40 def self.anthropic require "omniai/anthropic" unless defined?(OmniAI::Anthropic::Client) OmniAI::Anthropic::Client rescue ::LoadError raise Error, "requires 'omniai-anthropic': `gem install omniai-anthropic`" end |
.deepseek ⇒ Class<OmniAI::Client>
Initialize a client for DeepSeek. This method requires the provider if it is undefined.
52 53 54 55 56 57 |
# File 'lib/omniai/client.rb', line 52 def self.deepseek require "omniai/deepseek" unless defined?(OmniAI::DeepSeek::Client) OmniAI::DeepSeek::Client rescue ::LoadError raise Error, "requires 'omniai-deepseek': `gem install omniai-deepseek`" end |
.find(provider:) ⇒ OmniAI::Client
Initialize a client by provider (e.g. ‘openai’). This method attempts to require the provider.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/omniai/client.rb', line 102 def self.find(provider:, **) klass = case provider when :anthropic, "anthropic" then anthropic when :deepseek, "deepseek" then deepseek when :google, "google" then google when :mistral, "mistral" then mistral when :openai, "openai" then openai else raise Error, "unknown provider=#{provider.inspect}" end klass.new(**) end |
.google ⇒ Class<OmniAI::Client>
Lookup the ‘OmniAI::Google::Client“. This method requires the provider if it is undefined.
64 65 66 67 68 69 |
# File 'lib/omniai/client.rb', line 64 def self.google require "omniai/google" unless defined?(OmniAI::Google::Client) OmniAI::Google::Client rescue ::LoadError raise Error, "requires 'omniai-google': `gem install omniai-google`" end |
.mistral ⇒ Class<OmniAI::Client>
Initialize a client for Mistral. This method requires the provider if it is undefined.
76 77 78 79 80 81 |
# File 'lib/omniai/client.rb', line 76 def self.mistral require "omniai/mistral" unless defined?(OmniAI::Mistral::Client) OmniAI::Mistral::Client rescue ::LoadError raise Error, "requires 'omniai-mistral': `gem install omniai-mistral`" end |
.openai ⇒ Class<OmniAI::Client>
Initialize a client for OpenAI. This method requires the provider if it is undefined.
88 89 90 91 92 93 |
# File 'lib/omniai/client.rb', line 88 def self.openai require "omniai/openai" unless defined?(OmniAI::OpenAI::Client) OmniAI::OpenAI::Client rescue ::LoadError raise Error, "requires 'omniai-openai': `gem install omniai-openai`" end |
Instance Method Details
#chat(messages = nil, model:, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Response
161 162 163 |
# File 'lib/omniai/client.rb', line 161 def chat( = nil, model:, temperature: nil, format: nil, stream: nil, tools: nil, &) raise NotImplementedError, "#{self.class.name}#chat undefined" end |
#connection ⇒ HTTP::Client
141 142 143 144 145 146 |
# File 'lib/omniai/client.rb', line 141 def connection http = HTTP.persistent(@host) http = http.use(instrumentation: { instrumenter: Instrumentation.new(logger: @logger) }) if @logger http = http.timeout(@timeout) if @timeout http end |
#embed(input, model:) ⇒ OmniAI::Embed::Embedding
206 207 208 |
# File 'lib/omniai/client.rb', line 206 def (input, model:) raise NotImplementedError, "#{self.class.name}#embed undefined" end |
#inspect ⇒ String
128 129 130 131 132 133 |
# File 'lib/omniai/client.rb', line 128 def inspect props = [] props << "api_key=#{masked_api_key.inspect}" if @api_key props << "host=#{@host.inspect}" if @host "#<#{self.class.name} #{props.join(' ')}>" end |
#masked_api_key ⇒ String
136 137 138 |
# File 'lib/omniai/client.rb', line 136 def masked_api_key "#{api_key[..2]}***" if api_key end |
#speak(input, model:, voice:, speed: nil, format: nil) {|output| ... } ⇒ Tempfile
196 197 198 |
# File 'lib/omniai/client.rb', line 196 def speak(input, model:, voice:, speed: nil, format: nil, &stream) raise NotImplementedError, "#{self.class.name}#speak undefined" end |
#transcribe(io, model:, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ OmniAI::Transcribe::Transcription
175 176 177 |
# File 'lib/omniai/client.rb', line 175 def transcribe(io, model:, language: nil, prompt: nil, temperature: nil, format: nil) raise NotImplementedError, "#{self.class.name}#transcribe undefined" end |