omniai 2.7.0 → 2.8.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: 488be723c0a59ca0095eb3a1f64081cceff14ae982208e598da5058ee0ea0c4b
4
- data.tar.gz: 47805f82344429912eaa2e0f00299cc95868d35d04a6d424f698b719bf9d0fe8
3
+ metadata.gz: a9cab46e52805a61d08bf4638ef7ed9ab46549c016ada8740abb7471f3ee5d07
4
+ data.tar.gz: 3a34ea68b515d8759a76d689f2474648c7e55d51b42a93ee022c18df271e049e
5
5
  SHA512:
6
- metadata.gz: 1c0d66e74c7a0e1eb0296e371b0339d44cedbb7a747c2beeb7cb0547303140d0a6550fd8d7fc6629c09804c57cfcf780dec38f01f6c8aac49004ab28e9968872
7
- data.tar.gz: aeb129f452a6ea0a9c2e33a25afbe5f8be1e7b27445fb58399556e7bdd0475b0840b36465c6b33edbdf857c6d943c10824b0cc21b7e6a917d161829e4ca033a6
6
+ metadata.gz: b241dca1c95f27efd023c09cb6ed9e8193f94e2487490b376a816e5c50d8a6a42e6cb0bc54e47ec3aeba0b12f23de7b3a258d9ca29d222ce6bf414469e2ad777
7
+ data.tar.gz: b74ba2a9950c821b7ca6bd5d1348165daab7dea3b7372db702d40cdda8d2669c057b32913cf5713b6d75cf3d97a234acf25c1f11af3357cc465740b18ec5990e
data/README.md CHANGED
@@ -228,24 +228,27 @@ puts format.parse(response.text)
228
228
  }
229
229
  ```
230
230
 
231
- ### Example #7: [Chat w/ CLI](https://github.com/ksylvest/omniai/blob/main/examples/chat_with_cli)
231
+ ### Example #7: [CLI](https://github.com/ksylvest/omniai/blob/main/examples/cli)
232
232
 
233
233
  The `OmniAI` gem also ships with a CLI to simplify quick tests.
234
234
 
235
235
  ```bash
236
+ # Chat
237
+
236
238
  omniai chat "Who designed the Ruby programming language?"
237
- ```
239
+ omniai chat --provider="google" --model="gemini-2.0-flash" "Who are you?"
238
240
 
239
- ```
240
- The Ruby programming language was created by Yukihiro Matsumoto, often known as "Matz."
241
- ```
241
+ ## Speech to Text
242
242
 
243
- ```bash
244
- omniai chat --provider="google" --model="gemini-2.0-flash" "Who are you?"
245
- ```
243
+ omniai speak "Salley sells sea shells by the sea shore." > ./files/audio.wav
246
244
 
247
- ```
248
- I am a large language model, trained by Google.
245
+ # Text to Speech
246
+
247
+ omniai transcribe "./files/audio.wav"
248
+
249
+ # Embed
250
+
251
+ omniai embed "What is the capital of France?"
249
252
  ```
250
253
 
251
254
  ### Example #8: [Text-to-Speech](https://github.com/ksylvest/omniai/blob/main/examples/text_to_speech)
@@ -650,6 +653,18 @@ The capital of Spain is **Madrid**.
650
653
  ...
651
654
  ```
652
655
 
656
+ #### Text-to-Speech
657
+
658
+ ```bash
659
+ omniai speak "Sally sells sea shells on the sea shore." > audio.aac
660
+ ```
661
+
662
+ #### Speech-to-Text
663
+
664
+ ```bash
665
+ omniai transcribe ./audio.aac
666
+ ```
667
+
653
668
  ### MCP
654
669
 
