omniai 1.9.0 → 1.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +31 -5
- 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: 4f2dff570036129e4ae7b41a113f644a19a6dd1c75e71852721c5f7fc5fdd068
|
4
|
+
data.tar.gz: d48375ab7e70758ad7fc931d0ac70f739807e10cc35bc22161ddcb8a758fc0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 537c4e16730332602dccfc9fb3011f99739fdfec133362b362fded6e2fb54ec66c7070872426f331f6160dd3fdd3e82c61b7bfb326c8c2a5399fe662eb51acfc
|
7
|
+
data.tar.gz: 79b2adcacba078cbd8aa72330a9d8f6a1e1895e5824cccbf89bab50a86a789fdd83f49d23a70f39785912273ce8826cbbc6eba40eee2d7d671ff52a34b1bb171
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# OmniAI
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/ksylvest/omniai/blob/main/LICENSE)
|
4
|
+
[![RubyGems](https://img.shields.io/gem/v/omniai)](https://rubygems.org/gems/omniai)
|
5
|
+
[![GitHub](https://img.shields.io/badge/github-repo-blue.svg)](https://github.com/ksylvest/omniai)
|
6
|
+
[![Yard](https://img.shields.io/badge/docs-site-blue.svg)](https://omniai.ksylvest.com)
|
7
|
+
[![CircleCI](https://img.shields.io/circleci/build/github/ksylvest/omniai)](https://circleci.com/gh/ksylvest/omniai)
|
4
8
|
|
5
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.
|
6
10
|
|
@@ -72,16 +76,38 @@ require 'omniai/google'
|
|
72
76
|
|
73
77
|
CLIENT = OmniAI::Google::Client.new
|
74
78
|
|
79
|
+
LOCATION = OmniAI::Tool::Property.object(
|
80
|
+
properties: {
|
81
|
+
city: OmniAI::Tool::Property.string(description: 'e.g. "Toronto"'),
|
82
|
+
country: OmniAI::Tool::Property.string(description: 'e.g. "Canada"'),
|
83
|
+
},
|
84
|
+
required: %i[city country]
|
85
|
+
)
|
86
|
+
|
87
|
+
LOCATIONS = OmniAI::Tool::Property.array(
|
88
|
+
min_items: 1,
|
89
|
+
max_items: 5,
|
90
|
+
items: LOCATION
|
91
|
+
)
|
92
|
+
|
93
|
+
UNIT = OmniAI::Tool::Property.string(enum: %w[celcius fahrenheit])
|
94
|
+
|
95
|
+
WEATHER = proc do |locations:, unit: 'celsius'|
|
96
|
+
locations.map do |location|
|
97
|
+
"#{rand(20..50)}° #{unit} in #{location[:city]}, #{location[:country]}"
|
98
|
+
end.join("\n")
|
99
|
+
end
|
100
|
+
|
75
101
|
TOOL = OmniAI::Tool.new(
|
76
|
-
|
102
|
+
WEATHER,
|
77
103
|
name: 'Weather',
|
78
104
|
description: 'Lookup the weather in a location',
|
79
105
|
parameters: OmniAI::Tool::Parameters.new(
|
80
106
|
properties: {
|
81
|
-
|
82
|
-
unit:
|
107
|
+
locations: LOCATIONS,
|
108
|
+
unit: UNIT,
|
83
109
|
},
|
84
|
-
required: %i[
|
110
|
+
required: %i[locations]
|
85
111
|
)
|
86
112
|
)
|
87
113
|
|
@@ -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.2
|
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-05 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
|