omniai 3.1.0 → 3.1.2
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 +18 -18
- data/lib/omniai/schema/array.rb +38 -36
- data/lib/omniai/schema/base.rb +73 -0
- data/lib/omniai/schema/object.rb +40 -49
- data/lib/omniai/schema/scalar.rb +16 -11
- data/lib/omniai/schema.rb +27 -14
- data/lib/omniai/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4564620d223dc2b398e45479742eb8e2ab9873716a946af44a069b1df84ec96
|
|
4
|
+
data.tar.gz: d03aae31d15a19f1f14b0bf9643f79e85ac9f31aa4d8c0fa5b0d2ad0b959e982
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e09fcf9083efd4b6de9bd6e8658f04f4b6a6a92f27a935d30e345fed635609d0dd1b21bb0c32e78c25f3fd2e9b7a8f6728b367db6190fa4f69bf7dc47a717f42
|
|
7
|
+
data.tar.gz: 026e7f2fbddab552fc2635cd11856d652e06f2a3a3a9e30990612da223fe979aee105495be6d39a163dc8040c7bca927e16a6cddec63efe761570ab7eabc30ab
|
data/README.md
CHANGED
|
@@ -456,23 +456,23 @@ client = OmniAI::OpenAI::Client.new(timeout: {
|
|
|
456
456
|
|
|
457
457
|
### 💬 Chat
|
|
458
458
|
|
|
459
|
-
Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc) generate
|
|
459
|
+
Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc) generate text using the following calls:
|
|
460
460
|
|
|
461
|
-
####
|
|
461
|
+
#### Using a Basic Prompt
|
|
462
462
|
|
|
463
|
-
|
|
463
|
+
A chat response can be generated using a string for a prompt:
|
|
464
464
|
|
|
465
465
|
```ruby
|
|
466
|
-
|
|
467
|
-
|
|
466
|
+
response = client.chat('Tell me a joke.')
|
|
467
|
+
response.text # 'Why don't scientists trust atoms? They make up everything!'
|
|
468
468
|
```
|
|
469
469
|
|
|
470
|
-
####
|
|
470
|
+
#### Using a Complex Prompt
|
|
471
471
|
|
|
472
|
-
|
|
472
|
+
A chat response can be generated using a combination of messages and parts for a prompt:
|
|
473
473
|
|
|
474
474
|
```ruby
|
|
475
|
-
|
|
475
|
+
response = client.chat do |prompt|
|
|
476
476
|
prompt.system 'You are a helpful assistant with an expertise in animals.'
|
|
477
477
|
prompt.user do |message|
|
|
478
478
|
message.text 'What animals are in the attached photos?'
|
|
@@ -481,12 +481,12 @@ completion = client.chat do |prompt|
|
|
|
481
481
|
message.file('./hamster.jpeg', "image/jpeg")
|
|
482
482
|
end
|
|
483
483
|
end
|
|
484
|
-
|
|
484
|
+
response.text # 'They are photos of a cat, a cat, and a hamster.'
|
|
485
485
|
```
|
|
486
486
|
|
|
487
|
-
####
|
|
487
|
+
#### Streaming via Proc
|
|
488
488
|
|
|
489
|
-
A real-time stream of
|
|
489
|
+
A chat real-time stream of chunks can be generated with a proc:
|
|
490
490
|
|
|
491
491
|
```ruby
|
|
492
492
|
stream = proc do |chunk|
|
|
@@ -495,25 +495,25 @@ end
|
|
|
495
495
|
client.chat('Tell me a joke.', stream:)
|
|
496
496
|
```
|
|
497
497
|
|
|
498
|
-
####
|
|
498
|
+
#### Streaming via IO
|
|
499
499
|
|
|
500
|
-
|
|
500
|
+
A chat real-time stream of chunks can also work with any IO object (e.g., `File`, `$stdout`, `$stdin`, etc.):
|
|
501
501
|
|
|
502
502
|
```ruby
|
|
503
503
|
client.chat('Tell me a story', stream: $stdout)
|
|
504
504
|
```
|
|
505
505
|
|
|
506
|
-
####
|
|
506
|
+
#### Using Tools
|
|
507
507
|
|
|
508
|
-
|
|
508
|
+
The chat API can be provided with a set of tools to be invoked:
|
|
509
509
|
|
|
510
510
|
```ruby
|
|
511
511
|
class WeatherTool
|
|
512
512
|
description "Lookup the weather at a location in either Celsius or Fahrenheit."
|
|
513
513
|
|
|
514
|
-
parameter :location, :string, description: "The location to find the weather."
|
|
515
|
-
parameter :unit, :string, enum: %w[Celsius Fahrenheit], description: "The unit of measurement."
|
|
516
|
-
required %i[location]
|
|
514
|
+
parameter :location, :string, description: "The location to find the weather.", nullable: false
|
|
515
|
+
parameter :unit, :string, enum: %w[Celsius Fahrenheit], description: "The unit of measurement.", nullable: true
|
|
516
|
+
required %i[location unit]
|
|
517
517
|
|
|
518
518
|
# @param location [String]
|
|
519
519
|
# @param unit [String] "Celsius" or "Fahrenheit"
|
data/lib/omniai/schema/array.rb
CHANGED
|
@@ -16,7 +16,7 @@ module OmniAI
|
|
|
16
16
|
# })
|
|
17
17
|
# array.serialize # => { type: "array", items: { ... }, minItems: 1, maxItems: 5 }
|
|
18
18
|
# array.parse([{ "name" => "Ringo Starr" }]) # => [{ name: "Ringo Star" }]
|
|
19
|
-
class Array
|
|
19
|
+
class Array < Base
|
|
20
20
|
TYPE = "array"
|
|
21
21
|
|
|
22
22
|
# @!attribute [rw] items
|
|
@@ -31,41 +31,29 @@ module OmniAI
|
|
|
31
31
|
# @return [Integer, nil]
|
|
32
32
|
attr_accessor :min_items
|
|
33
33
|
|
|
34
|
-
# @!attribute [rw] description
|
|
35
|
-
# @return [String, nil]
|
|
36
|
-
attr_accessor :description
|
|
37
|
-
|
|
38
|
-
# @example
|
|
39
|
-
# array = OmniAI::Schema::Array.deserialize({
|
|
40
|
-
# type: "array",
|
|
41
|
-
# items: { type: "string" },
|
|
42
|
-
# minItems: 1,
|
|
43
|
-
# maxItems: 5,
|
|
44
|
-
# description: "A list of strings."
|
|
45
|
-
# }) # => OmniAI::Schema::Array
|
|
46
|
-
#
|
|
47
|
-
# @param data [Hash]
|
|
48
|
-
#
|
|
49
|
-
# @return [OmniAI::Schema::Array]
|
|
50
|
-
def self.deserialize(data)
|
|
51
|
-
new(
|
|
52
|
-
items: OmniAI::Schema.deserialize(data["items"] || data[:items]),
|
|
53
|
-
max_items: data[:maxItems] || data["maxItems"],
|
|
54
|
-
min_items: data[:minItems] || data["minItems"],
|
|
55
|
-
description: data[:description] || data["description"]
|
|
56
|
-
)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
34
|
# @param items [OmniAI::Schema::Object, OmniAI::Schema::Array, OmniAI::Schema::Scalar] required
|
|
35
|
+
# @param title [String] optional
|
|
36
|
+
# @param description [String] optional
|
|
37
|
+
# @param nullable [Boolean] optional
|
|
60
38
|
# @param min_items [Integer] optional
|
|
61
39
|
# @param max_items [Integer] optional
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
super()
|
|
40
|
+
def initialize(items:, title: nil, description: nil, min_items: nil, max_items: nil, nullable: nil)
|
|
41
|
+
super(title:, description:, nullable:)
|
|
65
42
|
@items = items
|
|
66
43
|
@min_items = min_items
|
|
67
44
|
@max_items = max_items
|
|
68
|
-
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# @example
|
|
48
|
+
# array.parse(["1", "2", "3"]) # => [1, 2, 3]
|
|
49
|
+
#
|
|
50
|
+
# @param data [Array]
|
|
51
|
+
#
|
|
52
|
+
# @return [Array]
|
|
53
|
+
def parse(data)
|
|
54
|
+
return data if data.nil? && nullable?
|
|
55
|
+
|
|
56
|
+
data.map { |arg| @items.parse(arg) }
|
|
69
57
|
end
|
|
70
58
|
|
|
71
59
|
# @example
|
|
@@ -76,7 +64,7 @@ module OmniAI
|
|
|
76
64
|
# @return [Hash]
|
|
77
65
|
def serialize(additional_properties: false)
|
|
78
66
|
{
|
|
79
|
-
type: TYPE,
|
|
67
|
+
type: nullify(TYPE),
|
|
80
68
|
description: @description,
|
|
81
69
|
items: @items.serialize(additional_properties:),
|
|
82
70
|
maxItems: @max_items,
|
|
@@ -85,13 +73,27 @@ module OmniAI
|
|
|
85
73
|
end
|
|
86
74
|
|
|
87
75
|
# @example
|
|
88
|
-
# array.
|
|
76
|
+
# array = OmniAI::Schema::Array.deserialize({
|
|
77
|
+
# type: "array",
|
|
78
|
+
# items: { type: "string" },
|
|
79
|
+
# minItems: 1,
|
|
80
|
+
# maxItems: 5,
|
|
81
|
+
# description: "A list of strings."
|
|
82
|
+
# }) # => OmniAI::Schema::Array
|
|
89
83
|
#
|
|
90
|
-
# @param data [
|
|
84
|
+
# @param data [Hash]
|
|
91
85
|
#
|
|
92
|
-
# @return [Array]
|
|
93
|
-
def
|
|
94
|
-
data
|
|
86
|
+
# @return [OmniAI::Schema::Array]
|
|
87
|
+
def self.deserialize(data)
|
|
88
|
+
nullable = Array(data[:type] || data["type"]).include?("null")
|
|
89
|
+
|
|
90
|
+
new(
|
|
91
|
+
items: OmniAI::Schema.deserialize(data["items"] || data[:items]),
|
|
92
|
+
max_items: data[:maxItems] || data["maxItems"],
|
|
93
|
+
min_items: data[:minItems] || data["minItems"],
|
|
94
|
+
description: data[:description] || data["description"],
|
|
95
|
+
nullable:
|
|
96
|
+
)
|
|
95
97
|
end
|
|
96
98
|
end
|
|
97
99
|
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OmniAI
|
|
4
|
+
module Schema
|
|
5
|
+
# @example
|
|
6
|
+
# object = OmniAI::Tool::Base.deserialize({ ... })
|
|
7
|
+
# object.serialize # => { ... }
|
|
8
|
+
# object.parse(...]
|
|
9
|
+
class Base
|
|
10
|
+
# @!attribute [rw] title
|
|
11
|
+
# @return [String, nil]
|
|
12
|
+
attr_accessor :title
|
|
13
|
+
|
|
14
|
+
# @!attribute [rw] description
|
|
15
|
+
# @return [String, nil]
|
|
16
|
+
attr_accessor :description
|
|
17
|
+
|
|
18
|
+
# @param title [String] optional
|
|
19
|
+
# @param description [String] optional
|
|
20
|
+
# @param nullable [Boolean] optional
|
|
21
|
+
def initialize(title: nil, description: nil, nullable: nil)
|
|
22
|
+
super()
|
|
23
|
+
@title = title
|
|
24
|
+
@description = description
|
|
25
|
+
@nullable = nullable
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @param value [Object]
|
|
29
|
+
# @return Object
|
|
30
|
+
def parse(value)
|
|
31
|
+
raise NotImplementedError, "#parse undefined"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @param additional_properties [Boolean]
|
|
35
|
+
#
|
|
36
|
+
# @return [Hash]
|
|
37
|
+
def serialize(additional_properties: false)
|
|
38
|
+
raise NotImplementedError, "#serialize undefined"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @param data [Hash]
|
|
42
|
+
#
|
|
43
|
+
# @return [OmniAI::Schema::Base]
|
|
44
|
+
def self.deserialize(data)
|
|
45
|
+
raise NotImplementedError, ".deserialize undefined"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @return [Boolean]
|
|
49
|
+
def nullable?
|
|
50
|
+
!!@nullable
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @return [OmniAI::Schema::Base]
|
|
54
|
+
def nullable
|
|
55
|
+
dup.tap do |object|
|
|
56
|
+
object.nullable = true
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def nonnullable
|
|
61
|
+
dup.tap do |object|
|
|
62
|
+
object.nullable = false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
protected
|
|
67
|
+
|
|
68
|
+
def nullify(type)
|
|
69
|
+
nullable? ? ["null", type] : type
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/omniai/schema/object.rb
CHANGED
|
@@ -12,7 +12,7 @@ module OmniAI
|
|
|
12
12
|
# })
|
|
13
13
|
# schema.serialize #=> { type: "object", properties: { ... }, required: %i[name] }
|
|
14
14
|
# schema.parse({ "name" => "John Doe" }) #=> { name: "John Doe" }
|
|
15
|
-
class Object
|
|
15
|
+
class Object < Base
|
|
16
16
|
TYPE = "object"
|
|
17
17
|
|
|
18
18
|
# @!attribute [rw] properties
|
|
@@ -23,43 +23,13 @@ module OmniAI
|
|
|
23
23
|
# @return [Array<String>]
|
|
24
24
|
attr_accessor :required
|
|
25
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
26
|
# @param title [String] optional
|
|
56
27
|
# @param description [String] optional
|
|
57
28
|
# @param properties [Hash] optional
|
|
58
29
|
# @param required [Array<String>] optional
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@description = description
|
|
30
|
+
# @param nulable [Boolean] optional
|
|
31
|
+
def initialize(title: nil, description: nil, properties: {}, required: [], nullable: nil)
|
|
32
|
+
super(title:, description:, nullable:)
|
|
63
33
|
@properties = properties
|
|
64
34
|
@required = required
|
|
65
35
|
end
|
|
@@ -70,16 +40,32 @@ module OmniAI
|
|
|
70
40
|
title: @title,
|
|
71
41
|
description: @description,
|
|
72
42
|
properties: @properties.dup,
|
|
73
|
-
required: @required.dup
|
|
43
|
+
required: @required.dup,
|
|
44
|
+
nullable: @nullable
|
|
74
45
|
)
|
|
75
46
|
end
|
|
76
47
|
|
|
48
|
+
# @param data [Hash]
|
|
49
|
+
#
|
|
50
|
+
# @return [Hash]
|
|
51
|
+
def parse(data)
|
|
52
|
+
return if data.nil? && nullable?
|
|
53
|
+
|
|
54
|
+
result = {}
|
|
55
|
+
@properties.each do |name, property|
|
|
56
|
+
value = data[String(name)]
|
|
57
|
+
result[name.intern] = property.parse(value) unless value.nil?
|
|
58
|
+
end
|
|
59
|
+
result
|
|
60
|
+
end
|
|
61
|
+
|
|
77
62
|
# @param additional_properties [Boolean, nil] optional
|
|
63
|
+
# @param require_all [Boolean, nil] optional
|
|
78
64
|
#
|
|
79
65
|
# @return [Hash]
|
|
80
66
|
def serialize(additional_properties: false)
|
|
81
67
|
{
|
|
82
|
-
type: TYPE,
|
|
68
|
+
type: nullify(TYPE),
|
|
83
69
|
title: @title,
|
|
84
70
|
description: @description,
|
|
85
71
|
properties: @properties.transform_values { |value| value.serialize(additional_properties:) },
|
|
@@ -88,21 +74,26 @@ module OmniAI
|
|
|
88
74
|
}.compact
|
|
89
75
|
end
|
|
90
76
|
|
|
91
|
-
# @
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
# @example
|
|
78
|
+
# OmniAI::Schema::Object.deserialize({
|
|
79
|
+
# type: "object",
|
|
80
|
+
# properties: {
|
|
81
|
+
# name: { type: "string" }
|
|
82
|
+
# },
|
|
83
|
+
# required: ["name"],
|
|
84
|
+
# }) # => OmniAI::Schema::Object
|
|
85
|
+
#
|
|
96
86
|
# @param data [Hash]
|
|
97
87
|
#
|
|
98
|
-
# @return [
|
|
99
|
-
def
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
# @return [OmniAI::Schema::Object]
|
|
89
|
+
def self.deserialize(data)
|
|
90
|
+
nullable = Array(data["type"] || data[:type]).include?("null")
|
|
91
|
+
title = data["title"] || data[:title]
|
|
92
|
+
description = data["description"] || data[:description]
|
|
93
|
+
properties = (data["properties"] || data[:properties]).transform_values { |i| OmniAI::Schema.deserialize(i) }
|
|
94
|
+
required = data["required"] || data[:required] || []
|
|
95
|
+
|
|
96
|
+
new(title:, description:, properties:, required:, nullable:)
|
|
106
97
|
end
|
|
107
98
|
end
|
|
108
99
|
end
|
data/lib/omniai/schema/scalar.rb
CHANGED
|
@@ -22,7 +22,7 @@ module OmniAI
|
|
|
22
22
|
# scalar.serialize #=> { type: "boolean" }
|
|
23
23
|
# scalar.parse(true) #=> true
|
|
24
24
|
# scalar.parse(false) #=> false
|
|
25
|
-
class Scalar
|
|
25
|
+
class Scalar < Base
|
|
26
26
|
module Type
|
|
27
27
|
BOOLEAN = "boolean"
|
|
28
28
|
INTEGER = "integer"
|
|
@@ -34,10 +34,6 @@ module OmniAI
|
|
|
34
34
|
# @return [String]
|
|
35
35
|
attr_accessor :type
|
|
36
36
|
|
|
37
|
-
# @!attribute [rw] description
|
|
38
|
-
# @return [String, nil]
|
|
39
|
-
attr_accessor :description
|
|
40
|
-
|
|
41
37
|
# @!attribute [rw] enum
|
|
42
38
|
# @return [Array<String>, nil]
|
|
43
39
|
attr_accessor :enum
|
|
@@ -68,32 +64,39 @@ module OmniAI
|
|
|
68
64
|
#
|
|
69
65
|
# @return [OmniAI::Schema::Scalar]
|
|
70
66
|
def self.deserialize(data)
|
|
71
|
-
|
|
67
|
+
types = Array(data["type"] || data[:type] || Type::STRING)
|
|
68
|
+
type = types.find { |type| !type.eql?("null") }
|
|
69
|
+
title = data["title"] || data[:title]
|
|
72
70
|
description = data["description"] || data[:description]
|
|
73
71
|
enum = data["enum"] || data[:enum]
|
|
74
72
|
|
|
75
|
-
new(type:, description:, enum:)
|
|
73
|
+
new(type:, title:, description:, enum:, nullable: types.include?("null"))
|
|
76
74
|
end
|
|
77
75
|
|
|
78
76
|
# @param type [String] required - the type of the property
|
|
77
|
+
# @param title [String] optional - a title of the property
|
|
79
78
|
# @param description [String] optional - a description of the property
|
|
80
79
|
# @param enum [Array] optional - the possible values of the property
|
|
80
|
+
# @param nullable [Boolean] optional - if the property may be null
|
|
81
81
|
#
|
|
82
82
|
# @return [OmniAI::Schema::Scalar]
|
|
83
|
-
def initialize(type:, description: nil, enum: nil)
|
|
84
|
-
super()
|
|
83
|
+
def initialize(type:, title: nil, description: nil, enum: nil, nullable: nil)
|
|
84
|
+
super(title:, description:, nullable:)
|
|
85
85
|
@type = type
|
|
86
|
-
@description = description
|
|
87
86
|
@enum = enum
|
|
88
87
|
end
|
|
89
88
|
|
|
90
89
|
# @example
|
|
91
90
|
# property.serialize #=> { type: "string" }
|
|
92
91
|
#
|
|
92
|
+
# @example
|
|
93
|
+
# property.serialize #=> { type: ["strig", "null"] }
|
|
94
|
+
#
|
|
93
95
|
# @return [Hash]
|
|
94
96
|
def serialize(*)
|
|
95
97
|
{
|
|
96
|
-
type: @type,
|
|
98
|
+
type: nullify(@type),
|
|
99
|
+
title: @title,
|
|
97
100
|
description: @description,
|
|
98
101
|
enum: @enum,
|
|
99
102
|
}.compact
|
|
@@ -106,6 +109,8 @@ module OmniAI
|
|
|
106
109
|
#
|
|
107
110
|
# @return [String, Integer, Float, Boolean, Object]
|
|
108
111
|
def parse(value)
|
|
112
|
+
return if value.nil? && nullable?
|
|
113
|
+
|
|
109
114
|
case @type
|
|
110
115
|
when Type::INTEGER then Integer(value)
|
|
111
116
|
when Type::STRING then String(value)
|
data/lib/omniai/schema.rb
CHANGED
|
@@ -47,7 +47,9 @@ module OmniAI
|
|
|
47
47
|
#
|
|
48
48
|
# @param data [OmniAI::Schema::Object, OmniAI::Schema::Array, OmniAI::Schema::Scalar]
|
|
49
49
|
def self.deserialize(data)
|
|
50
|
-
|
|
50
|
+
type = Array(data["type"] || data[:type]).find { |type| !type.eql?("null") }
|
|
51
|
+
|
|
52
|
+
case type
|
|
51
53
|
when OmniAI::Schema::Array::TYPE then OmniAI::Schema::Array.deserialize(data)
|
|
52
54
|
when OmniAI::Schema::Object::TYPE then OmniAI::Schema::Object.deserialize(data)
|
|
53
55
|
else OmniAI::Schema::Scalar.deserialize(data)
|
|
@@ -80,10 +82,11 @@ module OmniAI
|
|
|
80
82
|
# @param min_items [Integer] optional - the minimum number of items
|
|
81
83
|
# @param max_items [Integer] optional - the maximum number of items
|
|
82
84
|
# @param description [String] optional - a description of the array
|
|
85
|
+
# @param nullable [Boolean] optional - if the array may be null
|
|
83
86
|
#
|
|
84
87
|
# @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:)
|
|
88
|
+
def self.array(items:, min_items: nil, max_items: nil, description: nil, nullable: nil)
|
|
89
|
+
OmniAI::Schema::Array.new(items:, description:, min_items:, max_items:, nullable:)
|
|
87
90
|
end
|
|
88
91
|
|
|
89
92
|
# @example
|
|
@@ -101,54 +104,63 @@ module OmniAI
|
|
|
101
104
|
# @param properties [Hash<String, OmniAI::Schema::Scalar>] required - the properties of the object
|
|
102
105
|
# @param required [Array<Symbol>] optional - the required properties
|
|
103
106
|
# @param description [String] optional - a description of the object
|
|
107
|
+
# @param nullable [Boolean] optional - if the object may be null
|
|
104
108
|
#
|
|
105
109
|
# @return [OmniAI::Schema::Array]
|
|
106
|
-
def self.object(title: nil, properties: {}, required: [], description: nil)
|
|
107
|
-
OmniAI::Schema::Object.new(title:, properties:, required:, description:)
|
|
110
|
+
def self.object(title: nil, properties: {}, required: [], description: nil, nullable: nil)
|
|
111
|
+
OmniAI::Schema::Object.new(title:, properties:, required:, description:, nullable:)
|
|
108
112
|
end
|
|
109
113
|
|
|
110
114
|
# @example
|
|
111
115
|
# OmniAI::Schema.boolean(description: "Is the person employed?") #=> OmniAI::Schema::Scalar
|
|
112
116
|
#
|
|
117
|
+
# @param title [String] optional - the title of the property
|
|
113
118
|
# @param description [String] optional - a description of the property
|
|
114
119
|
# @param enum [Array<Boolean>] optional - the possible values of the property
|
|
120
|
+
# @param nullable [Boolean] optional - if the property may be null
|
|
115
121
|
#
|
|
116
122
|
# @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:)
|
|
123
|
+
def self.boolean(title: nil, description: nil, enum: nil, nullable: nil)
|
|
124
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::BOOLEAN, title:, description:, enum:, nullable:)
|
|
119
125
|
end
|
|
120
126
|
|
|
121
127
|
# @example
|
|
122
128
|
# OmniAI::Schema.integer(description: "The age of the person") #=> OmniAI::Schema::Scalar
|
|
123
129
|
#
|
|
130
|
+
# @param title [String] optional - the title of the property
|
|
124
131
|
# @param description [String] optional - a description of the property
|
|
125
|
-
# @param enum [Array<Integer>]
|
|
132
|
+
# @param enum [Array<Integer>] optional - the possible values of the property
|
|
133
|
+
# @param nullable [Boolean] optional - if the property may be null
|
|
126
134
|
#
|
|
127
135
|
# @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:)
|
|
136
|
+
def self.integer(title: nil, description: nil, enum: nil, nullable: nil)
|
|
137
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::INTEGER, title:, description:, enum:, nullable:)
|
|
130
138
|
end
|
|
131
139
|
|
|
132
140
|
# @example
|
|
133
141
|
# OmniAI::Schema.string(description: "The name of the person.") #=> OmniAI::Schema::Scalar
|
|
134
142
|
#
|
|
143
|
+
# @param title [String] optional - the title of the property
|
|
135
144
|
# @param description [String] optional - a description of the property
|
|
136
145
|
# @param enum [Array<String>] optional - the possible values of the property
|
|
146
|
+
# @param nullable [Boolean] optional - if the property may be null
|
|
137
147
|
#
|
|
138
148
|
# @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:)
|
|
149
|
+
def self.string(title: nil, description: nil, enum: nil, nullable: nil)
|
|
150
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::STRING, title:, description:, enum:, nullable:)
|
|
141
151
|
end
|
|
142
152
|
|
|
143
153
|
# @example
|
|
144
154
|
# OmniAI::Schema.number(description: "The current temperature.") #=> OmniAI::Schema::Scalar
|
|
145
155
|
#
|
|
156
|
+
# @param title [String] optional - the title of the property
|
|
146
157
|
# @param description [String] optional - a description of the property
|
|
147
158
|
# @param enum [Array<Number>] optional - the possible values of the property
|
|
159
|
+
# @param nullable [Boolean] optional - if the property may be null
|
|
148
160
|
#
|
|
149
161
|
# @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:)
|
|
162
|
+
def self.number(title: nil, description: nil, enum: nil, nullable: nil)
|
|
163
|
+
OmniAI::Schema::Scalar.new(type: OmniAI::Schema::Scalar::Type::NUMBER, title:, description:, enum:, nullable:)
|
|
152
164
|
end
|
|
153
165
|
|
|
154
166
|
# @example
|
|
@@ -156,6 +168,7 @@ module OmniAI
|
|
|
156
168
|
#
|
|
157
169
|
# @param name [String] required
|
|
158
170
|
# @param schema [OmniAI::Schema::Object] required
|
|
171
|
+
# @param nullable [Boolean] optional
|
|
159
172
|
#
|
|
160
173
|
# @return [OmniAI::Schema::Format]
|
|
161
174
|
def self.format(name:, schema:)
|
data/lib/omniai/version.rb
CHANGED
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: 3.1.
|
|
4
|
+
version: 3.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kevin Sylvestre
|
|
@@ -139,6 +139,7 @@ files:
|
|
|
139
139
|
- lib/omniai/parse_error.rb
|
|
140
140
|
- lib/omniai/schema.rb
|
|
141
141
|
- lib/omniai/schema/array.rb
|
|
142
|
+
- lib/omniai/schema/base.rb
|
|
142
143
|
- lib/omniai/schema/format.rb
|
|
143
144
|
- lib/omniai/schema/object.rb
|
|
144
145
|
- lib/omniai/schema/scalar.rb
|