omniai 2.5.0 → 2.7.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 +4 -4
- data/README.md +128 -49
- data/lib/omniai/chat/message.rb +7 -1
- data/lib/omniai/chat/response.rb +2 -0
- data/lib/omniai/chat.rb +1 -1
- data/lib/omniai/client.rb +36 -12
- data/lib/omniai/load_error.rb +7 -0
- data/lib/omniai/schema/array.rb +96 -0
- data/lib/omniai/schema/format.rb +71 -0
- data/lib/omniai/schema/object.rb +96 -0
- data/lib/omniai/schema/scalar.rb +118 -0
- data/lib/omniai/schema.rb +165 -0
- data/lib/omniai/tool.rb +5 -5
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +62 -0
- metadata +8 -6
- data/lib/omniai/tool/array.rb +0 -74
- data/lib/omniai/tool/object.rb +0 -62
- data/lib/omniai/tool/parameters.rb +0 -23
- data/lib/omniai/tool/property.rb +0 -151
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
module Schema
|
5
|
+
# @example
|
6
|
+
# schema = OmniAI::Schema::Object.deserialize({
|
7
|
+
# type: "object",
|
8
|
+
# properties: {
|
9
|
+
# name: { type: "string" }
|
10
|
+
# },
|
11
|
+
# required: ["name"],
|
12
|
+
# })
|
13
|
+
# schema.serialize #=> { type: "object", properties: { ... }, required: %i[name] }
|
14
|
+
# schema.parse({ "name" => "John Doe" }) #=> { name: "John Doe" }
|
15
|
+
class Object
|
16
|
+
TYPE = "object"
|
17
|
+
|
18
|
+
# @!attribute [rw] properties
|
19
|
+
# @return [Hash]
|
20
|
+
attr_accessor :properties
|
21
|
+
|
22
|
+
# @!attribute [rw] required
|
23
|
+
# @return [Array<String>]
|
24
|
+
attr_accessor :required
|
25
|
+
|
26
|
+
# @!attribute [rw] title
|
27
|
+
# @return [String, nil]
|
28
|
+
attr_accessor :title
|
29
|
+
|
30
|
+
# @!attribute [rw] description
|
31
|
+
# @return [String, nil]
|
32
|
+
attr_accessor :description
|
33
|
+
|
34
|
+
# @example
|
35
|
+
# OmniAI::Schema::Object.deserialize({
|
36
|
+
# type: "object",
|
37
|
+
# properties: {
|
38
|
+
# name: { type: "string" }
|
39
|
+
# },
|
40
|
+
# required: ["name"],
|
41
|
+
# }) # => OmniAI::Schema::Object
|
42
|
+
#
|
43
|
+
# @param data [Hash]
|
44
|
+
#
|
45
|
+
# @return [OmniAI::Schema::Object]
|
46
|
+
def self.deserialize(data)
|
47
|
+
title = data["title"] || data[:title]
|
48
|
+
description = data["description"] || data[:description]
|
49
|
+
properties = (data["properties"] || data[:properties]).transform_values { |i| OmniAI::Schema.deserialize(i) }
|
50
|
+
required = data["required"] || data[:required] || []
|
51
|
+
|
52
|
+
new(title:, description:, properties:, required:)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param title [String] optional
|
56
|
+
# @param description [String] optional
|
57
|
+
# @param properties [Hash] optional
|
58
|
+
# @param required [Array<String>] optional
|
59
|
+
def initialize(title: nil, description: nil, properties: {}, required: [])
|
60
|
+
super()
|
61
|
+
@title = title
|
62
|
+
@description = description
|
63
|
+
@properties = properties
|
64
|
+
@required = required
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Hash]
|
68
|
+
def serialize
|
69
|
+
{
|
70
|
+
type: TYPE,
|
71
|
+
title: @title,
|
72
|
+
description: @description,
|
73
|
+
properties: @properties.transform_values(&:serialize),
|
74
|
+
required: @required,
|
75
|
+
}.compact
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param name [Symbol]
|
79
|
+
def property(name, ...)
|
80
|
+
@properties[name] = OmniAI::Schema::Scalar.build(...)
|
81
|
+
end
|
82
|
+
|
83
|
+
# @param data [Hash]
|
84
|
+
#
|
85
|
+
# @return [Hash]
|
86
|
+
def parse(data)
|
87
|
+
result = {}
|
88
|
+
@properties.each do |name, property|
|
89
|
+
value = data[String(name)]
|
90
|
+
result[name.intern] = property.parse(value) unless value.nil?
|
91
|
+
end
|
92
|
+
result
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
module Schema
|
5
|
+
# @example
|
6
|
+
# scalar = OmniAI::Schema::Scalar.deserialize({ type: "string" })
|
7
|
+
# scalar.serialize #=> { type: "string" }
|
8
|
+
# scalar.parse("Hello World") #=> "Hello World"
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# scalar = OmniAI::Schema::Scalar.deserialize({ type: "integer" })
|
12
|
+
# scalar.serialize #=> { type: "integer" }
|
13
|
+
# scalar.parse("123") #=> 123
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# scalar = OmniAI::Schema::Scalar.deserialize({ type: "number" })
|
17
|
+
# scalar.serialize #=> { type: "number" }
|
18
|
+
# scalar.parse("123.45") #=> 123.45
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# scalar = OmniAI::Schema::Scalar.deserialize({ type: "boolean" })
|
22
|
+
# scalar.serialize #=> { type: "boolean" }
|
23
|
+
# scalar.parse(true) #=> true
|
24
|
+
# scalar.parse(false) #=> false
|
25
|
+
class Scalar
|
26
|
+
module Type
|
27
|
+
BOOLEAN = "boolean"
|
28
|
+
INTEGER = "integer"
|
29
|
+
STRING = "string"
|
30
|
+
NUMBER = "number"
|
31
|
+
end
|
32
|
+
|
33
|
+
# @!attribute [rw] type
|
34
|
+
# @return [String]
|
35
|
+
attr_accessor :type
|
36
|
+
|
37
|
+
# @!attribute [rw] description
|
38
|
+
# @return [String, nil]
|
39
|
+
attr_accessor :description
|
40
|
+
|
41
|
+
# @!attribute [rw] enum
|
42
|
+
# @return [Array<String>, nil]
|
43
|
+
attr_accessor :enum
|
44
|
+
|
45
|
+
# @example
|
46
|
+
# property = OmniAI::Schema::Scalar.deserialize({
|
47
|
+
# type: "string",
|
48
|
+
# description: "A predefined color.",
|
49
|
+
# enum: %w[red organge yellow green blue indigo violet],
|
50
|
+
# })
|
51
|
+
#
|
52
|
+
# @example
|
53
|
+
# property = OmniAI::Schema::Scalar.deserialize({
|
54
|
+
# type: "integer",
|
55
|
+
# })
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
# property = OmniAI::Schema::Scalar.deserialize({
|
59
|
+
# type: "number",
|
60
|
+
# })
|
61
|
+
#
|
62
|
+
# @example
|
63
|
+
# property = OmniAI::Schema::Scalar.deserialize({
|
64
|
+
# type: "boolean",
|
65
|
+
# })
|
66
|
+
#
|
67
|
+
# @param data [Hash]
|
68
|
+
#
|
69
|
+
# @return [OmniAI::Schema::Scalar]
|
70
|
+
def self.deserialize(data)
|
71
|
+
type = data["type"] || data[:type] || Type::STRING
|
72
|
+
description = data["description"] || data[:description]
|
73
|
+
enum = data["enum"] || data[:enum]
|
74
|
+
|
75
|
+
new(type:, description:, enum:)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param type [String] required - the type of the property
|
79
|
+
# @param description [String] optional - a description of the property
|
80
|
+
# @param enum [Array] optional - the possible values of the property
|
81
|
+
#
|
82
|
+
# @return [OmniAI::Schema::Scalar]
|
83
|
+
def initialize(type:, description: nil, enum: nil)
|
84
|
+
super()
|
85
|
+
@type = type
|
86
|
+
@description = description
|
87
|
+
@enum = enum
|
88
|
+
end
|
89
|
+
|
90
|
+
# @example
|
91
|
+
# property.serialize #=> { type: "string" }
|
92
|
+
#
|
93
|
+
# @return [Hash]
|
94
|
+
def serialize
|
95
|
+
{
|
96
|
+
type: @type,
|
97
|
+
description: @description,
|
98
|
+
enum: @enum,
|
99
|
+
}.compact
|
100
|
+
end
|
101
|
+
|
102
|
+
# @example
|
103
|
+
# property.parse("123") #=> 123
|
104
|
+
#
|
105
|
+
# @param value [String, Integer, Float, Boolean, Object]
|
106
|
+
#
|
107
|
+
# @return [String, Integer, Float, Boolean, Object]
|
108
|
+
def parse(value)
|
109
|
+
case @type
|
110
|
+
when Type::INTEGER then Integer(value)
|
111
|
+
when Type::STRING then String(value)
|
112
|
+
when Type::NUMBER then Float(value)
|
113
|
+
else value
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
# @example
|
5
|
+
# format = OmniAI::Schema.format(name: "Contact", schema: OmniAI::Schema.object(
|
6
|
+
# description: "A contact with a name, relationship, and addresses.",
|
7
|
+
# properties: {
|
8
|
+
# name: OmniAI::Schema.string,
|
9
|
+
# relationship: OmniAI::Schema.string(enum: %w[friend family]),
|
10
|
+
# addresses: OmniAI::Schema.array(
|
11
|
+
# items: OmniAI::Schema.object(
|
12
|
+
# title: "Address",
|
13
|
+
# description: "An address with street, city, state, and zip code.",
|
14
|
+
# properties: {
|
15
|
+
# street: OmniAI::Schema.string,
|
16
|
+
# city: OmniAI::Schema.string,
|
17
|
+
# state: OmniAI::Schema.string,
|
18
|
+
# zip: OmniAI::Schema.string,
|
19
|
+
# },
|
20
|
+
# required: %i[street city state zip]
|
21
|
+
# )
|
22
|
+
# ),
|
23
|
+
# },
|
24
|
+
# required: %i[name]
|
25
|
+
# ))
|
26
|
+
module Schema
|
27
|
+
# @example
|
28
|
+
# OmniAI::Schema.deserialize({
|
29
|
+
# type: 'object',
|
30
|
+
# title: 'Person',
|
31
|
+
# properties: { name: { type: 'string' } },
|
32
|
+
# required: %i[name],
|
33
|
+
# }) # => OmniAI::Schema::Object
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# OmniAI::Schema.deserialize({
|
37
|
+
# type: 'array',
|
38
|
+
# items: { type: 'string' },
|
39
|
+
# }) # => OmniAI::Schema::Array
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# OmniAI::Schema.deserialize({
|
43
|
+
# type: 'string',
|
44
|
+
# description: '...',
|
45
|
+
# enum: ['...', ],
|
46
|
+
# }) # => OmniAI::Schema::Scalar
|
47
|
+
#
|
48
|
+
# @param data [OmniAI::Schema::Object, OmniAI::Schema::Array, OmniAI::Schema::Scalar]
|
49
|
+
def self.deserialize(data)
|
50
|
+
case data["type"] || data[:type]
|
51
|
+
when OmniAI::Schema::Array::TYPE then OmniAI::Schema::Array.deserialize(data)
|
52
|
+
when OmniAI::Schema::Object::TYPE then OmniAI::Schema::Object.deserialize(data)
|
53
|
+
else OmniAI::Schema::Scalar.deserialize(data)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param kind [Symbol]
|
58
|
+
#
|
59
|
+
# @return [OmniAI::Schema::Object, OmniAI::Schema::Array, OmniAI::Schema::Scalar]
|
60
|
+
def self.build(kind, **args)
|
61
|
+
case kind
|
62
|
+
when :array then array(**args)
|
63
|
+
when :object then object(**args)
|
64
|
+
when :boolean then boolean(**args)
|
65
|
+
when :integer then integer(**args)
|
66
|
+
when :number then number(**args)
|
67
|
+
when :string then string(**args)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# @example
|
72
|
+
# property = OmniAI::Schema.array(
|
73
|
+
# items: OmniAI::Schema.string(description: 'The name of the person.'),
|
74
|
+
# description: 'A list of names.'
|
75
|
+
# min_items: 1,
|
76
|
+
# max_items: 5,
|
77
|
+
# )
|
78
|
+
#
|
79
|
+
# @param items [OmniAI::Schema::Scalar] required - the items in the array
|
80
|
+
# @param min_items [Integer] optional - the minimum number of items
|
81
|
+
# @param max_items [Integer] optional - the maximum number of items
|
82
|
+
# @param description [String] optional - a description of the array
|
83
|
+
#
|
84
|
+
# @return [OmniAI::Schema::Array]
|
85
|
+
def self.array(items:, min_items: nil, max_items: nil, description: nil)
|
86
|
+
OmniAI::Schema::Array.new(items:, description:, min_items:, max_items:)
|
87
|
+
end
|
88
|
+
|
89
|
+
# @example
|
90
|
+
# property = OmniAI::Schema.object(
|
91
|
+
# properties: {
|
92
|
+
# name: OmniAI::Schema.string(description: 'The name of the person.'),
|
93
|
+
# age: OmniAI::Schema.integer(description: 'The age of the person.'),
|
94
|
+
# employed: OmniAI::Schema.boolean(description: 'Is the person employed?'),
|
95
|
+
# },
|
96
|
+
# description: 'A person.'
|
97
|
+
# required: %i[name]
|
98
|
+
# )
|
99
|
+
#
|
100
|
+
# @param title [String] optional - the title of the object
|
101
|
+
# @param properties [Hash<String, OmniAI::Schema::Scalar>] required - the properties of the object
|
102
|
+
# @param required [Array<Symbol>] optional - the required properties
|
103
|
+
# @param description [String] optional - a description of the object
|
104
|
+
#
|
105
|
+
# @return [OmniAI::Schema::Array]
|
106
|
+
def self.object(title: nil, properties: {}, required: [], description: nil)
|
107
|
+
OmniAI::Schema::Object.new(title:, properties:, required:, description:)
|
108
|
+
end
|
109
|
+
|
110
|
+
# @example
|
111
|
+
# OmniAI::Schema.boolean(description: "Is the person employed?") #=> OmniAI::Schema::Scalar
|
112
|
+
#
|
113
|
+
# @param description [String] optional - a description of the property
|
114
|
+
# @param enum [Array<Boolean>] optional - the possible values of the property
|
115
|
+
#
|
116
|
+
# @return [OmniAI::Schema::Scalar]
|
117
|
+
def self.boolean(description: nil, enum: nil)
|
118
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::BOOLEAN, description:, enum:)
|
119
|
+
end
|
120
|
+
|
121
|
+
# @example
|
122
|
+
# OmniAI::Schema.integer(description: "The age of the person") #=> OmniAI::Schema::Scalar
|
123
|
+
#
|
124
|
+
# @param description [String] optional - a description of the property
|
125
|
+
# @param enum [Array<Integer>] optinoal - the possible values of the property
|
126
|
+
#
|
127
|
+
# @return [OmniAI::Schema::Scalar]
|
128
|
+
def self.integer(description: nil, enum: nil)
|
129
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::INTEGER, description:, enum:)
|
130
|
+
end
|
131
|
+
|
132
|
+
# @example
|
133
|
+
# OmniAI::Schema.string(description: "The name of the person.") #=> OmniAI::Schema::Scalar
|
134
|
+
#
|
135
|
+
# @param description [String] optional - a description of the property
|
136
|
+
# @param enum [Array<String>] optional - the possible values of the property
|
137
|
+
#
|
138
|
+
# @return [OmniAI::Schema::Scalar]
|
139
|
+
def self.string(description: nil, enum: nil)
|
140
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::STRING, description:, enum:)
|
141
|
+
end
|
142
|
+
|
143
|
+
# @example
|
144
|
+
# OmniAI::Schema.number(description: "The current temperature.") #=> OmniAI::Schema::Scalar
|
145
|
+
#
|
146
|
+
# @param description [String] optional - a description of the property
|
147
|
+
# @param enum [Array<Number>] optional - the possible values of the property
|
148
|
+
#
|
149
|
+
# @return [OmniAI::Schema::Scalar]
|
150
|
+
def self.number(description: nil, enum: nil)
|
151
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::NUMBER, description:, enum:)
|
152
|
+
end
|
153
|
+
|
154
|
+
# @example
|
155
|
+
# OmniAI::Schema.format(name: "Contact", schema: OmniAI::Schema.object(...)) #=> OmniAI::Schema::Format
|
156
|
+
#
|
157
|
+
# @param name [String] required
|
158
|
+
# @param schema [OmniAI::Schema::Object] required
|
159
|
+
#
|
160
|
+
# @return [OmniAI::Schema::Format]
|
161
|
+
def self.format(name:, schema:)
|
162
|
+
OmniAI::Schema::Format.new(name:, schema:)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/lib/omniai/tool.rb
CHANGED
@@ -25,15 +25,15 @@ module OmniAI
|
|
25
25
|
@description = description
|
26
26
|
end
|
27
27
|
|
28
|
-
# @return [OmniAI::
|
28
|
+
# @return [OmniAI::Schema::Object]
|
29
29
|
def parameters
|
30
|
-
@parameters ||=
|
30
|
+
@parameters ||= OmniAI::Schema::Object.new
|
31
31
|
end
|
32
32
|
|
33
33
|
# @param name [Symbol]
|
34
34
|
# @param kind [Symbol]
|
35
35
|
def parameter(name, kind, **)
|
36
|
-
parameters.properties[name] =
|
36
|
+
parameters.properties[name] = OmniAI::Schema.build(kind, **)
|
37
37
|
end
|
38
38
|
|
39
39
|
# @param names [Array<Symbol>]
|
@@ -118,7 +118,7 @@ module OmniAI
|
|
118
118
|
function: {
|
119
119
|
name: @name,
|
120
120
|
description: @description,
|
121
|
-
parameters: @parameters.is_a?(
|
121
|
+
parameters: @parameters.is_a?(Schema::Object) ? @parameters.serialize : @parameters,
|
122
122
|
}.compact,
|
123
123
|
}
|
124
124
|
end
|
@@ -134,7 +134,7 @@ module OmniAI
|
|
134
134
|
# @param args [Hash]
|
135
135
|
# @return [String]
|
136
136
|
def call(args = {})
|
137
|
-
@function.call(**(@parameters.is_a?(
|
137
|
+
@function.call(**(@parameters.is_a?(Schema::Object) ? @parameters.parse(args) : args))
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
data/lib/omniai/version.rb
CHANGED
data/lib/omniai.rb
CHANGED
@@ -16,6 +16,68 @@ loader.inflector.inflect "http_error" => "HTTPError"
|
|
16
16
|
loader.inflector.inflect "ssl_error" => "SSLError"
|
17
17
|
loader.setup
|
18
18
|
|
19
|
+
# @example
|
20
|
+
#
|
21
|
+
# OmniAI.chat(...)
|
22
|
+
# OmniAI.transcribe(...)
|
23
|
+
# OmniAI.speak(...)
|
24
|
+
# OmniAI.embed(...)
|
19
25
|
module OmniAI
|
20
26
|
class Error < StandardError; end
|
27
|
+
|
28
|
+
# Discover a client by provider ('openai' then 'anthropic' then 'google' then 'mistral' then 'deepseek').
|
29
|
+
#
|
30
|
+
# @param provider [Symbol] the provider to use (e.g. :openai, :anthropic, :google, :mistral, :deepseek) - optional
|
31
|
+
#
|
32
|
+
# @raise [OmniAI::LoadError] if no providers are installed
|
33
|
+
#
|
34
|
+
# @return [OmniAI::Client]
|
35
|
+
def self.client(provider: nil, **)
|
36
|
+
provider ? OmniAI::Client.find(provider:, **) : OmniAI::Client.discover(**)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @example
|
40
|
+
# response = OmniAI.chat("What is the capital of Spain?")
|
41
|
+
# puts response.text
|
42
|
+
#
|
43
|
+
# @example
|
44
|
+
# OmniAI.chat(stream: $stdout) do |prompt|
|
45
|
+
# prompt.system("Answer in both English and French.")
|
46
|
+
# prompt.user("How many people live in Tokyo?")
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# @see OmniAI::Client#chat
|
50
|
+
def self.chat(...)
|
51
|
+
client.chat(...)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @example
|
55
|
+
# File.open("audio.wav", "rb") do |file|
|
56
|
+
# puts OmniAI.transcribe(file).text
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# @see OmniAI::Client#transcribe
|
60
|
+
def self.transcribe(...)
|
61
|
+
client.transcribe(...)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @example
|
65
|
+
# File.open("audio.wav", "wb") do |file|
|
66
|
+
# OmniAI.speak("Sally sells seashells by the seashore.") do |chunk|
|
67
|
+
# file << chunk
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# @see OmniAI::Client#speak
|
72
|
+
def self.speak(...)
|
73
|
+
client.speak(...)
|
74
|
+
end
|
75
|
+
|
76
|
+
# @example
|
77
|
+
# embedding = OmniAI.embed("The quick brown fox jumps over the lazy dog.").embedding
|
78
|
+
#
|
79
|
+
# @see OmniAI::Client#embed
|
80
|
+
def self.embed(...)
|
81
|
+
client.embed(...)
|
82
|
+
end
|
21
83
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-05-22 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: event_stream_parser
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- lib/omniai/files.rb
|
113
113
|
- lib/omniai/http_error.rb
|
114
114
|
- lib/omniai/instrumentation.rb
|
115
|
+
- lib/omniai/load_error.rb
|
115
116
|
- lib/omniai/mcp/jrpc.rb
|
116
117
|
- lib/omniai/mcp/jrpc/error.rb
|
117
118
|
- lib/omniai/mcp/jrpc/request.rb
|
@@ -119,13 +120,14 @@ files:
|
|
119
120
|
- lib/omniai/mcp/server.rb
|
120
121
|
- lib/omniai/mcp/transport/base.rb
|
121
122
|
- lib/omniai/mcp/transport/stdio.rb
|
123
|
+
- lib/omniai/schema.rb
|
124
|
+
- lib/omniai/schema/array.rb
|
125
|
+
- lib/omniai/schema/format.rb
|
126
|
+
- lib/omniai/schema/object.rb
|
127
|
+
- lib/omniai/schema/scalar.rb
|
122
128
|
- lib/omniai/speak.rb
|
123
129
|
- lib/omniai/ssl_error.rb
|
124
130
|
- lib/omniai/tool.rb
|
125
|
-
- lib/omniai/tool/array.rb
|
126
|
-
- lib/omniai/tool/object.rb
|
127
|
-
- lib/omniai/tool/parameters.rb
|
128
|
-
- lib/omniai/tool/property.rb
|
129
131
|
- lib/omniai/transcribe.rb
|
130
132
|
- lib/omniai/transcribe/transcription.rb
|
131
133
|
- lib/omniai/version.rb
|
data/lib/omniai/tool/array.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OmniAI
|
4
|
-
class Tool
|
5
|
-
# Represents a schema object.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# array = OmniAI::Tool::Array.new(
|
9
|
-
# description: 'A list of people.',
|
10
|
-
# items: OmniAI::Tool::Object.new(
|
11
|
-
# properties: {
|
12
|
-
# name: OmniAI::Tool::Property.string(description: 'The name of the person.'),
|
13
|
-
# age: OmniAI::Tool::Property.integer(description: 'The age of the person.'),
|
14
|
-
# },
|
15
|
-
# required: %i[name]
|
16
|
-
# ),
|
17
|
-
# min_items: 1,
|
18
|
-
# max_items: 5,
|
19
|
-
# })
|
20
|
-
class Array
|
21
|
-
TYPE = "array"
|
22
|
-
|
23
|
-
# @!attribute [rw] items
|
24
|
-
# @return [OmniAI::Tool::Object, OmniAI::Tool::Array, OmniAI::Tool::Property]
|
25
|
-
attr_accessor :items
|
26
|
-
|
27
|
-
# @!attribute [rw] max_items
|
28
|
-
# @return [Integer, nil]
|
29
|
-
attr_accessor :max_items
|
30
|
-
|
31
|
-
# @!attribute [rw] min_items
|
32
|
-
# @return [Integer, nil]
|
33
|
-
attr_accessor :min_items
|
34
|
-
|
35
|
-
# @!attribute [rw] description
|
36
|
-
# @return [String, nil]
|
37
|
-
attr_accessor :description
|
38
|
-
|
39
|
-
# @param items [OmniAI::Tool::Object, OmniAI::Tool::Array, OmniAI::Tool::Property] required
|
40
|
-
# @param max_items [Integer] optional
|
41
|
-
# @param min_items [Integer] optional
|
42
|
-
# @param description [String] optional
|
43
|
-
def initialize(items:, max_items: nil, min_items: nil, description: nil)
|
44
|
-
@items = items
|
45
|
-
@description = description
|
46
|
-
@max_items = max_items
|
47
|
-
@min_items = min_items
|
48
|
-
end
|
49
|
-
|
50
|
-
# @example
|
51
|
-
# array.serialize # => { type: 'array', items: { type: 'string' } }
|
52
|
-
#
|
53
|
-
# @return [Hash]
|
54
|
-
def serialize
|
55
|
-
{
|
56
|
-
type: TYPE,
|
57
|
-
description: @description,
|
58
|
-
items: @items.serialize,
|
59
|
-
maxItems: @max_items,
|
60
|
-
minItems: @min_items,
|
61
|
-
}.compact
|
62
|
-
end
|
63
|
-
|
64
|
-
# @example
|
65
|
-
# array.parse(['1', '2', '3']) # => [1, 2, 3]
|
66
|
-
# @param args [Array]
|
67
|
-
#
|
68
|
-
# @return [Array]
|
69
|
-
def parse(args)
|
70
|
-
args.map { |arg| @items.parse(arg) }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/omniai/tool/object.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OmniAI
|
4
|
-
class Tool
|
5
|
-
# Represents a schema object.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# object = OmniAI::Tool::Object.new(
|
9
|
-
# properties: {
|
10
|
-
# name: OmniAI::Tool::Property.string(description: 'The name of the person.'),
|
11
|
-
# age: OmniAI::Tool::Property.integer(description: 'The age of the person.'),
|
12
|
-
# },
|
13
|
-
# required: %i[name]
|
14
|
-
# })
|
15
|
-
class Object
|
16
|
-
TYPE = "object"
|
17
|
-
|
18
|
-
# @!attribute [rw] properties
|
19
|
-
# @return [Hash]
|
20
|
-
attr_accessor :properties
|
21
|
-
|
22
|
-
# @!attribute [rw] required
|
23
|
-
# @return [Array<String>]
|
24
|
-
attr_accessor :required
|
25
|
-
|
26
|
-
# @!attribute [rw] description
|
27
|
-
# @return [String, nil]
|
28
|
-
attr_accessor :description
|
29
|
-
|
30
|
-
# @param properties [Hash]
|
31
|
-
# @param required [Array<String>]
|
32
|
-
# @return [OmniAI::Tool::Parameters]
|
33
|
-
def initialize(properties: {}, required: [], description: nil)
|
34
|
-
@properties = properties
|
35
|
-
@required = required
|
36
|
-
@description = description
|
37
|
-
end
|
38
|
-
|
39
|
-
# @return [Hash]
|
40
|
-
def serialize
|
41
|
-
{
|
42
|
-
type: TYPE,
|
43
|
-
description: @description,
|
44
|
-
properties: @properties.transform_values(&:serialize),
|
45
|
-
required: @required,
|
46
|
-
}.compact
|
47
|
-
end
|
48
|
-
|
49
|
-
# @param args [Hash]
|
50
|
-
#
|
51
|
-
# @return [Hash]
|
52
|
-
def parse(args)
|
53
|
-
result = {}
|
54
|
-
@properties.each do |name, property|
|
55
|
-
value = args[String(name)]
|
56
|
-
result[name.intern] = property.parse(value) unless value.nil?
|
57
|
-
end
|
58
|
-
result
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OmniAI
|
4
|
-
class Tool
|
5
|
-
# Parameters are used to define the arguments for a tool.
|
6
|
-
#
|
7
|
-
# @example
|
8
|
-
# parameters = OmniAI::Tool::Parameters.new(properties: {
|
9
|
-
# people: OmniAI::Tool::Parameters.array(
|
10
|
-
# items: OmniAI::Tool::Parameters.object(
|
11
|
-
# properties: {
|
12
|
-
# name: OmniAI::Tool::Parameters.string(description: 'The name of the person.'),
|
13
|
-
# age: OmniAI::Tool::Parameters.integer(description: 'The age of the person.'),
|
14
|
-
# employed: OmniAI::Tool::Parameters.boolean(description: 'Is the person employed?'),
|
15
|
-
# }
|
16
|
-
# n: OmniAI::Tool::Parameters.integer(description: 'The nth number to calculate.')
|
17
|
-
# required: %i[n]
|
18
|
-
# })
|
19
|
-
# tool = OmniAI::Tool.new(fibonacci, parameters: parameters)
|
20
|
-
class Parameters < Object
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|