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 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, 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, 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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omniai/openai/client.rb', line 31 def initialize( api_key: OmniAI::OpenAI.config.api_key, 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 end |
Instance Method Details
#assistants ⇒ OmniAI::OpenAI::Assistants
129 130 131 |
# File 'lib/omniai/openai/client.rb', line 129 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
76 77 78 |
# File 'lib/omniai/openai/client.rb', line 76 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
53 54 55 56 57 58 59 60 61 |
# File 'lib/omniai/openai/client.rb', line 53 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
84 85 86 |
# File 'lib/omniai/openai/client.rb', line 84 def (input, model: Embed::DEFAULT_MODEL) Embed.process!(input, model:, client: self) end |
#files ⇒ OmniAI::OpenAI::Files
124 125 126 |
# File 'lib/omniai/openai/client.rb', line 124 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``
119 120 121 |
# File 'lib/omniai/openai/client.rb', line 119 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
134 135 136 |
# File 'lib/omniai/openai/client.rb', line 134 def threads Threads.new(client: self) end |
#transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil) ⇒ OmniAI::Transcribe
98 99 100 |
# File 'lib/omniai/openai/client.rb', line 98 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 |