655
670
  [MCP](https://modelcontextprotocol.io/introduction) is an open protocol designed to standardize giving context to LLMs. The OmniAI implementation supports building an MCP server that operates via the [stdio](https://modelcontextprotocol.io/docs/concepts/transports) transport.
@@ -31,7 +31,7 @@ module OmniAI
31
31
 
32
32
  # @return [OmniAI::Client]
33
33
  def client
34
- @client ||= OmniAI::Client.find(provider: @provider)
34
+ @client ||= OmniAI.client(provider: @provider)
35
35
  end
36
36
  end
37
37
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class CLI
5
+ # Used by CLI to process commands like:
6
+ #
7
+ # omniai speak "Sally sells seashells by the seashore." > ./audio.aac
8
+ class SpeakHandler < BaseHandler
9
+ # @param argv [Array<String>]
10
+ def handle!(argv:)
11
+ parser.parse!(argv)
12
+
13
+ speak(argv.join(" "))
14
+ end
15
+
16
+ private
17
+
18
+ # @param input [String]
19
+ def speak(input)
20
+ client.speak(input, **@args) do |chunk|
21
+ @stdout.write(chunk)
22
+ end
23
+ @stdout.flush
24
+ end
25
+
26
+ # @return [OptionParser]
27
+ def parser
28
+ OptionParser.new do |options|
29
+ options.banner = 'usage: omniai speak [options] "<prompt>"'
30
+
31
+ options.on("-h", "--help", "help") do
32
+ @stdout.puts(options)
33
+ exit
34
+ end
35
+
36
+ options.on("-p", "--provider=PROVIDER", "provider") do |provider|
37
+ @provider = provider
38
+ end
39
+
40
+ options.on("-m", "--model=MODEL", "model") do |model|
41
+ @args[:model] = model
42
+ end
43
+
44
+ options.on("-v", "--voice=VOICE", "voice") do |voice|
45
+ @args[:voice] = voice
46
+ end
47
+
48
+ options.on("-s", "--speed=SPEED", Float, "speed") do |speed|
49
+ @args[:speed] = speed
50
+ end
51
+
52
+ options.on("-f", "--format=FORMAT", "format") do |format|
53
+ @args[:format] = format
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAI
4
+ class CLI
5
+ # Used by CLI to process commands like:
6
+ #
7
+ # omniai transcribe ./audio.wav
8
+ class TranscribeHandler < BaseHandler
9
+ # @param argv [Array<String>]
10
+ def handle!(argv:)
11
+ parser.parse!(argv)
12
+
13
+ argv.each do |path|
14
+ transcribe(path)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ # @param input [String]
21
+ def transcribe(input)
22
+ File.open(input, "rb") do |file|
23
+ @stdout.puts(client.transcribe(file, **@args).text)
24
+ end
25
+ end
26
+
27
+ # @return [OptionParser]
28
+ def parser
29
+ OptionParser.new do |options|
30
+ options.banner = 'usage: omniai chat [options] "<prompt>"'
31
+
32
+ options.on("-h", "--help", "help") do
33
+ @stdout.puts(options)
34
+ exit
35
+ end
36
+
37
+ options.on("-p", "--provider=PROVIDER", "provider") do |provider|
38
+ @provider = provider
39
+ end
40
+
41
+ options.on("-m", "--model=MODEL", "model") do |model|
42
+ @args[:model] = model
43
+ end
44
+
45
+ options.on("-l", "--language=LANGUAGE", "language") do |language|
46
+ @args[:language] = language
47
+ end
48
+
49
+ options.on("-f", "--format=FORMAT", "format") do |format|
50
+ @args[:format] = format
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
data/lib/omniai/cli.rb CHANGED
@@ -13,7 +13,7 @@ module OmniAI
13
13
  # @param stdin [IO] a stream
14
14
  # @param stdout [IO] a stream
15
15
  # @param provider [String] a provider
16
- def initialize(stdin: $stdin, stdout: $stdout, provider: "openai")
16
+ def initialize(stdin: $stdin, stdout: $stdout, provider: nil)
17
17
  @stdin = stdin
18
18
  @stdout = stdout
19
19
  @provider = provider
@@ -30,6 +30,8 @@ module OmniAI
30
30
  case command
31
31
  when "chat" then ChatHandler
32
32
  when "embed" then EmbedHandler
33
+ when "speak" then SpeakHandler
34
+ when "transcribe" then TranscribeHandler
33
35
  else raise Error, "unsupported command=#{command.inspect}"
34
36
  end
35
37
 
@@ -60,6 +62,9 @@ module OmniAI
60
62
  options.separator <<~COMMANDS
61
63
  commands:
62
64
  chat
65
+ embed
66
+ speak
67
+ transcribe
63
68
  COMMANDS
64
69
  end
65
70
  end
data/lib/omniai/speak.rb CHANGED
@@ -23,7 +23,11 @@ module OmniAI
23
23
  # end
24
24
  # end
25
25
  #
26
- # client.transcribe(File.open("..."), model: "...", format: :json)
26
+ # File.open('audio.wav', 'wb') do |file|
27
+ # client.speak('Sally sells seashells by the seashore.', format: OmniAI::Speak::Format::WAV) do |chunk|
28
+ # file << chunk
29
+ # end
30
+ # end
27
31
  class Speak
28
32
  module Format
29
33
  AAC = "aac"
@@ -34,6 +38,8 @@ module OmniAI
34
38
  WAV = "wav"
35
39
  end
36
40
 
41
+ DEFAULT_FORMAT = Format::AAC
42
+
37
43
  # @raise [HTTPError]
38
44
  #
39
45
  # @param client [OmniAI::Client] required
@@ -52,7 +58,7 @@ module OmniAI
52
58
  # @yield [chunk]
53
59
  #
54
60
  # @return [Tempfile]
55
- def self.process!(input, client:, model:, voice:, speed: nil, format: nil, &)
61
+ def self.process!(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT, &)
56
62
  new(input, client:, model:, voice:, speed:, format:).process!(&)
57
63
  end
58
64
 
@@ -68,7 +74,7 @@ module OmniAI
68
74
  # - "opus"
69
75
  # - "pcm"
70
76
  # - "wav"
71
- def initialize(input, client:, model:, voice:, speed: nil, format: nil)
77
+ def initialize(input, client:, model:, voice:, speed: nil, format: DEFAULT_FORMAT)
72
78
  @input = input
73
79
  @client = client
74
80
  @model = model
@@ -23,7 +23,9 @@ module OmniAI
23
23
  # end
24
24
  # end
25
25
  #
26
- # client.transcribe(File.open("..."), model: "...", format: :json)
26
+ # File.open('audio.wav', 'rb') do |file|
27
+ # client.transcribe(file, model: "...", format: :json)
28
+ # end
27
29
  class Transcribe
28
30
  module Language
29
31
  AFRIKAANS = "af"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = "2.7.0"
4
+ VERSION = "2.8.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -103,6 +103,8 @@ files:
103
103
  - lib/omniai/cli/base_handler.rb
104
104
  - lib/omniai/cli/chat_handler.rb
105
105
  - lib/omniai/cli/embed_handler.rb
106
+ - lib/omniai/cli/speak_handler.rb
107
+ - lib/omniai/cli/transcribe_handler.rb
106
108
  - lib/omniai/client.rb
107
109
  - lib/omniai/config.rb
108
110
  - lib/omniai/context.rb