ox-ai-workers 0.9.7 → 0.9.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d07816453560dd2bdb34d054ae67f111291b09f587e743aeab80bd7143d5681b
4
- data.tar.gz: 43b0ca3a4866147b2f412e02c22e626964ff96d0968a5957b9ba132765370c3f
3
+ metadata.gz: cea51225b7b09bfd512c62960fc5e01f3bb6ed848e8efc6d72115ac6765ac254
4
+ data.tar.gz: 3f355bf99d4a5d3101c3d8b2f8e7f4859509489bb857c50b49d3efba15dc086f
5
5
  SHA512:
6
- metadata.gz: c24890557276fa3a358ff0f633a6dbbf01ce8aaf769abef008d8614755f41fae3b4c55d766b32be17c11e6976c93864ef1c95bea9dafd8b0fe456cfab0256d0e
7
- data.tar.gz: e6b08fa61b8b3c4a05c2a6d2b9c3f742d9c86a2865923b6448bb5fc659f561f8d499e0953a392567967fb1d3b28471c81245fd68e8cd63c920d86a407248121b
6
+ metadata.gz: b665b7c498647dc8c53fe9bd538f3db34c424fc2277b4226e08e66faa0fbc3f3df5cc8d9d8a65301cca94c0b30b0241140565675486a0f2e70be55cbaf43ceef
7
+ data.tar.gz: dcf0ef347b4e2017f69e09bc85bc99ffa785a4bf0d6ff565c292a0d8ee50fde675d49851766a25d9c473f67126d41185955365da303e4fe0272ad70e0b9a4b3c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ ## [0.9.8] - 2025-05-12
3
+
4
+ - Added `strict` parameter for `define_function`
5
+
2
6
  ## [0.9.6] - 2025-05-10
3
7
 
4
8
  - Added `add_file` for `Iterator` (only pdf for now)
data/README.md CHANGED
@@ -397,6 +397,8 @@ class MyTool
397
397
  end
398
398
  ```
399
399
 
400
+ The `define_function` method accepts an optional `strict` parameter (defaults to `true`) that controls whether additional properties are allowed in the input. When `strict: true` (default), the schema will include `additionalProperties: false`, enforcing that only defined properties can be used.
401
+
400
402
  ### Working with Files and Images
401
403
 
402
404
  You can easily add files and images to your assistants:
@@ -33,8 +33,10 @@ module OxAiWorkers
33
33
  context = context_for(to_id)
34
34
  @assistants[to_id].replace_context(context)
35
35
  @assistants[to_id].add_task message
36
- @assistants[to_id].add_task "#{I18n.t('oxaiworkers.tool.pipeline.send_message.result')}: #{result}"
37
- @assistants[to_id].add_task "#{I18n.t('oxaiworkers.tool.pipeline.send_message.example')}: #{example}"
36
+ with_locale do
37
+ @assistants[to_id].add_task "#{I18n.t('oxaiworkers.tool.pipeline.send_message.result')}: #{result}"
38
+ @assistants[to_id].add_task "#{I18n.t('oxaiworkers.tool.pipeline.send_message.example')}: #{example}"
39
+ end
38
40
  @assistants[to_id].execute
39
41
  nil
40
42
  end
@@ -53,10 +53,10 @@ module OxAiWorkers
53
53
  # @param method_name [Symbol] Name of the method to define
54
54
  # @param description [String] Description of the function
55
55
  # @yield Block that defines the parameters for the function
56
- def define_function(method_name, description:, &)
56
+ def define_function(method_name, description:, strict: true, &)
57
57
  return unless @white_list.nil? || @white_list == method_name || @white_list.include?(method_name)
58
58
 
59
- function_schemas.add_function(method_name:, description:, &)
59
+ function_schemas.add_function(method_name:, description:, strict:, &)
60
60
  end
61
61
 
62
62
  # Returns the FunctionSchemas instance for this tool
@@ -105,11 +105,11 @@ module OxAiWorkers
105
105
  # @param description [String] Description of the function
106
106
  # @yield Block that defines the parameters for the function
107
107
  # @raise [ArgumentError] If a block is defined and no parameters are specified for the function
108
- def add_function(method_name:, description:, &)
108
+ def add_function(method_name:, description:, strict:, &)
109
109
  name = function_name(method_name)
110
110
 
111
111
  if block_given?
112
- parameters = ParameterBuilder.new(parent_type: 'object').build(&)
112
+ parameters = ParameterBuilder.new(parent_type: 'object', strict:).build(&)
113
113
 
114
114
  if parameters[:properties].empty?
115
115
  raise ArgumentError,
@@ -117,9 +117,12 @@ module OxAiWorkers
117
117
  end
118
118
  end
119
119
 
120
+ function_params = { name:, description:, parameters: }
121
+ function_params[:strict] = true if strict
122
+
120
123
  @schemas[method_name] = {
121
124
  type: 'function',
122
- function: { name:, description:, parameters:, strict: !parameters.nil? }.compact
125
+ function: function_params.compact
123
126
  }
124
127
  end
125
128
 
@@ -163,9 +166,10 @@ module OxAiWorkers
163
166
  class ParameterBuilder
164
167
  VALID_TYPES = %w[object array string number integer boolean].freeze
165
168
 
166
- def initialize(parent_type:)
169
+ def initialize(parent_type:, strict: true)
167
170
  @schema = parent_type == 'object' ? { type: 'object', properties: {}, required: [] } : {}
168
171
  @parent_type = parent_type
172
+ @strict = strict
169
173
  end
170
174
 
171
175
  # Builds the parameter schema
@@ -192,7 +196,7 @@ module OxAiWorkers
192
196
  prop = { type:, description:, enum: }.compact
193
197
 
194
198
  if block_given?
195
- nested_schema = ParameterBuilder.new(parent_type: type).build(&)
199
+ nested_schema = ParameterBuilder.new(parent_type: type, strict: @strict).build(&)
196
200
 
197
201
  case type
198
202
  when 'object'
@@ -214,7 +218,7 @@ module OxAiWorkers
214
218
  if @parent_type == 'object'
215
219
  @schema[:properties][name] = prop
216
220
  @schema[:required] << name.to_s if required
217
- @schema[:additionalProperties] = false
221
+ @schema[:additionalProperties] = false if @strict
218
222
  else
219
223
  @schema = prop
220
224
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = '0.9.7'
4
+ VERSION = '0.9.8'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox-ai-workers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Smolev