omniai 1.9.0 → 1.9.1
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 +26 -4
- data/lib/omniai/tool/array.rb +74 -0
- data/lib/omniai/tool/object.rb +62 -0
- data/lib/omniai/tool/parameters.rb +15 -39
- data/lib/omniai/tool/property.rb +66 -18
- data/lib/omniai/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a97ef62618647e49906212c6b7d01e1b17fe3f8149a651d3f3481a3ffd46b79
|
4
|
+
data.tar.gz: d97ec89bb5eac0f6e2c393bacdc9e2e3408d1eec62b612371e465506477bc598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08f05b135a0ac4d9acaf33fc0b221d4c4cf6634a0face266a57d0886821816984b7cdda3dffe266dc4b178497bf385a75221abb0b3afd8a650065631dea8838d'
|
7
|
+
data.tar.gz: b0c5655ac13cfdc37e429181e6e7315d2a1717b2a17bce253c655c715efa9a9dd595ad1ddc05bdb9e172a0ff9167b05f9b9ddc0344a10c224be4bbc5d11b087c
|
data/README.md
CHANGED
@@ -72,16 +72,38 @@ require 'omniai/google'
|
|
72
72
|
|
73
73
|
CLIENT = OmniAI::Google::Client.new
|
74
74
|
|
75
|
+
LOCATION = OmniAI::Tool::Property.object(
|
76
|
+
properties: {
|
77
|
+
city: OmniAI::Tool::Property.string(description: 'e.g. "Toronto"'),
|
78
|
+
country: OmniAI::Tool::Property.string(description: 'e.g. "Canada"'),
|
79
|
+
},
|
80
|
+
required: %i[city country]
|
81
|
+
)
|
82
|
+
|
83
|
+
LOCATIONS = OmniAI::Tool::Property.array(
|
84
|
+
min_items: 1,
|
85
|
+
max_items: 5,
|
86
|
+
items: LOCATION
|
87
|
+
)
|
88
|
+
|
89
|
+
UNIT = OmniAI::Tool::Property.string(enum: %w[celcius fahrenheit])
|
90
|
+
|
91
|
+
WEATHER = proc do |locations:, unit: 'celsius'|
|
92
|
+
locations.map do |location|
|
93
|
+
"#{rand(20..50)}° #{unit} in #{location[:city]}, #{location[:country]}"
|
94
|
+
end.join("\n")
|
95
|
+
end
|
96
|
+
|
75
97
|
TOOL = OmniAI::Tool.new(
|
76
|
-
|
98
|
+
WEATHER,
|
77
99
|
name: 'Weather',
|
78
100
|
description: 'Lookup the weather in a location',
|
79
101
|
parameters: OmniAI::Tool::Parameters.new(
|
80
102
|
properties: {
|
81
|
-
|
82
|
-
unit:
|
103
|
+
locations: LOCATIONS,
|
104
|
+
unit: UNIT,
|
83
105
|
},
|
84
|
-
required: %i[
|
106
|
+
required: %i[locations]
|
85
107
|
)
|
86
108
|
)
|
87
109
|
|
@@ -0,0 +1,74 @@
|
|
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
|
@@ -0,0 +1,62 @@
|
|
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
|
@@ -2,46 +2,22 @@
|
|
2
2
|
|
3
3
|
module OmniAI
|
4
4
|
class Tool
|
5
|
-
#
|
5
|
+
# Parameters are used to define the arguments for a tool.
|
6
6
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
@type = type
|
22
|
-
@properties = properties
|
23
|
-
@required = required
|
24
|
-
end
|
25
|
-
|
26
|
-
# @return [Hash]
|
27
|
-
def serialize
|
28
|
-
{
|
29
|
-
type: @type,
|
30
|
-
properties: @properties.transform_values(&:serialize),
|
31
|
-
required: @required,
|
32
|
-
}.compact
|
33
|
-
end
|
34
|
-
|
35
|
-
# @param args [Hash]
|
36
|
-
# @return [Hash]
|
37
|
-
def parse(args)
|
38
|
-
result = {}
|
39
|
-
@properties.each do |name, property|
|
40
|
-
value = args[String(name)]
|
41
|
-
result[name.intern] = property.parse(value) if value
|
42
|
-
end
|
43
|
-
result
|
44
|
-
end
|
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
|
+
# employeed: OmniAI::Tool::Parameters.boolean(description: 'Is the person employeed?'),
|
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
|
45
21
|
end
|
46
22
|
end
|
47
23
|
end
|
data/lib/omniai/tool/property.rb
CHANGED
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module OmniAI
|
4
4
|
class Tool
|
5
|
-
#
|
5
|
+
# A property used for a tool parameter.
|
6
6
|
#
|
7
|
-
#
|
7
|
+
# @example
|
8
|
+
# OmniAI::Tool::Property.array(description: '...', items: ...)
|
9
|
+
# OmniAI::Tool::Property.object(description: '...', properties: { ... }, required: %i[...])
|
10
|
+
# OmniAI::Tool::Property.string(description: '...')
|
11
|
+
# OmniAI::Tool::Property.integer(description: '...')
|
12
|
+
# OmniAI::Tool::Property.number(description: '...')
|
13
|
+
# OmniAI::Tool::Property.boolean(description: '...')
|
8
14
|
class Property
|
9
15
|
module Type
|
10
16
|
BOOLEAN = 'boolean'
|
@@ -22,36 +28,80 @@ module OmniAI
|
|
22
28
|
# @return [Array<String>, nil]
|
23
29
|
attr_reader :enum
|
24
30
|
|
25
|
-
# @
|
26
|
-
#
|
31
|
+
# @example
|
32
|
+
# property = OmniAI::Tool::Property.array(
|
33
|
+
# items: OmniAI::Tool::Property.string(description: 'The name of the person.'),
|
34
|
+
# description: 'A list of names.'
|
35
|
+
# min_items: 1,
|
36
|
+
# max_items: 5,
|
37
|
+
# )
|
38
|
+
#
|
39
|
+
# @param items [OmniAI::Tool::Property] required - the items in the array
|
40
|
+
# @param min_items [Integer] optional - the minimum number of items
|
41
|
+
# @param max_items [Integer] optional - the maximum number of items
|
42
|
+
# @param description [String] optional - a description of the array
|
43
|
+
#
|
44
|
+
# @return [OmniAI::Tool::Array]
|
45
|
+
def self.array(items:, min_items: nil, max_items: nil, description: nil)
|
46
|
+
OmniAI::Tool::Array.new(items:, description:, min_items:, max_items:)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @example
|
50
|
+
# property = OmniAI::Tool::Property.object(
|
51
|
+
# properties: {
|
52
|
+
# name: OmniAI::Tool::Property.string(description: 'The name of the person.'),
|
53
|
+
# age: OmniAI::Tool::Property.integer(description: 'The age of the person.'),
|
54
|
+
# employeed: OmniAI::Tool::Property.boolean(description: 'Is the person employeed?'),
|
55
|
+
# },
|
56
|
+
# description: 'A person.'
|
57
|
+
# required: %i[name]
|
58
|
+
# )
|
59
|
+
#
|
60
|
+
# @param properties [Hash<String, OmniAI::Tool::Property>] required - the properties of the object
|
61
|
+
# @param requird [Array<Symbol>] optional - the required properties
|
62
|
+
# @param description [String] optional - a description of the object
|
63
|
+
#
|
64
|
+
# @return [OmniAI::Tool::Array]
|
65
|
+
def self.object(properties: {}, required: [], description: nil)
|
66
|
+
OmniAI::Tool::Object.new(properties:, required:, description:)
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param description [String] optional - a description of the property
|
70
|
+
# @param enum [Array<Boolean>] optional - the possible values of the property
|
71
|
+
#
|
27
72
|
# @return [OmniAI::Tool::Property]
|
28
73
|
def self.boolean(description: nil, enum: nil)
|
29
74
|
new(type: Type::BOOLEAN, description:, enum:)
|
30
75
|
end
|
31
76
|
|
32
|
-
# @param description [String]
|
33
|
-
# @param enum [Array<
|
77
|
+
# @param description [String] optional - a description of the property
|
78
|
+
# @param enum [Array<Integer>] optinoal - the possible values of the property
|
79
|
+
#
|
34
80
|
# @return [OmniAI::Tool::Property]
|
35
81
|
def self.integer(description: nil, enum: nil)
|
36
82
|
new(type: Type::INTEGER, description:, enum:)
|
37
83
|
end
|
38
84
|
|
39
|
-
# @param description [String]
|
40
|
-
# @param enum [Array<String>]
|
85
|
+
# @param description [String] optional - a description of the property
|
86
|
+
# @param enum [Array<String>] optional - the possible values of the property
|
87
|
+
#
|
41
88
|
# @return [OmniAI::Tool::Property]
|
42
89
|
def self.string(description: nil, enum: nil)
|
43
90
|
new(type: Type::STRING, description:, enum:)
|
44
91
|
end
|
45
92
|
|
46
|
-
# @param description [String]
|
47
|
-
# @param enum [Array<
|
93
|
+
# @param description [String] optional - a description of the property
|
94
|
+
# @param enum [Array<Number>] optional - the possible values of the property
|
95
|
+
#
|
48
96
|
# @return [OmniAI::Tool::Property]
|
49
97
|
def self.number(description: nil, enum: nil)
|
50
98
|
new(type: Type::NUMBER, description:, enum:)
|
51
99
|
end
|
52
100
|
|
53
|
-
# @param
|
54
|
-
# @param
|
101
|
+
# @param type [String] required - the type of the property
|
102
|
+
# @param description [String] optional - a description of the property
|
103
|
+
# @param enum [Array] optional - the possible values of the property
|
104
|
+
#
|
55
105
|
# @return [OmniAI::Tool::Property]
|
56
106
|
def initialize(type:, description: nil, enum: nil)
|
57
107
|
@type = type
|
@@ -60,12 +110,7 @@ module OmniAI
|
|
60
110
|
end
|
61
111
|
|
62
112
|
# @example
|
63
|
-
# property.serialize
|
64
|
-
# # {
|
65
|
-
# # type: 'string',
|
66
|
-
# # description: 'The unit (e.g. "fahrenheit" or "celsius").'
|
67
|
-
# # enum: %w[fahrenheit celsius]
|
68
|
-
# # }
|
113
|
+
# property.serialize #=> { type: 'string' }
|
69
114
|
#
|
70
115
|
# @return [Hash]
|
71
116
|
def serialize
|
@@ -76,6 +121,9 @@ module OmniAI
|
|
76
121
|
}.compact
|
77
122
|
end
|
78
123
|
|
124
|
+
# @example
|
125
|
+
# property.parse('123') #=> 123
|
126
|
+
#
|
79
127
|
# @return [String, Integer, Float, Boolean, Object]
|
80
128
|
def parse(value)
|
81
129
|
case @type
|
data/lib/omniai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -98,6 +98,8 @@ files:
|
|
98
98
|
- lib/omniai/instrumentation.rb
|
99
99
|
- lib/omniai/speak.rb
|
100
100
|
- lib/omniai/tool.rb
|
101
|
+
- lib/omniai/tool/array.rb
|
102
|
+
- lib/omniai/tool/object.rb
|
101
103
|
- lib/omniai/tool/parameters.rb
|
102
104
|
- lib/omniai/tool/property.rb
|
103
105
|
- lib/omniai/transcribe.rb
|