omniai 1.9.2 → 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +14 -13
- data/bin/console +3 -3
- data/exe/omniai +1 -1
- data/lib/omniai/chat/choice.rb +2 -2
- data/lib/omniai/chat/content.rb +3 -3
- data/lib/omniai/chat/file.rb +1 -1
- data/lib/omniai/chat/function.rb +3 -3
- data/lib/omniai/chat/message.rb +4 -4
- data/lib/omniai/chat/payload.rb +2 -2
- data/lib/omniai/chat/stream.rb +2 -2
- data/lib/omniai/chat/text.rb +2 -2
- data/lib/omniai/chat/tool_call.rb +3 -3
- data/lib/omniai/chat/tool_call_message.rb +3 -3
- data/lib/omniai/chat/tool_call_result.rb +2 -2
- data/lib/omniai/chat/url.rb +3 -3
- data/lib/omniai/chat/usage.rb +3 -3
- data/lib/omniai/chat.rb +7 -7
- data/lib/omniai/cli/base_handler.rb +3 -3
- data/lib/omniai/cli/chat_handler.rb +8 -8
- data/lib/omniai/cli/embed_handler.rb +6 -6
- data/lib/omniai/cli.rb +9 -9
- data/lib/omniai/client.rb +8 -8
- data/lib/omniai/embed/response.rb +3 -3
- data/lib/omniai/embed.rb +1 -1
- data/lib/omniai/files.rb +11 -0
- data/lib/omniai/speak.rb +7 -7
- data/lib/omniai/tool/array.rb +1 -1
- data/lib/omniai/tool/object.rb +1 -1
- data/lib/omniai/tool/property.rb +4 -4
- data/lib/omniai/tool.rb +1 -1
- data/lib/omniai/transcribe.rb +63 -63
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +8 -8
- metadata +4 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d4e9aaa996b53fb59b2658817f02dd8ceddade770b14e3d726a79d8df9a294b
|
4
|
+
data.tar.gz: 66d182ff7a87448ea7a24e30851e2a603e660de5dfd430bb8ea56af77e3f0656
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f8595c7def1c8cef80df7de2b2027c581502c1a08ab7ca2306e685fdfe07c0b4987b3d7c366892dca75307984b5daf81410eedd9cf3102eb1f34b17acacffdf
|
7
|
+
data.tar.gz: 7522d79dc5c2a4a847dd431fd272edc693a1658eb293586bf65dae71ff98b2dcfa6d2f4beee083f62966925abcbd6ab4a1f7c4920c4133b5c3d0522572c026e0
|
data/Gemfile
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
gemspec
|
6
6
|
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
10
|
-
gem
|
11
|
-
gem
|
12
|
-
gem
|
13
|
-
gem
|
14
|
-
gem
|
15
|
-
gem
|
16
|
-
gem
|
17
|
-
gem
|
18
|
-
gem
|
7
|
+
gem "factory_bot"
|
8
|
+
gem "logger"
|
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/bin/console
CHANGED
data/exe/omniai
CHANGED
data/lib/omniai/chat/choice.rb
CHANGED
@@ -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[
|
35
|
-
message = Message.deserialize(data[
|
34
|
+
index = data["index"]
|
35
|
+
message = Message.deserialize(data["message"] || data["delta"], context:)
|
36
36
|
|
37
37
|
new(message:, index:)
|
38
38
|
end
|
data/lib/omniai/chat/content.rb
CHANGED
@@ -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?(
|
35
|
+
raise ArgumentError, "untyped data=#{data.inspect}" unless data.key?("type")
|
36
36
|
|
37
|
-
case data[
|
38
|
-
when
|
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
|
data/lib/omniai/chat/file.rb
CHANGED
data/lib/omniai/chat/function.rb
CHANGED
@@ -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[
|
33
|
+
name = data["name"]
|
34
34
|
arguments = begin
|
35
|
-
JSON.parse(data[
|
35
|
+
JSON.parse(data["arguments"]) if data["arguments"]
|
36
36
|
rescue JSON::ParserError
|
37
|
-
data[
|
37
|
+
data["arguments"]
|
38
38
|
end
|
39
39
|
|
40
40
|
new(name:, arguments:)
|
data/lib/omniai/chat/message.rb
CHANGED
@@ -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,
|
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[
|
85
|
-
content = Content.deserialize(data[
|
86
|
-
tool_call_list = data[
|
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
|
data/lib/omniai/chat/payload.rb
CHANGED
@@ -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[
|
32
|
-
usage = Usage.deserialize(data[
|
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
|
data/lib/omniai/chat/stream.rb
CHANGED
@@ -23,7 +23,7 @@ module OmniAI
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
|
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?(
|
50
|
+
return if data.eql?("[DONE]")
|
51
51
|
|
52
52
|
block.call(Payload.deserialize(JSON.parse(data), context: @context))
|
53
53
|
end
|
data/lib/omniai/chat/text.rb
CHANGED
@@ -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[
|
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:
|
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[
|
34
|
-
function = Function.deserialize(data[
|
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:
|
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[
|
35
|
-
content = JSON.parse(data[
|
36
|
-
tool_call_id = data[
|
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[
|
45
|
-
tool_call_id = data[
|
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
|
data/lib/omniai/chat/url.rb
CHANGED
@@ -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[
|
35
|
-
uri = data["#{type}_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
|
-
|
71
|
+
protected
|
72
72
|
|
73
73
|
# @raise [FetchError]
|
74
74
|
#
|
data/lib/omniai/chat/usage.rb
CHANGED
@@ -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[
|
39
|
-
output_tokens = data[
|
40
|
-
total_tokens = data[
|
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 =
|
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 =
|
49
|
-
USER =
|
50
|
-
SYSTEM =
|
51
|
-
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,
|
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
|
-
|
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:
|
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:
|
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
|
-
|
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
|
-
|
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(
|
46
|
+
options.on("-h", "--help", "help") do
|
47
47
|
@stdout.puts(options)
|
48
48
|
exit
|
49
49
|
end
|
50
50
|
|
51
|
-
options.on(
|
52
|
-
options.on(
|
53
|
-
options.on(
|
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(
|
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
|
-
|
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(
|
47
|
+
options.on("-h", "--help", "help") do
|
48
48
|
@stdout.puts(options)
|
49
49
|
exit
|
50
50
|
end
|
51
51
|
|
52
|
-
options.on(
|
53
|
-
options.on(
|
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
|
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:
|
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
|
34
|
-
when
|
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
|
-
|
41
|
+
private
|
42
42
|
|
43
43
|
# @return [OptionParser]
|
44
44
|
def parser
|
45
45
|
OptionParser.new do |options|
|
46
|
-
options.banner =
|
46
|
+
options.banner = "usage: omniai [options] <command> [<args>]"
|
47
47
|
|
48
|
-
options.on(
|
48
|
+
options.on("-h", "--help", "help") do
|
49
49
|
@stdout.puts(options)
|
50
50
|
exit
|
51
51
|
end
|
52
52
|
|
53
|
-
options.on(
|
53
|
+
options.on("-v", "--version", "version") do
|
54
54
|
@stdout.puts(VERSION)
|
55
55
|
exit
|
56
56
|
end
|
57
57
|
|
58
|
-
options.on(
|
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
|
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
|
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
|
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
|
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,
|
84
|
-
when :google,
|
85
|
-
when :mistral,
|
86
|
-
when :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(
|
31
|
-
total_tokens = @data.dig(
|
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[
|
53
|
+
@data["data"].map { |embedding| embedding["embedding"] }
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
data/lib/omniai/embed.rb
CHANGED
data/lib/omniai/files.rb
ADDED
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 =
|
30
|
-
FLAC =
|
31
|
-
MP3 =
|
32
|
-
OPUS =
|
33
|
-
PCM =
|
34
|
-
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
|
-
|
97
|
+
protected
|
98
98
|
|
99
99
|
# @param response [HTTP::Response]
|
100
100
|
#
|
data/lib/omniai/tool/array.rb
CHANGED
data/lib/omniai/tool/object.rb
CHANGED
data/lib/omniai/tool/property.rb
CHANGED
@@ -13,10 +13,10 @@ module OmniAI
|
|
13
13
|
# OmniAI::Tool::Property.boolean(description: '...')
|
14
14
|
class Property
|
15
15
|
module Type
|
16
|
-
BOOLEAN =
|
17
|
-
INTEGER =
|
18
|
-
STRING =
|
19
|
-
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
data/lib/omniai/transcribe.rb
CHANGED
@@ -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 =
|
30
|
-
ARABIC =
|
31
|
-
ARMENIAN =
|
32
|
-
AZERBAIJANI =
|
33
|
-
BELARUSIAN =
|
34
|
-
BOSNIAN =
|
35
|
-
BULGARIAN =
|
36
|
-
CATALAN =
|
37
|
-
CHINESE =
|
38
|
-
CROATIAN =
|
39
|
-
CZECH =
|
40
|
-
DANISH =
|
41
|
-
DUTCH =
|
42
|
-
ENGLISH =
|
43
|
-
ESTONIAN =
|
44
|
-
FINNISH =
|
45
|
-
FRENCH =
|
46
|
-
GALICIAN =
|
47
|
-
GERMAN =
|
48
|
-
GREEK =
|
49
|
-
HEBREW =
|
50
|
-
HINDI =
|
51
|
-
HUNGARIAN =
|
52
|
-
ICELANDIC =
|
53
|
-
INDONESIAN =
|
54
|
-
ITALIAN =
|
55
|
-
JAPANESE =
|
56
|
-
KANNADA =
|
57
|
-
KAZAKH =
|
58
|
-
KOREAN =
|
59
|
-
LATVIAN =
|
60
|
-
LITHUANIAN =
|
61
|
-
MACEDONIAN =
|
62
|
-
MALAY =
|
63
|
-
MARATHI =
|
64
|
-
MAORI =
|
65
|
-
NEPALI =
|
66
|
-
NORWEGIAN =
|
67
|
-
PERSIAN =
|
68
|
-
POLISH =
|
69
|
-
PORTUGUESE =
|
70
|
-
ROMANIAN =
|
71
|
-
RUSSIAN =
|
72
|
-
SERBIAN =
|
73
|
-
SLOVAK =
|
74
|
-
SLOVENIAN =
|
75
|
-
SPANISH =
|
76
|
-
SWAHILI =
|
77
|
-
SWEDISH =
|
78
|
-
TAGALOG =
|
79
|
-
TAMIL =
|
80
|
-
THAI =
|
81
|
-
TURKISH =
|
82
|
-
UKRAINIAN =
|
83
|
-
URDU =
|
84
|
-
VIETNAMESE =
|
85
|
-
WELSH =
|
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 =
|
90
|
-
TEXT =
|
91
|
-
VTT =
|
92
|
-
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[
|
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
|
-
|
127
|
+
protected
|
128
128
|
|
129
129
|
# @return [Hash]
|
130
130
|
def payload
|
data/lib/omniai/version.rb
CHANGED
data/lib/omniai.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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
|
11
|
-
loader.inflector.inflect
|
12
|
-
loader.inflector.inflect
|
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.
|
4
|
+
version: 1.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-18 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: event_stream_parser
|
@@ -95,6 +94,7 @@ files:
|
|
95
94
|
- lib/omniai/embed.rb
|
96
95
|
- lib/omniai/embed/response.rb
|
97
96
|
- lib/omniai/embed/usage.rb
|
97
|
+
- lib/omniai/files.rb
|
98
98
|
- lib/omniai/instrumentation.rb
|
99
99
|
- lib/omniai/speak.rb
|
100
100
|
- lib/omniai/tool.rb
|
@@ -112,7 +112,6 @@ metadata:
|
|
112
112
|
homepage_uri: https://github.com/ksylvest/omniai
|
113
113
|
changelog_uri: https://github.com/ksylvest/omniai/releases
|
114
114
|
rubygems_mfa_required: 'true'
|
115
|
-
post_install_message:
|
116
115
|
rdoc_options: []
|
117
116
|
require_paths:
|
118
117
|
- lib
|
@@ -127,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
126
|
- !ruby/object:Gem::Version
|
128
127
|
version: '0'
|
129
128
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
-
signing_key:
|
129
|
+
rubygems_version: 3.6.2
|
132
130
|
specification_version: 4
|
133
131
|
summary: A generalized framework for interacting with many AI services
|
134
132
|
test_files: []
|