omniai-openai 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 667d8318e96d3e6611a3ca20ced5dcefefc0896a4c84c48427ce441756cb9e60
4
- data.tar.gz: 13161c5726cc33fcc7934a4164f751244b3c577fb52a1cdf30301dc10f733c84
3
+ metadata.gz: f35b8f18f1fed4fc62a4d69d1ec9d94b7b93dfe6d7110e9f64369625cafd8702
4
+ data.tar.gz: 746528fa3065f9f843bafb9b82946dda6d57bb121b81bbf6a8f4c43e72e1888e
5
5
  SHA512:
6
- metadata.gz: d44485bdcebe5ee67a846c4517ea62fdb4fd98dfbab464f64fd10316561a396369ce5579367c8f073d79edfee0a790baa46c2fc31dfd2a4522221f0d16679a23
7
- data.tar.gz: 2f1054f58e35f37012bc6b95f7605b0eeee01010718c2446a14b623b37cde0028d08ed56330d10bf1145fe5dfa69c3c138f54f5ec7d2bf65e55eb4727a21c664
6
+ metadata.gz: 4a11987f0c6dceeed121166820240c9c878ddc7f88b7c2cf2598c5f14ed5cdc1d6730d3463396f4c56b38f37d7ac4d983b7af461afd00c58db613a58b887d075
7
+ data.tar.gz: 129bd67690492743d3945fc15da22d5b9f4ec1bc384c56d8dcd2d60d1fd0419f802c6b804cbf154efdd4828d5e42220a30f890d58c08f9aaa634c1c8ba8bfa20
data/Gemfile CHANGED
@@ -11,4 +11,5 @@ gem 'rspec_junit_formatter'
11
11
  gem 'rubocop'
12
12
  gem 'rubocop-rake'
13
13
  gem 'rubocop-rspec'
14
+ gem 'simplecov'
14
15
  gem 'webmock'
data/README.md CHANGED
@@ -116,3 +116,56 @@ JSON.parse(completion.choice.message.content) # { "name": "Ringo" }
116
116
  [OpenAI API Reference `response_format`](https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream)
117
117
 
118
118
  > When using JSON mode, you must also instruct the model to produce JSON yourself via a system or user message.
119
+
120
+ ### Transcribe
121
+
122
+ A transcription is generated by passing in a path to a file:
123
+
124
+ ```ruby
125
+ transcription = client.transcribe(file.path)
126
+ transcription.text # '...'
127
+ ```
128
+
129
+ #### Prompt
130
+
131
+ `prompt` is optional and can provide additional context for transcribing:
132
+
133
+ ```ruby
134
+ transcription = client.transcribe(file.path, prompt: '')
135
+ transcription.text # '...'
136
+ ```
137
+
138
+ [OpenAI API Reference `prompt`](https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-prompt)
139
+
140
+ #### Format
141
+
142
+ `format` is optional and supports `json`, `text`, `srt` or `vtt`:
143
+
144
+ ```ruby
145
+ transcription = client.transcribe(file.path, format: OmniAI::Transcribe::Format::TEXT)
146
+ transcription.text # '...'
147
+ ```
148
+
149
+ [OpenAI API Reference `response_format`](https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-response_format)
150
+
151
+ #### Language
152
+
153
+ `language` is optional and may improve accuracy and latency:
154
+
155
+ ```ruby
156
+ transcription = client.transcribe(file.path, language: OmniAI::Transcribe::Language::SPANISH)
157
+ transcription.text
158
+ ```
159
+
160
+ [OpenAI API Reference `language`](https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-language)
161
+
162
+ #### Temperature
163
+
164
+ `temperature` is optional and must be between 0.0 (more deterministic) and 1.0 (less deterministic):
165
+
166
+ ```ruby
167
+ transcription = client.transcribe(file.path, temperature: 0.2)
168
+ transcription.text
169
+ ```
170
+
171
+ [OpenAI API Reference `temperature`](https://platform.openai.com/docs/api-reference/audio/createTranscription#audio-createtranscription-temperature)
@@ -64,6 +64,20 @@ module OmniAI
64
64
  def chat(messages, model: Chat::Model::GPT_4O, temperature: nil, format: nil, stream: nil)
65
65
  Chat.process!(messages, model:, temperature:, format:, stream:, client: self)
66
66
  end
67
+
68
+ # @raise [OmniAI::Error]
69
+ #
70
+ # @param path [String]
71
+ # @param model [String]
72
+ # @param language [String, nil] optional
73
+ # @param prompt [String, nil] optional
74
+ # @param temperature [Float, nil] optional
75
+ # @param format [Symbol] :text, :srt, :vtt, or :json (default)
76
+ #
77
+ # @return text [OmniAI::Transcribe::Transcription]
78
+ def transcribe(path, model: Transcribe::Model::WHISPER, language: nil, prompt: nil, temperature: nil, format: nil)
79
+ Transcribe.process!(path, model:, language:, prompt:, temperature:, format:, client: self)
80
+ end
67
81
  end
68
82
  end
69
83
  end
@@ -4,7 +4,7 @@ module OmniAI
4
4
  module OpenAI
5
5
  # Configuration for managing the OpenAI `api_key` / `organization` / `project` / `logger`.
6
6
  class Config < OmniAI::Config
7
- attr_accessor :organization, :project, :chat_options
7
+ attr_accessor :organization, :project, :chat_options, :transcribe_options
8
8
 
9
9
  def initialize
10
10
  super
@@ -13,6 +13,7 @@ module OmniAI
13
13
  @project = ENV.fetch('OPENAI_PROJECT', nil)
14
14
  @host = ENV.fetch('OPENAI_HOST', 'https://api.openai.com')
15
15
  @chat_options = {}
16
+ @transcribe_options = {}
16
17
  end
17
18
  end
18
19
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ module OpenAI
5
+ # An OpenAI transcribe implementation.
6
+ class Transcribe < OmniAI::Transcribe
7
+ module Model
8
+ WHISPER_1 = 'whisper-1'
9
+ WHISPER = WHISPER_1
10
+ end
11
+
12
+ protected
13
+
14
+ # @return [Hash]
15
+ def payload
16
+ OmniAI::OpenAI
17
+ .config.transcribe_options
18
+ .merge(super)
19
+ .merge({ response_format: @format || Format::JSON })
20
+ end
21
+
22
+ # @return [String]
23
+ def path
24
+ "/#{OmniAI::OpenAI::Client::VERSION}/audio/transcriptions"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-openai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2024-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: event_stream_parser
@@ -65,6 +65,7 @@ files:
65
65
  - lib/omniai/openai/chat.rb
66
66
  - lib/omniai/openai/client.rb
67
67
  - lib/omniai/openai/config.rb
68
+ - lib/omniai/openai/transcribe.rb
68
69
  - lib/omniai/openai/version.rb
69
70
  homepage: https://github.com/ksylvest/omniai-openai
70
71
  licenses: []