omniai 1.9.2 → 1.9.4

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: 4f2dff570036129e4ae7b41a113f644a19a6dd1c75e71852721c5f7fc5fdd068
4
- data.tar.gz: d48375ab7e70758ad7fc931d0ac70f739807e10cc35bc22161ddcb8a758fc0b7
3
+ metadata.gz: eca1c768ff6bacdf521418a896e115253ad01e80848bb3a2416772b18e17cc84
4
+ data.tar.gz: 78a171dc3b7ccf17765166836f12daca5cc14baaa77396f680682b7c9ceb4a4b
5
5
  SHA512:
6
- metadata.gz: 537c4e16730332602dccfc9fb3011f99739fdfec133362b362fded6e2fb54ec66c7070872426f331f6160dd3fdd3e82c61b7bfb326c8c2a5399fe662eb51acfc
7
- data.tar.gz: 79b2adcacba078cbd8aa72330a9d8f6a1e1895e5824cccbf89bab50a86a789fdd83f49d23a70f39785912273ce8826cbbc6eba40eee2d7d671ff52a34b1bb171
6
+ metadata.gz: 865e34d906b82247bbd5a664610e96fdc256b40d9701b5cd2d1cb5166d1334dda233272117d7065a7dabd2e25e77a5e454ea2cb8af028f63b8998dfc575cd67c
7
+ data.tar.gz: 57951e245c5b6a29e5d147b0c91c6a1decb37bca7af7aabe9580a51016d332343f981d4bab733fef5350c6a40024633e0792e1ecceefc245dbe8f781d5bcf1a4
data/Gemfile CHANGED
@@ -1,18 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'factory_bot'
8
- gem 'logger'
9
- gem 'rake'
10
- gem 'rspec'
11
- gem 'rspec_junit_formatter'
12
- gem 'rubocop'
13
- gem 'rubocop-factory_bot'
14
- gem 'rubocop-rake'
15
- gem 'rubocop-rspec'
16
- gem 'simplecov'
17
- gem 'webmock'
18
- gem 'yard'
7
+ gem "factory_bot"
8
+ gem "irb"
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rspec_junit_formatter"
12
+ gem "rubocop"
13
+ gem "rubocop-basic"
14
+ gem "rubocop-factory_bot"
15
+ gem "rubocop-rake"
16
+ gem "rubocop-rspec"
17
+ gem "simplecov"
18
+ gem "webmock"
19
+ gem "yard"
data/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  OmniAI standardizes the APIs of various AI / LLM companies such as Anthropic, Google, Mistral and OpenAI for the generation of text, the conversion of text-to-speech, the conversion of speech-to-text, the generation of embeddings, and more. It offers a unified API regardless of the provider and task.
10
10
 
