Class: OmniAI::OpenAI::Client
- Inherits:
-
Client
- Object
- Client
- OmniAI::OpenAI::Client
- Defined in:
- lib/omniai/openai/client.rb
Overview
Constant Summary collapse
- VERSION =
'v1'
Instance Attribute Summary collapse
-
#api_prefix ⇒ Object
readonly
Returns the value of attribute api_prefix.
Instance Method Summary collapse
- #assistants ⇒ OmniAI::OpenAI::Assistants
- #chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion
- #connection ⇒ HTTP::Client
- #embed(input, model: Embed::DEFAULT_MODEL) ⇒ Object
- #files ⇒ OmniAI::OpenAI::Files
-
#initialize(api_key: OmniAI::OpenAI.config.api_key, api_prefix: '', host: OmniAI::OpenAI.config.host, organization: OmniAI::OpenAI.config.organization, project: OmniAI::OpenAI.config.project, logger: OmniAI::OpenAI.config.logger, timeout: OmniAI::OpenAI.config.timeout) ⇒ Client
constructor
A new instance of Client.
- #speak(input, model: Speak::Model::TTS_1_HD, voice: Speak::Voice::ALLOY, speed: nil, format: nil) {|output| ... } ⇒ Tempfile``
- #threads ⇒ OmniAI::OpenAI::Threads
- #transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ OmniAI::Transcribe
Constructor Details
#initialize(api_key: OmniAI::OpenAI.config.api_key, api_prefix: '', host: OmniAI::OpenAI.config.host, organization: OmniAI::OpenAI.config.organization, project: OmniAI::OpenAI.config.project, logger: OmniAI::OpenAI.config.logger, timeout: OmniAI::OpenAI.config.timeout) ⇒ Client
Returns a new instance of Client.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/omniai/openai/client.rb', line 34 def initialize( api_key: OmniAI::OpenAI.config.api_key, api_prefix: '', host: OmniAI::OpenAI.config.host, organization: OmniAI::OpenAI.config.organization, project: OmniAI::OpenAI.config.project, logger: OmniAI::OpenAI.config.logger, timeout: OmniAI::OpenAI.config.timeout ) if api_key.nil? && host.eql?(Config::DEFAULT_HOST) raise( ArgumentError, %(ENV['OPENAI_API_KEY'] must be defined or `api_key` must be passed when using #{Config::DEFAULT_HOST}) ) end super(api_key:, host:, logger:, timeout:) @organization = organization @project = project @api_prefix = api_prefix return if @api_prefix.empty? || @api_prefix.start_with?('/') @api_prefix.prepend('/') end |
Instance Attribute Details
#api_prefix ⇒ Object (readonly)
Returns the value of attribute api_prefix.
25 26 27 |
# File 'lib/omniai/openai/client.rb', line 25 def api_prefix @api_prefix end |
Instance Method Details
#assistants ⇒ OmniAI::OpenAI::Assistants
138 139 140 |
# File 'lib/omniai/openai/client.rb', line 138 def assistants Assistants.new(client: self) end |
#chat(messages = nil, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil) {|prompt| ... } ⇒ OmniAI::Chat::Completion
85 86 87 |
# File 'lib/omniai/openai/client.rb', line 85 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
62 63 64 65 66 67 68 69 70 |
# File 'lib/omniai/openai/client.rb', line 62 def connection @connection ||= begin http = super http = http.auth("Bearer #{@api_key}") if @api_key http = http.headers('OpenAI-Organization': @organization) if @organization http = http.headers('OpenAI-Project': @project) if @project http end end |
#embed(input, model: Embed::DEFAULT_MODEL) ⇒ Object
93 94 95 |
# File 'lib/omniai/openai/client.rb', line 93 def (input, model: Embed::DEFAULT_MODEL) Embed.process!(input, model:, client: self) end |
#files ⇒ OmniAI::OpenAI::Files
133 134 135 |
# File 'lib/omniai/openai/client.rb', line 133 def files Files.new(client: self) end |
#speak(input, model: Speak::Model::TTS_1_HD, voice: Speak::Voice::ALLOY, speed: nil, format: nil) {|output| ... } ⇒ Tempfile``
128 129 130 |
# File 'lib/omniai/openai/client.rb', line 128 def speak(input, model: Speak::Model::TTS_1_HD, voice: Speak::Voice::ALLOY, speed: nil, format: nil, &) Speak.process!(input, model:, voice:, speed:, format:, client: self, &) end |
#threads ⇒ OmniAI::OpenAI::Threads
143 144 145 |
# File 'lib/omniai/openai/client.rb', line 143 def threads Threads.new(client: self) end |
#transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ OmniAI::Transcribe
107 108 109 |
# File 'lib/omniai/openai/client.rb', line 107 def transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil) Transcribe.process!(path, model:, language:, prompt:, temperature:, format:, client: self) end |