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.
@@ -1,151 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OmniAI
4
- class Tool
5
- # A property used for a tool parameter.
6
- #
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: '...')
14
- class Property
15
- module Type
16
- BOOLEAN = "boolean"
17
- INTEGER = "integer"
18
- STRING = "string"
19
- NUMBER = "number"
20
- end
21
-
22
- # @return [String]
23
- attr_reader :type
24
-
25
- # @return [String, nil]
26
- attr_reader :description
27
-
28
- # @return [Array<String>, nil]
29
- attr_reader :enum
30
-
31
- # @param kind [Symbol]
32
- # @return [OmniAI::Tool::Property]
33
- def self.build(kind, **args)
34
- case kind
35
- when :array then array(**args)
36
- when :object then object(**args)
37
- when :boolean then boolean(**args)
38
- when :integer then integer(**args)
39
- when :string then string(**args)
40
- when :number then number(**args)
41
- end
42
- end
43
-
44
- # @example
45
- # property = OmniAI::Tool::Property.array(
46
- # items: OmniAI::Tool::Property.string(description: 'The name of the person.'),
47
- # description: 'A list of names.'
48
- # min_items: 1,
49
- # max_items: 5,
50
- # )
51
- #
52
- # @param items [OmniAI::Tool::Property] required - the items in the array
53
- # @param min_items [Integer] optional - the minimum number of items
54
- # @param max_items [Integer] optional - the maximum number of items
55
- # @param description [String] optional - a description of the array
56
- #
57
- # @return [OmniAI::Tool::Array]
58
- def self.array(items:, min_items: nil, max_items: nil, description: nil)
59
- OmniAI::Tool::Array.new(items:, description:, min_items:, max_items:)
60
- end
61
-
62
- # @example
63
- # property = OmniAI::Tool::Property.object(
64
- # properties: {
65
- # name: OmniAI::Tool::Property.string(description: 'The name of the person.'),
66
- # age: OmniAI::Tool::Property.integer(description: 'The age of the person.'),
67
- # employed: OmniAI::Tool::Property.boolean(description: 'Is the person employed?'),
68
- # },
69
- # description: 'A person.'
70
- # required: %i[name]
71
- # )
72
- #
73
- # @param properties [Hash<String, OmniAI::Tool::Property>] required - the properties of the object
74
- # @param required [Array<Symbol>] optional - the required properties
75
- # @param description [String] optional - a description of the object
76
- #
77
- # @return [OmniAI::Tool::Array]
78
- def self.object(properties: {}, required: [], description: nil)
79
- OmniAI::Tool::Object.new(properties:, required:, description:)
80
- end
81
-
82
- # @param description [String] optional - a description of the property
83
- # @param enum [Array<Boolean>] optional - the possible values of the property
84
- #
85
- # @return [OmniAI::Tool::Property]
86
- def self.boolean(description: nil, enum: nil)
87
- new(type: Type::BOOLEAN, description:, enum:)
88
- end
89
-
90
- # @param description [String] optional - a description of the property
91
- # @param enum [Array<Integer>] optinoal - the possible values of the property
92
- #
93
- # @return [OmniAI::Tool::Property]
94
- def self.integer(description: nil, enum: nil)
95
- new(type: Type::INTEGER, description:, enum:)
96
- end
97
-
98
- # @param description [String] optional - a description of the property
99
- # @param enum [Array<String>] optional - the possible values of the property
100
- #
101
- # @return [OmniAI::Tool::Property]
102
- def self.string(description: nil, enum: nil)
103
- new(type: Type::STRING, description:, enum:)
104
- end
105
-
106
- # @param description [String] optional - a description of the property
107
- # @param enum [Array<Number>] optional - the possible values of the property
108
- #
109
- # @return [OmniAI::Tool::Property]
110
- def self.number(description: nil, enum: nil)
111
- new(type: Type::NUMBER, description:, enum:)
112
- end
113
-
114
- # @param type [String] required - the type of the property
115
- # @param description [String] optional - a description of the property
116
- # @param enum [Array] optional - the possible values of the property
117
- #
118
- # @return [OmniAI::Tool::Property]
119
- def initialize(type:, description: nil, enum: nil)
120
- @type = type
121
- @description = description
122
- @enum = enum
123
- end
124
-
125
- # @example
126
- # property.serialize #=> { type: 'string' }
127
- #
128
- # @return [Hash]
129
- def serialize
130
- {
131
- type: @type,
132
- description: @description,
133
- enum: @enum,
134
- }.compact
135
- end
136
-
137
- # @example
138
- # property.parse('123') #=> 123
139
- #
140
- # @return [String, Integer, Float, Boolean, Object]
141
- def parse(value)
142
- case @type
143
- when Type::INTEGER then Integer(value)
144
- when Type::STRING then String(value)
145
- when Type::NUMBER then Float(value)
146
- else value
147
- end
148
- end
149
- end
150
- end
151
- end