ox-ai-workers 0.5.7 → 0.6.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/.ruby-version +1 -0
- data/CHANGELOG.md +9 -0
- data/README.md +3 -2
- data/lib/ox-ai-workers.rb +4 -1
- data/lib/oxaiworkers/delayed_request.rb +1 -1
- data/lib/oxaiworkers/engine.rb +11 -0
- data/lib/oxaiworkers/iterator.rb +28 -5
- data/lib/oxaiworkers/load_i18n.rb +4 -2
- data/lib/oxaiworkers/state_batch.rb +2 -2
- data/lib/oxaiworkers/state_tools.rb +2 -2
- data/lib/oxaiworkers/tool_definition.rb +178 -159
- data/lib/oxaiworkers/version.rb +1 -1
- metadata +15 -13
- /data/{locales/en.assistant.yml → config/locales/en.oxaiworkers.assistant.yml} +0 -0
- /data/{locales/en.iterator.yml → config/locales/en.oxaiworkers.iterator.yml} +0 -0
- /data/{locales/en.tool.yml → config/locales/en.oxaiworkers.tool.yml} +0 -0
- /data/{locales/ru.assistant.yml → config/locales/ru.oxaiworkers.assistant.yml} +0 -0
- /data/{locales/ru.iterator.yml → config/locales/ru.oxaiworkers.iterator.yml} +0 -0
- /data/{locales/ru.tool.yml → config/locales/ru.oxaiworkers.tool.yml} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173694a4b29ea7a2c690add1cdbf322d62b005427c1310f5ea6dde2dea0a8c81
|
4
|
+
data.tar.gz: 1687d91cffe2ca48a50a4b5669ab3bcf2874a2e8b649d668a7ee6a3806e3eb8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a162f9ef5c72938e502cd5c491a018643d75f833aad9a767388d222e440526b33d85aac263d9db4ab3448429ce97e16fba90bf1a70358c672ac4fe4c1b74b22d
|
7
|
+
data.tar.gz: 8c807fdaac63f3c75cfe770b966ac3e1f6e537a7a4942d253ee2385b449ce0c37205ecd98e07c68e8aa4a0b1a2b3dd86c53a2355d2378b3e6e6e21b0b9d83f8a
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.4
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.0] - 2024-08-02
|
4
|
+
|
5
|
+
- Added rails compatibility
|
6
|
+
- Added `wait_for_complete` option
|
7
|
+
|
8
|
+
## [0.5.8] - 2024-08-02
|
9
|
+
|
10
|
+
- Fixed gem `state_machines`
|
11
|
+
|
3
12
|
## [0.5.7] - 2024-08-02
|
4
13
|
|
5
14
|
- Added monkey patch for `full_function_name`
|
data/README.md
CHANGED
@@ -86,9 +86,10 @@ For a more robust setup, you can configure the gem with your API keys, for examp
|
|
86
86
|
OxAiWorkers.configure do |config|
|
87
87
|
config.access_token = ENV.fetch("OPENAI")
|
88
88
|
config.model = "gpt-4o"
|
89
|
-
config.max_tokens = 4096
|
90
|
-
config.temperature = 0.7
|
89
|
+
config.max_tokens = 4096 # Default
|
90
|
+
config.temperature = 0.7 # Default
|
91
91
|
config.auto_execute = true # Default
|
92
|
+
config.wait_for_complete = true # Default
|
92
93
|
end
|
93
94
|
```
|
94
95
|
|
data/lib/ox-ai-workers.rb
CHANGED
@@ -31,6 +31,8 @@ require_relative 'oxaiworkers/assistant/sysop'
|
|
31
31
|
require_relative 'oxaiworkers/assistant/coder'
|
32
32
|
require_relative 'oxaiworkers/assistant/localizer'
|
33
33
|
|
34
|
+
require_relative 'oxaiworkers/engine' if defined?(Rails)
|
35
|
+
|
34
36
|
module OxAiWorkers
|
35
37
|
DEFAULT_MODEL = 'gpt-4o-mini'
|
36
38
|
DEFAULT_MAX_TOKEN = 4096
|
@@ -40,7 +42,7 @@ module OxAiWorkers
|
|
40
42
|
class ConfigurationError < Error; end
|
41
43
|
|
42
44
|
class Configuration
|
43
|
-
attr_accessor :model, :max_tokens, :temperature, :access_token, :auto_execute
|
45
|
+
attr_accessor :model, :max_tokens, :temperature, :access_token, :auto_execute, :wait_for_complete
|
44
46
|
|
45
47
|
def initialize
|
46
48
|
@access_token = nil
|
@@ -48,6 +50,7 @@ module OxAiWorkers
|
|
48
50
|
@max_tokens = DEFAULT_MAX_TOKEN
|
49
51
|
@temperature = DEFAULT_TEMPERATURE
|
50
52
|
@auto_execute = true
|
53
|
+
@wait_for_complete = true
|
51
54
|
|
52
55
|
[Array, NilClass, String, Symbol, Hash].each do |c|
|
53
56
|
c.send(:include, OxAiWorkers::PresentCompat) unless c.method_defined?(:present?)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module OxAiWorkers
|
4
4
|
class DelayedRequest < OxAiWorkers::StateBatch
|
5
5
|
def initialize(batch_id: nil, model: nil, max_tokens: nil, temperature: nil)
|
6
|
-
initialize_requests(model
|
6
|
+
initialize_requests(model:, max_tokens:, temperature:)
|
7
7
|
@custom_id = nil if batch_id.present?
|
8
8
|
@batch_id = batch_id
|
9
9
|
@file_id = nil
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module OxAiWorkers
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace OxAiWorkers # this is generally recommended
|
4
|
+
|
5
|
+
# no other special configuration needed. But maybe you want
|
6
|
+
# an initializer to be added to the app? Easy!
|
7
|
+
# initializer 'yourgem.boot_stuff_up' do
|
8
|
+
# OxAiWorkers.boot_something_up!
|
9
|
+
# end
|
10
|
+
end
|
11
|
+
end
|
data/lib/oxaiworkers/iterator.rb
CHANGED
@@ -54,6 +54,11 @@ module OxAiWorkers
|
|
54
54
|
super()
|
55
55
|
end
|
56
56
|
|
57
|
+
#
|
58
|
+
# Resets the state of the object by setting all instance variables to their initial values.
|
59
|
+
#
|
60
|
+
# Returns nothing.
|
61
|
+
#
|
57
62
|
def cleanup
|
58
63
|
@result = nil
|
59
64
|
@queue = []
|
@@ -63,6 +68,11 @@ module OxAiWorkers
|
|
63
68
|
complete_iteration
|
64
69
|
end
|
65
70
|
|
71
|
+
# Updates the internal state of the iterator by adding the given `speach` to the `@queue` and calling the `@on_inner_monologue` callback with the `speach` text.
|
72
|
+
#
|
73
|
+
# @param speach [String] The text to be added to the `@queue` and passed to the `@on_inner_monologue` callback.
|
74
|
+
#
|
75
|
+
# @return [nil] This method does not return a value.
|
66
76
|
def inner_monologue(speach:)
|
67
77
|
# @queue.pop
|
68
78
|
@queue << { role: :assistant, content: speach.to_s }
|
@@ -74,7 +84,7 @@ module OxAiWorkers
|
|
74
84
|
# @queue.pop
|
75
85
|
@queue << { role: :assistant, content: text.to_s }
|
76
86
|
complete! unless available_defs.include?(:action_request)
|
77
|
-
@on_outer_voice&.call(text:
|
87
|
+
@on_outer_voice&.call(text:)
|
78
88
|
nil
|
79
89
|
end
|
80
90
|
|
@@ -96,7 +106,7 @@ module OxAiWorkers
|
|
96
106
|
@worker.finish
|
97
107
|
rebuild_worker
|
98
108
|
complete! if can_complete?
|
99
|
-
@on_summarize&.call(text:
|
109
|
+
@on_summarize&.call(text:)
|
100
110
|
nil
|
101
111
|
end
|
102
112
|
|
@@ -158,11 +168,24 @@ module OxAiWorkers
|
|
158
168
|
|
159
169
|
def external_request
|
160
170
|
@worker.request!
|
161
|
-
|
171
|
+
if OxAiWorkers.configuration.wait_for_complete
|
172
|
+
wait_for_complete
|
173
|
+
else
|
174
|
+
ticker
|
175
|
+
end
|
162
176
|
end
|
163
177
|
|
164
178
|
def ticker
|
165
|
-
|
179
|
+
return false unless @worker.completed?
|
180
|
+
|
181
|
+
analyze!
|
182
|
+
true
|
183
|
+
end
|
184
|
+
|
185
|
+
def wait_for_complete
|
186
|
+
return unless requested?
|
187
|
+
|
188
|
+
sleep(60) unless ticker
|
166
189
|
analyze!
|
167
190
|
end
|
168
191
|
|
@@ -199,7 +222,7 @@ module OxAiWorkers
|
|
199
222
|
end
|
200
223
|
|
201
224
|
def add_context(text, role: :system)
|
202
|
-
@context << { role
|
225
|
+
@context << { role:, content: text }
|
203
226
|
end
|
204
227
|
|
205
228
|
def execute
|
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
unless defined?(Rails)
|
4
|
+
require 'i18n'
|
5
|
+
I18n.load_path += Dir["#{File.expand_path('../../config/locales', __dir__)}/*.yml"]
|
6
|
+
end
|
5
7
|
|
6
8
|
module OxAiWorkers
|
7
9
|
module LoadI18n
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'state_machines/core'
|
4
4
|
|
5
5
|
module OxAiWorkers
|
6
6
|
class StateBatch < OxAiWorkers::ModuleRequest
|
7
7
|
include OxAiWorkers::StateHelper
|
8
|
-
extend
|
8
|
+
extend StateMachines::MacroMethods
|
9
9
|
|
10
10
|
alias state_initialize initialize
|
11
11
|
attr_accessor :file_id, :batch_id
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'state_machines/core'
|
4
4
|
|
5
5
|
module OxAiWorkers
|
6
6
|
class StateTools
|
7
7
|
include OxAiWorkers::StateHelper
|
8
|
-
extend
|
8
|
+
extend StateMachines::MacroMethods
|
9
9
|
|
10
10
|
state_machine :state, initial: :idle do
|
11
11
|
before_transition from: any, do: :log_me
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'json'
|
4
4
|
|
5
5
|
#
|
6
6
|
# Extends a class to be used as a tool in the assistant.
|
@@ -36,201 +36,220 @@ require "json"
|
|
36
36
|
# end
|
37
37
|
# end
|
38
38
|
#
|
39
|
-
module OxAiWorkers
|
40
|
-
|
39
|
+
module OxAiWorkers
|
40
|
+
module ToolDefinition
|
41
|
+
attr_accessor :white_list
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# @param method_name [Symbol] Name of the method to define
|
49
|
-
# @param description [String] Description of the function
|
50
|
-
# @yield Block that defines the parameters for the function
|
51
|
-
def define_function(method_name, description:, &)
|
52
|
-
if @white_list.nil? || @white_list == method_name || @white_list.include?(method_name)
|
53
|
-
function_schemas.add_function(method_name:, description:, &)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Returns the FunctionSchemas instance for this tool
|
58
|
-
#
|
59
|
-
# @return [FunctionSchemas] The FunctionSchemas instance
|
60
|
-
def function_schemas
|
61
|
-
@function_schemas ||= FunctionSchemas.new(tool_name)
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns the snake_case version of the class name as the tool's name
|
65
|
-
#
|
66
|
-
# @return [String] The snake_case version of the class name
|
67
|
-
def tool_name
|
68
|
-
@tool_name ||= (self.respond_to?(:name) ? name : self.class.name)
|
69
|
-
.gsub("::", "_")
|
70
|
-
.gsub(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, "_")
|
71
|
-
.downcase
|
72
|
-
end
|
73
|
-
|
74
|
-
def full_function_name(fun)
|
75
|
-
function_schemas.function_name(fun)
|
76
|
-
end
|
77
|
-
|
78
|
-
# Manages schemas for functions
|
79
|
-
class FunctionSchemas
|
80
|
-
def initialize(tool_name)
|
81
|
-
@schemas = {}
|
82
|
-
@tool_name = tool_name
|
83
|
-
end
|
84
|
-
|
85
|
-
def function_name method_name
|
86
|
-
"#{@tool_name}__#{method_name}"
|
43
|
+
# Initializes the white list with the given `only` parameter.
|
44
|
+
#
|
45
|
+
# @param only [Object, Array] The object or array to initialize the white list with.
|
46
|
+
# @return [Array] The initialized white list.
|
47
|
+
def init_white_list_with(only)
|
48
|
+
@white_list = only.is_a?(Array) ? only : [only]
|
87
49
|
end
|
88
50
|
|
89
|
-
#
|
51
|
+
# Defines a function for the tool
|
90
52
|
#
|
91
|
-
# @param method_name [Symbol] Name of the method to
|
53
|
+
# @param method_name [Symbol] Name of the method to define
|
92
54
|
# @param description [String] Description of the function
|
93
55
|
# @yield Block that defines the parameters for the function
|
94
|
-
|
95
|
-
|
96
|
-
name = function_name(method_name)
|
56
|
+
def define_function(method_name, description:, &)
|
57
|
+
return unless @white_list.nil? || @white_list == method_name || @white_list.include?(method_name)
|
97
58
|
|
98
|
-
|
99
|
-
|
59
|
+
function_schemas.add_function(method_name:, description:, &)
|
60
|
+
end
|
100
61
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
62
|
+
# Returns the FunctionSchemas instance for this tool
|
63
|
+
#
|
64
|
+
# @return [FunctionSchemas] The FunctionSchemas instance
|
65
|
+
def function_schemas
|
66
|
+
@function_schemas ||= FunctionSchemas.new(tool_name)
|
67
|
+
end
|
105
68
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
69
|
+
# Returns the snake_case version of the class name as the tool's name
|
70
|
+
#
|
71
|
+
# @return [String] The snake_case version of the class name
|
72
|
+
def tool_name
|
73
|
+
@tool_name ||= (respond_to?(:name) ? name : self.class.name)
|
74
|
+
.gsub('::', '_')
|
75
|
+
.gsub(/(?<=[A-Z])(?=[A-Z][a-z])|(?<=[a-z\d])(?=[A-Z])/, '_')
|
76
|
+
.downcase
|
110
77
|
end
|
111
78
|
|
112
|
-
#
|
79
|
+
# Returns the full function name for the given function.
|
113
80
|
#
|
114
|
-
# @
|
115
|
-
|
116
|
-
|
81
|
+
# @param fun [Symbol] The function name.
|
82
|
+
# @return [String] The full function name, which is the tool name concatenated with the function name.
|
83
|
+
def full_function_name(fun)
|
84
|
+
function_schemas.function_name(fun)
|
117
85
|
end
|
118
86
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
@
|
87
|
+
# Manages schemas for functions
|
88
|
+
class FunctionSchemas
|
89
|
+
def initialize(tool_name)
|
90
|
+
@schemas = {}
|
91
|
+
@tool_name = tool_name
|
124
92
|
end
|
125
|
-
end
|
126
93
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
94
|
+
# Returns the full function name for the given method name.
|
95
|
+
#
|
96
|
+
# @param method_name [Symbol] The name of the method.
|
97
|
+
# @return [String] The full function name, which is the tool name concatenated with the method name.
|
98
|
+
def function_name(method_name)
|
99
|
+
"#{@tool_name}__#{method_name}"
|
133
100
|
end
|
134
|
-
end
|
135
101
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
102
|
+
# Adds a function to the schemas
|
103
|
+
#
|
104
|
+
# @param method_name [Symbol] Name of the method to add
|
105
|
+
# @param description [String] Description of the function
|
106
|
+
# @yield Block that defines the parameters for the function
|
107
|
+
# @raise [ArgumentError] If a block is defined and no parameters are specified for the function
|
108
|
+
def add_function(method_name:, description:, &)
|
109
|
+
name = function_name(method_name)
|
110
|
+
|
111
|
+
if block_given?
|
112
|
+
parameters = ParameterBuilder.new(parent_type: 'object').build(&)
|
113
|
+
|
114
|
+
if parameters[:properties].empty?
|
115
|
+
raise ArgumentError,
|
116
|
+
'Function parameters must have at least one property defined within it, if a block is provided'
|
117
|
+
end
|
118
|
+
end
|
143
119
|
|
144
|
-
|
145
|
-
|
146
|
-
|
120
|
+
@schemas[method_name] = {
|
121
|
+
type: 'function',
|
122
|
+
function: { name:, description:, parameters: }.compact
|
123
|
+
}
|
124
|
+
end
|
147
125
|
|
148
|
-
|
149
|
-
|
150
|
-
@
|
151
|
-
|
126
|
+
# Converts schemas to OpenAI-compatible format
|
127
|
+
#
|
128
|
+
# @return [String] JSON string of schemas in OpenAI format
|
129
|
+
def to_openai_format(only: nil)
|
130
|
+
valid_schemas(only:).values
|
131
|
+
end
|
152
132
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
133
|
+
# Returns a subset of schemas based on the provided filter.
|
134
|
+
#
|
135
|
+
# @param only [Array<Symbol>] An optional array of schema names to filter by.
|
136
|
+
# @return [Hash<Symbol, Hash>] A hash of schemas with their corresponding names as keys.
|
137
|
+
def valid_schemas(only: nil)
|
138
|
+
if only.nil?
|
139
|
+
@schemas
|
140
|
+
else
|
141
|
+
@schemas.select { |name, _schema| only.include?(name) }
|
142
|
+
end
|
143
|
+
end
|
161
144
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
# @param required [Boolean] Whether the property is required
|
169
|
-
# @yield [Block] Block for nested properties (only for object and array types)
|
170
|
-
# @raise [ArgumentError] If any parameter is invalid
|
171
|
-
def property(name = nil, type:, description: nil, enum: nil, required: false, &)
|
172
|
-
validate_parameters(name:, type:, enum:, required:)
|
173
|
-
|
174
|
-
prop = {type:, description:, enum:}.compact
|
175
|
-
|
176
|
-
if block_given?
|
177
|
-
nested_schema = ParameterBuilder.new(parent_type: type).build(&)
|
178
|
-
|
179
|
-
case type
|
180
|
-
when "object"
|
181
|
-
if nested_schema[:properties].empty?
|
182
|
-
raise ArgumentError, "Object properties must have at least one property defined within it"
|
183
|
-
end
|
184
|
-
prop = nested_schema
|
185
|
-
when "array"
|
186
|
-
if nested_schema.empty?
|
187
|
-
raise ArgumentError, "Array properties must have at least one item defined within it"
|
188
|
-
end
|
189
|
-
prop[:items] = nested_schema
|
145
|
+
# Converts schemas to Anthropic-compatible format
|
146
|
+
#
|
147
|
+
# @return [String] JSON string of schemas in Anthropic format
|
148
|
+
def to_anthropic_format(only: nil)
|
149
|
+
valid_schemas(only:).values.map do |schema|
|
150
|
+
schema[:function].transform_keys('parameters' => 'input_schema')
|
190
151
|
end
|
191
152
|
end
|
192
153
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
154
|
+
# Converts schemas to Google Gemini-compatible format
|
155
|
+
#
|
156
|
+
# @return [String] JSON string of schemas in Google Gemini format
|
157
|
+
def to_google_gemini_format(only: nil)
|
158
|
+
valid_schemas(only:).values.map { |schema| schema[:function] }
|
198
159
|
end
|
199
160
|
end
|
200
161
|
|
201
|
-
#
|
202
|
-
|
162
|
+
# Builds parameter schemas for functions
|
163
|
+
class ParameterBuilder
|
164
|
+
VALID_TYPES = %w[object array string number integer boolean].freeze
|
203
165
|
|
204
|
-
|
166
|
+
def initialize(parent_type:)
|
167
|
+
@schema = parent_type == 'object' ? { type: 'object', properties: {}, required: [] } : {}
|
168
|
+
@parent_type = parent_type
|
169
|
+
end
|
205
170
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
171
|
+
# Builds the parameter schema
|
172
|
+
#
|
173
|
+
# @yield Block that defines the properties of the schema
|
174
|
+
# @return [Hash] The built schema
|
175
|
+
def build(&)
|
176
|
+
instance_eval(&)
|
177
|
+
@schema
|
178
|
+
end
|
179
|
+
|
180
|
+
# Defines a property in the schema
|
181
|
+
#
|
182
|
+
# @param name [Symbol] Name of the property (required only for a parent of type object)
|
183
|
+
# @param type [String] Type of the property
|
184
|
+
# @param description [String] Description of the property
|
185
|
+
# @param enum [Array] Array of allowed values
|
186
|
+
# @param required [Boolean] Whether the property is required
|
187
|
+
# @yield [Block] Block for nested properties (only for object and array types)
|
188
|
+
# @raise [ArgumentError] If any parameter is invalid
|
189
|
+
def property(name = nil, type:, description: nil, enum: nil, required: false, &)
|
190
|
+
validate_parameters(name:, type:, enum:, required:)
|
191
|
+
|
192
|
+
prop = { type:, description:, enum: }.compact
|
193
|
+
|
194
|
+
if block_given?
|
195
|
+
nested_schema = ParameterBuilder.new(parent_type: type).build(&)
|
196
|
+
|
197
|
+
case type
|
198
|
+
when 'object'
|
199
|
+
if nested_schema[:properties].empty?
|
200
|
+
raise ArgumentError, 'Object properties must have at least one property defined within it'
|
201
|
+
end
|
202
|
+
|
203
|
+
prop = nested_schema
|
204
|
+
when 'array'
|
205
|
+
if nested_schema.empty?
|
206
|
+
raise ArgumentError,
|
207
|
+
'Array properties must have at least one item defined within it'
|
208
|
+
end
|
209
|
+
|
210
|
+
prop[:items] = nested_schema
|
211
|
+
end
|
217
212
|
end
|
218
|
-
|
219
|
-
|
213
|
+
|
214
|
+
if @parent_type == 'object'
|
215
|
+
@schema[:properties][name] = prop
|
216
|
+
@schema[:required] << name.to_s if required
|
217
|
+
else
|
218
|
+
@schema = prop
|
220
219
|
end
|
221
220
|
end
|
222
221
|
|
223
|
-
|
224
|
-
|
225
|
-
|
222
|
+
# Alias for property method, used for defining array items
|
223
|
+
alias item property
|
224
|
+
|
225
|
+
private
|
226
|
+
|
227
|
+
# Validates the parameters for a property
|
228
|
+
#
|
229
|
+
# @param name [Symbol] Name of the property
|
230
|
+
# @param type [String] Type of the property
|
231
|
+
# @param enum [Array] Array of allowed values
|
232
|
+
# @param required [Boolean] Whether the property is required
|
233
|
+
# @raise [ArgumentError] If any parameter is invalid
|
234
|
+
def validate_parameters(name:, type:, enum:, required:)
|
235
|
+
if @parent_type == 'object'
|
236
|
+
raise ArgumentError, 'Name must be provided for properties of an object' if name.nil?
|
237
|
+
raise ArgumentError, "Invalid name '#{name}'. Name must be a symbol" unless name.is_a?(Symbol)
|
238
|
+
end
|
226
239
|
|
227
|
-
|
228
|
-
|
229
|
-
|
240
|
+
unless VALID_TYPES.include?(type)
|
241
|
+
raise ArgumentError, "Invalid type '#{type}'. Valid types are: #{VALID_TYPES.join(', ')}"
|
242
|
+
end
|
243
|
+
|
244
|
+
unless enum.nil? || enum.is_a?(Array)
|
245
|
+
raise ArgumentError,
|
246
|
+
"Invalid enum '#{enum}'. Enum must be nil or an array"
|
247
|
+
end
|
248
|
+
|
249
|
+
return if [true, false].include?(required)
|
230
250
|
|
231
|
-
unless [true, false].include?(required)
|
232
251
|
raise ArgumentError, "Invalid required '#{required}'. Required must be a boolean"
|
233
252
|
end
|
234
253
|
end
|
235
254
|
end
|
236
|
-
end
|
255
|
+
end
|
data/lib/oxaiworkers/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox-ai-workers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -95,19 +95,19 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '7'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: state_machines
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0.6'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0.6'
|
111
111
|
description: |2
|
112
112
|
OxAiWorkers (ox-ai-workers) is a cutting-edge Ruby gem designed to seamlessly integrate
|
113
113
|
a sophisticated state machine with the powerful capabilities of generative intelligence
|
@@ -124,11 +124,18 @@ executables:
|
|
124
124
|
extensions: []
|
125
125
|
extra_rdoc_files: []
|
126
126
|
files:
|
127
|
+
- ".ruby-version"
|
127
128
|
- CHANGELOG.md
|
128
129
|
- CODE_OF_CONDUCT.md
|
129
130
|
- LICENSE
|
130
131
|
- README.md
|
131
132
|
- Rakefile
|
133
|
+
- config/locales/en.oxaiworkers.assistant.yml
|
134
|
+
- config/locales/en.oxaiworkers.iterator.yml
|
135
|
+
- config/locales/en.oxaiworkers.tool.yml
|
136
|
+
- config/locales/ru.oxaiworkers.assistant.yml
|
137
|
+
- config/locales/ru.oxaiworkers.iterator.yml
|
138
|
+
- config/locales/ru.oxaiworkers.tool.yml
|
132
139
|
- exe/oxaiworkers
|
133
140
|
- exe/start
|
134
141
|
- lib/ox-ai-workers.rb
|
@@ -140,6 +147,7 @@ files:
|
|
140
147
|
- lib/oxaiworkers/contextual_logger.rb
|
141
148
|
- lib/oxaiworkers/delayed_request.rb
|
142
149
|
- lib/oxaiworkers/dependency_helper.rb
|
150
|
+
- lib/oxaiworkers/engine.rb
|
143
151
|
- lib/oxaiworkers/iterator.rb
|
144
152
|
- lib/oxaiworkers/load_i18n.rb
|
145
153
|
- lib/oxaiworkers/module_request.rb
|
@@ -154,12 +162,6 @@ files:
|
|
154
162
|
- lib/oxaiworkers/tool_definition.rb
|
155
163
|
- lib/oxaiworkers/version.rb
|
156
164
|
- lib/ruby/ox-ai-workers.rb
|
157
|
-
- locales/en.assistant.yml
|
158
|
-
- locales/en.iterator.yml
|
159
|
-
- locales/en.tool.yml
|
160
|
-
- locales/ru.assistant.yml
|
161
|
-
- locales/ru.iterator.yml
|
162
|
-
- locales/ru.tool.yml
|
163
165
|
- template/my_assistant.rb
|
164
166
|
- template/start
|
165
167
|
- template/tools/my_tool.rb
|
@@ -178,14 +180,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
180
|
requirements:
|
179
181
|
- - ">="
|
180
182
|
- !ruby/object:Gem::Version
|
181
|
-
version: 2.
|
183
|
+
version: 3.2.0
|
182
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
185
|
requirements:
|
184
186
|
- - ">="
|
185
187
|
- !ruby/object:Gem::Version
|
186
188
|
version: '0'
|
187
189
|
requirements: []
|
188
|
-
rubygems_version: 3.5.
|
190
|
+
rubygems_version: 3.5.17
|
189
191
|
signing_key:
|
190
192
|
specification_version: 4
|
191
193
|
summary: A powerful state machine with OpenAI generative intelligence integration
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|