11
11
  - [OmniAI::Anthropic](https://github.com/ksylvest/omniai-anthropic)
12
+ - [OmniAI::DeepSeek](https://github.com/ksylvest/omniai-deepseek)
12
13
  - [OmniAI::Google](https://github.com/ksylvest/omniai-google)
13
14
  - [OmniAI::Mistral](https://github.com/ksylvest/omniai-mistral)
14
15
  - [OmniAI::OpenAI](https://github.com/ksylvest/omniai-openai)
@@ -167,12 +168,17 @@ search('Who do you call to fix a toilet?')
167
168
 
168
169
  ## Installation
169
170
 
171
+ The main `omniai` gem is installed with:
172
+
170
173
  ```sh
171
174
  gem install omniai
172
175
  ```
173
176
 
177
+ Specific provider gems are installed with:
178
+
174
179
  ```sh
175
180
  gem install omniai-anthropic
181
+ gem install omniai-deepseek
176
182
  gem install omniai-mistral
177
183
  gem install omniai-google
178
184
  gem install omniai-openai
@@ -192,6 +198,14 @@ require 'omniai/anthropic'
192
198
  client = OmniAI::Anthropic::Client.new
193
199
  ```
194
200
 
201
+ #### [OmniAI::DeepSeek](https://github.com/ksylvest/omniai-deepseek)
202
+
203
+ ```ruby
204
+ require 'omniai/deepseek'
205
+
206
+ client = OmniAI::DeepSeek::Client.new
207
+ ```
208
+
195
209
  #### [OmniAI::Google](https://github.com/ksylvest/omniai-google)
196
210
 
197
211
  ```ruby
data/bin/console CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'bundler/setup'
5
- require 'omniai'
4
+ require "bundler/setup"
5
+ require "omniai"
6
6
 
7
- require 'irb'
7
+ require "irb"
8
8
  IRB.start(__FILE__)
data/exe/omniai CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'omniai'
4
+ require "omniai"
5
5
 
6
6
  cli = OmniAI::CLI.new
7
7
  cli.parse
@@ -31,8 +31,8 @@ module OmniAI
31
31
  deserialize = context&.deserializer(:choice)
32
32
  return deserialize.call(data, context:) if deserialize
33
33
 
34
- index = data['index']
35
- message = Message.deserialize(data['message'] || data['delta'], context:)
34
+ index = data["index"]
35
+ message = Message.deserialize(data["message"] || data["delta"], context:)
36
36
 
37
37
  new(message:, index:)
38
38
  end
@@ -32,10 +32,10 @@ module OmniAI
32
32
 
33
33
  return data if data.is_a?(String)
34
34
 
35
- raise ArgumentError, "untyped data=#{data.inspect}" unless data.key?('type')
35
+ raise ArgumentError, "untyped data=#{data.inspect}" unless data.key?("type")
36
36
 
37
- case data['type']
38
- when 'text' then Text.deserialize(data, context:)
37
+ case data["type"]
38
+ when "text" then Text.deserialize(data, context:)
39
39
  when /(.*)_url/ then URL.deserialize(data, context:)
40
40
  else raise ArgumentError, "unknown type=#{data['type'].inspect}"
41
41
  end
@@ -44,7 +44,7 @@ module OmniAI
44
44
  def filename
45
45
  case @io
46
46
  when Tempfile, File, String then ::File.basename(@io)
47
- else 'DATA'
47
+ else "DATA"
48
48
  end
49
49
  end
50
50
  end
@@ -30,11 +30,11 @@ module OmniAI
30
30
  deserialize = context&.deserializer(:function)
31
31
  return deserialize.call(data, context:) if deserialize
32
32
 
33
- name = data['name']
33
+ name = data["name"]
34
34
  arguments = begin
35
- JSON.parse(data['arguments']) if data['arguments']
35
+ JSON.parse(data["arguments"]) if data["arguments"]
36
36
  rescue JSON::ParserError
37
- data['arguments']
37
+ data["arguments"]
38
38
  end
39
39
 
40
40
  new(name:, arguments:)
@@ -30,7 +30,7 @@ module OmniAI
30
30
  #
31
31
  # @return [Message]
32
32
  def self.build(content = nil, role: Role::USER, &block)
33
- raise ArgumentError, 'content or block is required' if content.nil? && block.nil?
33
+ raise ArgumentError, "content or block is required" if content.nil? && block.nil?
34
34
 
35
35
  Builder.build(role:) do |builder|
36
36
  builder.text(content) if content
@@ -81,9 +81,9 @@ module OmniAI
81
81
  deserialize = context&.deserializer(:message)
82
82
  return deserialize.call(data, context:) if deserialize
83
83
 
84
- role = data['role']
85
- content = Content.deserialize(data['content'], context:)
86
- tool_call_list = data['tool_calls']&.map { |subdata| ToolCall.deserialize(subdata, context:) }
84
+ role = data["role"]
85
+ content = Content.deserialize(data["content"], context:)
86
+ tool_call_list = data["tool_calls"]&.map { |subdata| ToolCall.deserialize(subdata, context:) }
87
87
 
88
88
  new(content:, role:, tool_call_list:)
89
89
  end
@@ -28,8 +28,8 @@ module OmniAI
28
28
  deserialize = context&.deserializer(:payload)
29
29
  return deserialize.call(data, context:) if deserialize
30
30
 
31
- choices = data['choices'].map { |choice_data| Choice.deserialize(choice_data, context:) }
32
- usage = Usage.deserialize(data['usage'], context:) if data['usage']
31
+ choices = data["choices"].map { |choice_data| Choice.deserialize(choice_data, context:) }
32
+ usage = Usage.deserialize(data["usage"], context:) if data["usage"]
33
33
 
34
34
  new(choices:, usage:)
35
35
  end
@@ -23,7 +23,7 @@ module OmniAI
23
23
  end
24
24
  end
25
25
 
26
- protected
26
+ protected
27
27
 
28
28
  # @param type [String]
29
29
  # @param data [String]
@@ -47,7 +47,7 @@ module OmniAI
47
47
  def process!(type, data, id, &block)
48
48
  log(type, data, id)
49
49
 
50
- return if data.eql?('[DONE]')
50
+ return if data.eql?("[DONE]")
51
51
 
52
52
  block.call(Payload.deserialize(JSON.parse(data), context: @context))
53
53
  end
@@ -28,7 +28,7 @@ module OmniAI
28
28
  deserialize = context&.deserializer(:text)
29
29
  return deserialize.call(data, context:) if deserialize
30
30
 
31
- new(data['text'])
31
+ new(data["text"])
32
32
  end
33
33
 
34
34
  # @param context [Context] optional
@@ -38,7 +38,7 @@ module OmniAI
38
38
  serializer = context&.serializer(:text)
39
39
  return serializer.call(self, context:) if serializer
40
40
 
41
- { type: 'text', text: @text }
41
+ { type: "text", text: @text }
42
42
  end
43
43
  end
44
44
  end
@@ -30,8 +30,8 @@ module OmniAI
30
30
  deserialize = context&.deserializer(:tool_call)
31
31
  return deserialize.call(data, context:) if deserialize
32
32
 
33
- id = data['id']
34
- function = Function.deserialize(data['function'], context:)
33
+ id = data["id"]
34
+ function = Function.deserialize(data["function"], context:)
35
35
 
36
36
  new(id:, function:)
37
37
  end
@@ -45,7 +45,7 @@ module OmniAI
45
45
 
46
46
  {
47
47
  id: @id,
48
- type: 'function',
48
+ type: "function",
49
49
  function: @function.serialize(context:),
50
50
  }
51
51
  end
@@ -31,9 +31,9 @@ module OmniAI
31
31
  deserialize = context&.deserializer(:tool_message)
32
32
  return deserialize.call(data, context:) if deserialize
33
33
 
34
- role = data['role']
35
- content = JSON.parse(data['content'])
36
- tool_call_id = data['tool_call_id']
34
+ role = data["role"]
35
+ content = JSON.parse(data["content"])
36
+ tool_call_id = data["tool_call_id"]
37
37
 
38
38
  new(role:, content:, tool_call_id:)
39
39
  end
@@ -41,8 +41,8 @@ module OmniAI
41
41
  deserialize = context&.deserializer(:tool_call_result)
42
42
  return deserialize.call(data, context:) if deserialize
43
43
 
44
- content = JSON.parse(data['content'])
45
- tool_call_id = data['tool_call_id']
44
+ content = JSON.parse(data["content"])
45
+ tool_call_id = data["tool_call_id"]
46
46
 
47
47
  new(content:, tool_call_id:)
48
48
  end
@@ -31,8 +31,8 @@ module OmniAI
31
31
  deserialize = context&.deserializer(:url)
32
32
  return deserialize.call(data, context:) if deserialize
33
33
 
34
- type = /(?<type>\w+)_url/.match(data['type'])[:type]
35
- uri = data["#{type}_url"]['url']
34
+ type = /(?<type>\w+)_url/.match(data["type"])[:type]
35
+ uri = data["#{type}_url"]["url"]
36
36
 
37
37
  new(uri, type)
38
38
  end
@@ -68,7 +68,7 @@ module OmniAI
68
68
  ::File.basename(@uri)
69
69
  end
70
70
 
71
- protected
71
+ protected
72
72
 
73
73
  # @raise [FetchError]
74
74
  #
@@ -35,9 +35,9 @@ module OmniAI
35
35
  deserialize = context&.deserializer(:usage)
36
36
  return deserialize.call(data, context:) if deserialize
37
37
 
38
- input_tokens = data['input_tokens']
39
- output_tokens = data['output_tokens']
40
- total_tokens = data['total_tokens']
38
+ input_tokens = data["input_tokens"]
39
+ output_tokens = data["output_tokens"]
40
+ total_tokens = data["total_tokens"]
41
41
 
42
42
  new(input_tokens:, output_tokens:, total_tokens:)
43
43
  end
data/lib/omniai/chat.rb CHANGED
@@ -25,7 +25,7 @@ module OmniAI
25
25
  #
26
26
  # client.chat(messages, model: "...", temperature: 0.0, format: :text)
27
27
  class Chat
28
- JSON_PROMPT = 'Respond with valid JSON. Do not include any non-JSON in the response.'
28
+ JSON_PROMPT = "Respond with valid JSON. Do not include any non-JSON in the response."
29
29
 
30
30
  # An error raised for tool-call issues.
31
31
  class ToolCallError < Error
@@ -45,10 +45,10 @@ module OmniAI
45
45
  end
46
46
 
47
47
  module Role
48
- ASSISTANT = 'assistant'
49
- USER = 'user'
50
- SYSTEM = 'system'
51
- TOOL = 'tool'
48
+ ASSISTANT = "assistant"
49
+ USER = "user"
50
+ SYSTEM = "system"
51
+ TOOL = "tool"
52
52
  end
53
53
 
54
54
  module Format
@@ -72,7 +72,7 @@ module OmniAI
72
72
  #
73
73
  # @return [OmniAi::Chat]
74
74
  def initialize(prompt = nil, client:, model:, temperature: nil, stream: nil, tools: nil, format: nil, &block)
75
- raise ArgumentError, 'prompt or block is required' if !prompt && !block
75
+ raise ArgumentError, "prompt or block is required" if !prompt && !block
76
76
 
77
77
  @prompt = prompt ? Prompt.parse(prompt) : Prompt.new
78
78
  block&.call(@prompt)
@@ -94,7 +94,7 @@ module OmniAI
94
94
  parse!(response:)
95
95
  end
96
96
 
97
- protected
97
+ protected
98
98
 
99
99
  # Override to provide an context for serializers / deserializes for a provider.
100
100
  #
@@ -8,14 +8,14 @@ module OmniAI
8
8
  # @param stdout [IO] an optional stream for stdout
9
9
  # @param provider [String] an optional provider (defaults to 'openai')
10
10
  # @param argv [Array<String>]
11
- def self.handle!(argv:, stdin: $stdin, stdout: $stdout, provider: 'openai')
11
+ def self.handle!(argv:, stdin: $stdin, stdout: $stdout, provider: "openai")
12
12
  new(stdin:, stdout:, provider:).handle!(argv:)
13
13
  end
14
14
 
15
15
  # @param stdin [IO] an optional stream for stdin
16
16
  # @param stdout [IO] an optional stream for stdout
17
17
  # @param provider [String] an optional provider (defaults to 'openai')
18
- def initialize(stdin: $stdin, stdout: $stdout, provider: 'openai')
18
+ def initialize(stdin: $stdin, stdout: $stdout, provider: "openai")
19
19
  @stdin = stdin
20
20
  @stdout = stdout
21
21
  @provider = provider
@@ -27,7 +27,7 @@ module OmniAI
27
27
  raise NotImplementedError, "#{self.class}#handle! undefined"
28
28
  end
29
29
 
30
- private
30
+ private
31
31
 
32
32
  # @return [OmniAI::Client]
33
33
  def client
@@ -11,17 +11,17 @@ module OmniAI
11
11
  if argv.empty?
12
12
  listen!
13
13
  else
14
- chat(prompt: argv.join(' '))
14
+ chat(prompt: argv.join(" "))
15
15
  end
16
16
  end
17
17
 
18
- private
18
+ private
19
19
 
20
20
  def listen!
21
21
  @stdout.puts('Type "exit" or "quit" to leave.')
22
22
 
23
23
  loop do
24
- @stdout.print('# ')
24
+ @stdout.print("# ")
25
25
  @stdout.flush
26
26
  prompt = @stdin.gets&.chomp
27
27
 
@@ -43,17 +43,17 @@ module OmniAI
43
43
  OptionParser.new do |options|
44
44
  options.banner = 'usage: omniai chat [options] "<prompt>"'
45
45
 
46
- options.on('-h', '--help', 'help') do
46
+ options.on("-h", "--help", "help") do
47
47
  @stdout.puts(options)
48
48
  exit
49
49
  end
50
50
 
51
- options.on('-p', '--provider=PROVIDER', 'provider') { |provider| @provider = provider }
52
- options.on('-m', '--model=MODEL', 'model') { |model| @args[:model] = model }
53
- options.on('-t', '--temperature=TEMPERATURE', Float, 'temperature') do |temperature|
51
+ options.on("-p", "--provider=PROVIDER", "provider") { |provider| @provider = provider }
52
+ options.on("-m", "--model=MODEL", "model") { |model| @args[:model] = model }
53
+ options.on("-t", "--temperature=TEMPERATURE", Float, "temperature") do |temperature|
54
54
  @args[:temperature] = temperature
55
55
  end
56
- options.on('-f', '--format=FORMAT', 'format') { |format| @args[:format] = format.intern }
56
+ options.on("-f", "--format=FORMAT", "format") { |format| @args[:format] = format.intern }
57
57
  end
58
58
  end
59
59
  end
@@ -11,17 +11,17 @@ module OmniAI
11
11
  if argv.empty?
12
12
  listen!
13
13
  else
14
- embed(input: argv.join(' '))
14
+ embed(input: argv.join(" "))
15
15
  end
16
16
  end
17
17
 
18
- private
18
+ private
19
19
 
20
20
  def listen!
21
21
  @stdout.puts('Type "exit" or "quit" to leave.')
22
22
 
23
23
  loop do
24
- @stdout.print('# ')
24
+ @stdout.print("# ")
25
25
  @stdout.flush
26
26
  input = @stdin.gets&.chomp
27
27
 
@@ -44,13 +44,13 @@ module OmniAI
44
44
  OptionParser.new do |options|
45
45
  options.banner = 'usage: omniai embed [options] "<prompt>"'
46
46
 
47
- options.on('-h', '--help', 'help') do
47
+ options.on("-h", "--help", "help") do
48
48
  @stdout.puts(options)
49
49
  exit
50
50
  end
51
51
 
52
- options.on('-p', '--provider=PROVIDER', 'provider') { |provider| @provider = provider }
53
- options.on('-m', '--model=MODEL', 'model') { |model| @args[:model] = model }
52
+ options.on("-p", "--provider=PROVIDER", "provider") { |provider| @provider = provider }
53
+ options.on("-m", "--model=MODEL", "model") { |model| @args[:model] = model }
54
54
  end
55
55
  end
56
56
  end
data/lib/omniai/cli.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'optparse'
3
+ require "optparse"
4
4
 
5
5
  module OmniAI
6
6
  # Used when interacting with the suite from the command line interface (CLI).
@@ -15,7 +15,7 @@ module OmniAI
15
15
  # @param stdin [IO] a stream
16
16
  # @param stdout [IO] a stream
17
17
  # @param provider [String] a provider
18
- def initialize(stdin: $stdin, stdout: $stdout, provider: 'openai')
18
+ def initialize(stdin: $stdin, stdout: $stdout, provider: "openai")
19
19
  @stdin = stdin
20
20
  @stdout = stdout
21
21
  @provider = provider
@@ -30,32 +30,32 @@ module OmniAI
30
30
 
31
31
  handler =
32
32
  case command
33
- when 'chat' then ChatHandler
34
- when 'embed' then EmbedHandler
33
+ when "chat" then ChatHandler
34
+ when "embed" then EmbedHandler
35
35
  else raise Error, "unsupported command=#{command.inspect}"
36
36
  end
37
37
 
38
38
  handler.handle!(stdin: @stdin, stdout: @stdout, provider: @provider, argv:)
39
39
  end
40
40
 
41
- private
41
+ private
42
42
 
43
43
  # @return [OptionParser]
44
44
  def parser
45
45
  OptionParser.new do |options|
46
- options.banner = 'usage: omniai [options] <command> [<args>]'
46
+ options.banner = "usage: omniai [options] <command> [<args>]"
47
47
 
48
- options.on('-h', '--help', 'help') do
48
+ options.on("-h", "--help", "help") do
49
49
  @stdout.puts(options)
50
50
  exit
51
51
  end
52
52
 
53
- options.on('-v', '--version', 'version') do
53
+ options.on("-v", "--version", "version") do
54
54
  @stdout.puts(VERSION)
55
55
  exit
56
56
  end
57
57
 
58
- options.on('-p', '--provider=PROVIDER', 'provider (default="openai")') do |provider|
58
+ options.on("-p", "--provider=PROVIDER", 'provider (default="openai")') do |provider|
59
59
  @provider = provider
60
60
  end
61
61
 
data/lib/omniai/client.rb CHANGED
@@ -33,7 +33,7 @@ module OmniAI
33
33
  # @raise [OmniAI::Error] if the provider is not defined and the gem is not installed
34
34
  # @return [Class<OmniAI::Client>]
35
35
  def self.anthropic
36
- require 'omniai/anthropic' unless defined?(OmniAI::Anthropic::Client)
36
+ require "omniai/anthropic" unless defined?(OmniAI::Anthropic::Client)
37
37
  OmniAI::Anthropic::Client
38
38
  rescue LoadError
39
39
  raise Error, "requires 'omniai-anthropic': `gem install omniai-anthropic`"
@@ -44,7 +44,7 @@ module OmniAI
44
44
  # @raise [OmniAI::Error] if the provider is not defined and the gem is not installed
45
45
  # @return [Class<OmniAI::Client>]
46
46
  def self.google
47
- require 'omniai/google' unless defined?(OmniAI::Google::Client)
47
+ require "omniai/google" unless defined?(OmniAI::Google::Client)
48
48
  OmniAI::Google::Client
49
49
  rescue LoadError
50
50
  raise Error, "requires 'omniai-google': `gem install omniai-google`"
@@ -55,7 +55,7 @@ module OmniAI
55
55
  # @raise [OmniAI::Error] if the provider is not defined and the gem is not installed
56
56
  # @return [Class<OmniAI::Client>]
57
57
  def self.mistral
58
- require 'omniai/mistral' unless defined?(OmniAI::Mistral::Client)
58
+ require "omniai/mistral" unless defined?(OmniAI::Mistral::Client)
59
59
  OmniAI::Mistral::Client
60
60
  rescue LoadError
61
61
  raise Error, "requires 'omniai-mistral': `gem install omniai-mistral`"
@@ -66,7 +66,7 @@ module OmniAI
66
66
  # @raise [OmniAI::Error] if the provider is not defined and the gem is not installed
67
67
  # @return [Class<OmniAI::Client>]
68
68
  def self.openai
69
- require 'omniai/openai' unless defined?(OmniAI::OpenAI::Client)
69
+ require "omniai/openai" unless defined?(OmniAI::OpenAI::Client)
70
70
  OmniAI::OpenAI::Client
71
71
  rescue LoadError
72
72
  raise Error, "requires 'omniai-openai': `gem install omniai-openai`"
@@ -80,10 +80,10 @@ module OmniAI
80
80
  def self.find(provider:, **)
81
81
  klass =
82
82
  case provider
83
- when :anthropic, 'anthropic' then anthropic
84
- when :google, 'google' then google
85
- when :mistral, 'mistral' then mistral
86
- when :openai, 'openai' then openai
83
+ when :anthropic, "anthropic" then anthropic
84
+ when :google, "google" then google
85
+ when :mistral, "mistral" then mistral
86
+ when :openai, "openai" then openai
87
87
  else raise Error, "unknown provider=#{provider.inspect}"
88
88
  end
89
89
 
@@ -27,8 +27,8 @@ module OmniAI
27
27
  if deserializer
28
28
  deserializer.call(@data, context: @context)
29
29
  else
30
- prompt_tokens = @data.dig('usage', 'prompt_tokens')
31
- total_tokens = @data.dig('usage', 'total_tokens')
30
+ prompt_tokens = @data.dig("usage", "prompt_tokens")
31
+ total_tokens = @data.dig("usage", "total_tokens")
32
32
 
33
33
  Usage.new(prompt_tokens:, total_tokens:)
34
34
  end
@@ -50,7 +50,7 @@ module OmniAI
50
50
  if deserializer
51
51
  deserializer.call(@data, context: @context)
52
52
  else
53
- @data['data'].map { |embedding| embedding['embedding'] }
53
+ @data["data"].map { |embedding| embedding["embedding"] }
54
54
  end
55
55
  end
56
56
  end
data/lib/omniai/embed.rb CHANGED
@@ -51,7 +51,7 @@ module OmniAI
51
51
  parse!(response:)
52
52
  end
53
53
 
54
- protected
54
+ protected
55
55
 
56
56
  # @param response [HTTP::Response]
57
57
  # @return [Response]
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ # A manager for files.
5
+ class Files
6
+ # @param client [OmniAI::Client]
7
+ def initialize(client:)
8
+ @client = client
9
+ end
10
+ end
11
+ end
data/lib/omniai/speak.rb CHANGED
@@ -26,12 +26,12 @@ module OmniAI
26
26
  # client.transcribe(File.open("..."), model: "...", format: :json)
27
27
  class Speak
28
28
  module Format
29
- AAC = 'aac'
30
- FLAC = 'flac'
31
- MP3 = 'mp3'
32
- OPUS = 'opus'
33
- PCM = 'pcm'
34
- WAV = 'wav'
29
+ AAC = "aac"
30
+ FLAC = "flac"
31
+ MP3 = "mp3"
32
+ OPUS = "opus"
33
+ PCM = "pcm"
34
+ WAV = "wav"
35
35
  end
36
36
 
37
37
  # @raise [HTTPError]
@@ -94,7 +94,7 @@ module OmniAI
94
94
  end
95
95
  end
96
96
 
97
- protected
97
+ protected
98
98
 
99
99
  # @param response [HTTP::Response]
100
100
  #
@@ -18,7 +18,7 @@ module OmniAI
18
18
  # max_items: 5,
19
19
  # })
20
20
  class Array
21
- TYPE = 'array'
21
+ TYPE = "array"
22
22
 
23
23
  # @!attribute [rw] items
24
24
  # @return [OmniAI::Tool::Object, OmniAI::Tool::Array, OmniAI::Tool::Property]
@@ -13,7 +13,7 @@ module OmniAI
13
13
  # required: %i[name]
14
14
  # })
15
15
  class Object
16
- TYPE = 'object'
16
+ TYPE = "object"
17
17
 
18
18
  # @!attribute [rw] properties
19
19
  # @return [Hash]
@@ -13,10 +13,10 @@ module OmniAI
13
13
  # OmniAI::Tool::Property.boolean(description: '...')
14
14
  class Property
15
15
  module Type
16
- BOOLEAN = 'boolean'
17
- INTEGER = 'integer'
18
- STRING = 'string'
19
- NUMBER = 'number'
16
+ BOOLEAN = "boolean"
17
+ INTEGER = "integer"
18
+ STRING = "string"
19
+ NUMBER = "number"
20
20
  end
21
21
 
22
22
  # @return [String]
data/lib/omniai/tool.rb CHANGED
@@ -70,7 +70,7 @@ module OmniAI
70
70
  return serialize.call(self, context:) if serialize
71
71
 
72
72
  {
73
- type: 'function',
73
+ type: "function",
74
74
  function: {
75
75
  name: @name,
76
76
  description: @description,
@@ -26,70 +26,70 @@ module OmniAI
26
26
  # client.transcribe(File.open("..."), model: "...", format: :json)
27
27
  class Transcribe
28
28
  module Language
29
- AFRIKAANS = 'af'
30
- ARABIC = 'ar'
31
- ARMENIAN = 'hy'
32
- AZERBAIJANI = 'az'
33
- BELARUSIAN = 'be'
34
- BOSNIAN = 'bs'
35
- BULGARIAN = 'bg'
36
- CATALAN = 'ca'
37
- CHINESE = 'zh'
38
- CROATIAN = 'hr'
39
- CZECH = 'cs'
40
- DANISH = 'da'
41
- DUTCH = 'nl'
42
- ENGLISH = 'en'
43
- ESTONIAN = 'et'
44
- FINNISH = 'fi'
45
- FRENCH = 'fr'
46
- GALICIAN = 'gl'
47
- GERMAN = 'de'
48
- GREEK = 'el'
49
- HEBREW = 'he'
50
- HINDI = 'hi'
51
- HUNGARIAN = 'hu'
52
- ICELANDIC = 'is'
53
- INDONESIAN = 'id'
54
- ITALIAN = 'it'
55
- JAPANESE = 'ja'
56
- KANNADA = 'kn'
57
- KAZAKH = 'kk'
58
- KOREAN = 'ko'
59
- LATVIAN = 'lv'
60
- LITHUANIAN = 'lt'
61
- MACEDONIAN = 'mk'
62
- MALAY = 'ms'
63
- MARATHI = 'mr'
64
- MAORI = 'mi'
65
- NEPALI = 'ne'
66
- NORWEGIAN = 'no'
67
- PERSIAN = 'fa'
68
- POLISH = 'pl'
69
- PORTUGUESE = 'pt'
70
- ROMANIAN = 'ro'
71
- RUSSIAN = 'ru'
72
- SERBIAN = 'sr'
73
- SLOVAK = 'sk'
74
- SLOVENIAN = 'sl'
75
- SPANISH = 'es'
76
- SWAHILI = 'sw'
77
- SWEDISH = 'sv'
78
- TAGALOG = 'tl'
79
- TAMIL = 'ta'
80
- THAI = 'th'
81
- TURKISH = 'tr'
82
- UKRAINIAN = 'uk'
83
- URDU = 'ur'
84
- VIETNAMESE = 'vi'
85
- WELSH = 'cy'
29
+ AFRIKAANS = "af"
30
+ ARABIC = "ar"
31
+ ARMENIAN = "hy"
32
+ AZERBAIJANI = "az"
33
+ BELARUSIAN = "be"
34
+ BOSNIAN = "bs"
35
+ BULGARIAN = "bg"
36
+ CATALAN = "ca"
37
+ CHINESE = "zh"
38
+ CROATIAN = "hr"
39
+ CZECH = "cs"
40
+ DANISH = "da"
41
+ DUTCH = "nl"
42
+ ENGLISH = "en"
43
+ ESTONIAN = "et"
44
+ FINNISH = "fi"
45
+ FRENCH = "fr"
46
+ GALICIAN = "gl"
47
+ GERMAN = "de"
48
+ GREEK = "el"
49
+ HEBREW = "he"
50
+ HINDI = "hi"
51
+ HUNGARIAN = "hu"
52
+ ICELANDIC = "is"
53
+ INDONESIAN = "id"
54
+ ITALIAN = "it"
55
+ JAPANESE = "ja"
56
+ KANNADA = "kn"
57
+ KAZAKH = "kk"
58
+ KOREAN = "ko"
59
+ LATVIAN = "lv"
60
+ LITHUANIAN = "lt"
61
+ MACEDONIAN = "mk"
62
+ MALAY = "ms"
63
+ MARATHI = "mr"
64
+ MAORI = "mi"
65
+ NEPALI = "ne"
66
+ NORWEGIAN = "no"
67
+ PERSIAN = "fa"
68
+ POLISH = "pl"
69
+ PORTUGUESE = "pt"
70
+ ROMANIAN = "ro"
71
+ RUSSIAN = "ru"
72
+ SERBIAN = "sr"
73
+ SLOVAK = "sk"
74
+ SLOVENIAN = "sl"
75
+ SPANISH = "es"
76
+ SWAHILI = "sw"
77
+ SWEDISH = "sv"
78
+ TAGALOG = "tl"
79
+ TAMIL = "ta"
80
+ THAI = "th"
81
+ TURKISH = "tr"
82
+ UKRAINIAN = "uk"
83
+ URDU = "ur"
84
+ VIETNAMESE = "vi"
85
+ WELSH = "cy"
86
86
  end
87
87
 
88
88
  module Format
89
- JSON = 'json'
90
- TEXT = 'text'
91
- VTT = 'vtt'
92
- SRT = 'srt'
89
+ JSON = "json"
90
+ TEXT = "text"
91
+ VTT = "vtt"
92
+ SRT = "srt"
93
93
  end
94
94
 
95
95
  def self.process!(...)
@@ -120,11 +120,11 @@ module OmniAI
120
120
 
121
121
  raise HTTPError, response.flush unless response.status.ok?
122
122
 
123
- text = @format.nil? || @format.eql?(Format::JSON) ? response.parse['text'] : String(response.body)
123
+ text = @format.nil? || @format.eql?(Format::JSON) ? response.parse["text"] : String(response.body)
124
124
  Transcription.new(text:, model: @model, format: @format)
125
125
  end
126
126
 
127
- protected
127
+ protected
128
128
 
129
129
  # @return [Hash]
130
130
  def payload
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.9.2'
4
+ VERSION = "1.9.4"
5
5
  end
data/lib/omniai.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'logger'
4
- require 'event_stream_parser'
5
- require 'http'
6
- require 'uri'
7
- require 'zeitwerk'
3
+ require "logger"
4
+ require "event_stream_parser"
5
+ require "http"
6
+ require "uri"
7
+ require "zeitwerk"
8
8
 
9
9
  loader = Zeitwerk::Loader.for_gem
10
- loader.inflector.inflect 'omniai' => 'OmniAI'
11
- loader.inflector.inflect 'url' => 'URL'
12
- loader.inflector.inflect 'cli' => 'CLI'
10
+ loader.inflector.inflect "omniai" => "OmniAI"
11
+ loader.inflector.inflect "url" => "URL"
12
+ loader.inflector.inflect "cli" => "CLI"
13
13
  loader.setup
14
14
 
15
15
  module OmniAI
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-05 00:00:00.000000000 Z
10
+ date: 2025-01-30 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: event_stream_parser
@@ -38,6 +37,20 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: logger
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: zeitwerk
43
56
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +108,7 @@ files:
95
108
  - lib/omniai/embed.rb
96
109
  - lib/omniai/embed/response.rb
97
110
  - lib/omniai/embed/usage.rb
111
+ - lib/omniai/files.rb
98
112
  - lib/omniai/instrumentation.rb
99
113
  - lib/omniai/speak.rb
100
114
  - lib/omniai/tool.rb
@@ -112,7 +126,6 @@ metadata:
112
126
  homepage_uri: https://github.com/ksylvest/omniai
113
127
  changelog_uri: https://github.com/ksylvest/omniai/releases
114
128
  rubygems_mfa_required: 'true'
115
- post_install_message:
116
129
  rdoc_options: []
117
130
  require_paths:
118
131
  - lib
@@ -127,8 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
140
  - !ruby/object:Gem::Version
128
141
  version: '0'
129
142
  requirements: []
130
- rubygems_version: 3.5.18
131
- signing_key:
143
+ rubygems_version: 3.6.2
132
144
  specification_version: 4
133
145
  summary: A generalized framework for interacting with many AI services
134
146
  test_files: []