omniai-openai 1.0.1 → 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: 17b76524bf985fda37fec8e7cea18aece3380a1831be7de6abe2652767aafc92
4
- data.tar.gz: e32a791f07f2697f56f2dfa15f11e8b05abf4416610925880d12cc7b5d0dda90
3
+ metadata.gz: f35b8f18f1fed4fc62a4d69d1ec9d94b7b93dfe6d7110e9f64369625cafd8702
4
+ data.tar.gz: 746528fa3065f9f843bafb9b82946dda6d57bb121b81bbf6a8f4c43e72e1888e
5
5
  SHA512:
6
- metadata.gz: 9aa657f83ece505e056597a36c73a77f24abc45af4094c5e982b949bc9631ba6a401ff410220855c43073232578bda7fe37ed7003e006259caaf8d1333825dab
7
- data.tar.gz: a96fe7cb53c737220b21c43013af12fab828476336827c446bfb12e64b02340ef55cac0a762facd0d5103db8afad078bf72b94fe760bbda2d36437eeee68468b
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
@@ -49,7 +49,7 @@ completion.choice.message.content # 'Why did the chicken cross the road? To get
49
49
 
50
50
  ```ruby
51
51
  completion = client.chat.completion({
52
- role: OmniAI::OpenAI::Chat::Role::USER,
52
+ role: OmniAI::Chat::Role::USER,
53
53
  content: 'Is it wise to jump off a bridge?'
54
54
  })
55
55
  completion.choice.message.content # 'No.'
@@ -58,7 +58,7 @@ completion.choice.message.content # 'No.'
58
58
  ```ruby
59
59
  completion = client.chat.completion([
60
60
  {
61
- role: OmniAI::OpenAI::Chat::Role::SYSTEM,
61
+ role: OmniAI::Chat::Role::SYSTEM,
62
62
  content: 'You are a helpful assistant.'
63
63
  },
64
64
  'What is the capital of Canada?',
@@ -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.1'
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.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-14 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: []
@@ -72,7 +73,7 @@ metadata:
72
73
  homepage_uri: https://github.com/ksylvest/omniai-openai
73
74
  changelog_uri: https://github.com/ksylvest/omniai-openai/releases
74
75
  rubygems_mfa_required: 'true'
75
- post_install_message:
76
+ post_install_message:
76
77
  rdoc_options: []
77
78
  require_paths:
78
79
  - lib
@@ -87,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.5.11
91
- signing_key:
91
+ rubygems_version: 3.5.3
92
+ signing_key:
92
93
  specification_version: 4
93
94
  summary: A generalized framework for interacting with OpenAI
94
95
  test_files: []