ox-ai-workers 0.9.7 → 0.9.9
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/CHANGELOG.md +5 -0
- data/README.md +22 -0
- data/config/locales/en.oxaiworkers.tool.yml +6 -1
- data/config/locales/ru.oxaiworkers.tool.yml +5 -0
- data/lib/ox-ai-workers.rb +3 -1
- data/lib/oxaiworkers/tool/pipeline.rb +4 -2
- data/lib/oxaiworkers/tool/wolfram.rb +52 -0
- data/lib/oxaiworkers/tool_definition.rb +12 -8
- data/lib/oxaiworkers/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: 9fde2ab33d3d1b89a4b351ff58f6c9f4d85c9d667770d6d258e5ee8215655666
|
4
|
+
data.tar.gz: dbbd0c85cf70948b8c92342e3b57804bf0b62828a5276b29650e66a79ac34742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b1b2e7494c478266ba2044db4545006a28d2d7be61eeb62309b40eb360f8b5eed41672657c0e5b87c5efb0d2424572b5618df128b093f1e58b4eee9e49ea29
|
7
|
+
data.tar.gz: '00697510a6c17ce5a98b9460b4446fece185a5f618286e18c7ae28907d3c7ddaa17a480648342dd947a73373bb61a7fa34353b967e22449f8acd7812e4ead33e'
|
data/CHANGELOG.md
CHANGED
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:
|
@@ -567,6 +569,26 @@ OxAiWorkers provides several specialized tools to extend functionality:
|
|
567
569
|
|
568
570
|
Provides functions for generating images with customizable parameters like size and quality, with ability to save generated images to disk.
|
569
571
|
|
572
|
+
- **Wolfram**: Query the Wolfram Alpha computational knowledge engine
|
573
|
+
|
574
|
+
```ruby
|
575
|
+
`gem "wolfram-alpha", github: "neonix20b/wolfram-alpha"`
|
576
|
+
```
|
577
|
+
|
578
|
+
```ruby
|
579
|
+
OxAiWorkers.configuration.access_token_wolfram = 'YOUR_WOLFRAM_API_KEY'
|
580
|
+
```
|
581
|
+
|
582
|
+
```ruby
|
583
|
+
# Initialize with optional parameters
|
584
|
+
wolfram = OxAiWorkers::Tool::Wolfram.new(
|
585
|
+
access_token: 'YOUR_WOLFRAM_API_KEY', # Optional: API key
|
586
|
+
location: 'Berlin' # Optional: Location to use for the query
|
587
|
+
)
|
588
|
+
```
|
589
|
+
|
590
|
+
This tool enables access to Wolfram Alpha's vast computational intelligence for performing complex mathematical calculations, solving equations, accessing scientific data, and answering knowledge-based queries with precise, authoritative results.
|
591
|
+
|
570
592
|
- **Pipeline**: Assistant coordination and communication tool
|
571
593
|
|
572
594
|
```ruby
|
@@ -44,4 +44,9 @@ en:
|
|
44
44
|
prompt: 'Text description of the image to generate on **English language**'
|
45
45
|
size: 'Size of the generated image'
|
46
46
|
quality: 'Quality of the generated image'
|
47
|
-
file_name: 'File name for saving the generated image in png format. For example: image.png'
|
47
|
+
file_name: 'File name for saving the generated image in png format. For example: image.png'
|
48
|
+
wolfram_alpha:
|
49
|
+
ask:
|
50
|
+
description: 'Wolfram Alpha Tool: Query the Wolfram Alpha computational knowledge engine'
|
51
|
+
prompt: 'The query to send to Wolfram Alpha'
|
52
|
+
location: 'Location information to provide context for the query'
|
@@ -49,3 +49,8 @@ ru:
|
|
49
49
|
description: 'Инструмент редактирования изображений: Редактирует изображение на основе предоставленного текстового запроса.'
|
50
50
|
input_image: 'URL или путь к изображению для редактирования'
|
51
51
|
prompt: 'Текстовое описание действий для редактирования изображения'
|
52
|
+
wolfram_alpha:
|
53
|
+
ask:
|
54
|
+
description: 'Инструмент Wolfram Alpha: Запрос к вычислительной базе знаний Wolfram Alpha'
|
55
|
+
prompt: 'Запрос для отправки в Wolfram Alpha'
|
56
|
+
location: 'Информация о местоположении для контекста запроса'
|
data/lib/ox-ai-workers.rb
CHANGED
@@ -28,6 +28,7 @@ require_relative 'oxaiworkers/tool/database'
|
|
28
28
|
require_relative 'oxaiworkers/tool/file_system'
|
29
29
|
require_relative 'oxaiworkers/tool/pipeline'
|
30
30
|
require_relative 'oxaiworkers/tool/pixels'
|
31
|
+
require_relative 'oxaiworkers/tool/wolfram'
|
31
32
|
|
32
33
|
require_relative 'oxaiworkers/assistant/module_base'
|
33
34
|
require_relative 'oxaiworkers/assistant/sysop'
|
@@ -58,7 +59,7 @@ module OxAiWorkers
|
|
58
59
|
|
59
60
|
class Configuration
|
60
61
|
attr_accessor :max_tokens, :temperature, :wait_for_complete, :access_token_deepseek, :access_token_openai,
|
61
|
-
:access_token_stability
|
62
|
+
:access_token_stability, :access_token_wolfram
|
62
63
|
|
63
64
|
def initialize
|
64
65
|
@max_tokens = DEFAULT_MAX_TOKEN
|
@@ -68,6 +69,7 @@ module OxAiWorkers
|
|
68
69
|
@access_token_deepseek = nil
|
69
70
|
@access_token_openai = nil
|
70
71
|
@access_token_stability = nil
|
72
|
+
@access_token_wolfram = nil
|
71
73
|
|
72
74
|
[Array, NilClass, String, Symbol, Hash].each do |c|
|
73
75
|
c.send(:include, OxAiWorkers::PresentCompat) unless c.method_defined?(:present?)
|
@@ -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
|
-
|
37
|
-
|
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
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module OxAiWorkers
|
5
|
+
module Tool
|
6
|
+
class Wolfram
|
7
|
+
include OxAiWorkers::ToolDefinition
|
8
|
+
include OxAiWorkers::DependencyHelper
|
9
|
+
include OxAiWorkers::LoadI18n
|
10
|
+
|
11
|
+
attr_accessor :access_token, :location
|
12
|
+
|
13
|
+
def initialize(only: nil, access_token: nil, location: nil)
|
14
|
+
store_locale
|
15
|
+
|
16
|
+
init_white_list_with only
|
17
|
+
|
18
|
+
define_function :ask, description: I18n.t('oxaiworkers.tool.wolfram_alpha.ask.description') do
|
19
|
+
property :prompt, type: 'string', description: I18n.t('oxaiworkers.tool.wolfram_alpha.ask.prompt'),
|
20
|
+
required: true
|
21
|
+
if location.nil?
|
22
|
+
property :location, type: 'string', description: I18n.t('oxaiworkers.tool.wolfram_alpha.ask.location'),
|
23
|
+
required: true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
@access_token = access_token
|
28
|
+
@location = location
|
29
|
+
end
|
30
|
+
|
31
|
+
def ask(prompt:, location: nil)
|
32
|
+
location ||= @location
|
33
|
+
options = { location: }
|
34
|
+
api_key = @access_token || OxAiWorkers.configuration.access_token_wolfram
|
35
|
+
@wolfram ||= WolframAlpha::Client.new api_key, options.compact
|
36
|
+
response = @wolfram.query prompt
|
37
|
+
input = response['Input'] # Get the input interpretation pod.
|
38
|
+
result = ''
|
39
|
+
result = "Input interpretation:\n#{input.subpods.map(&:plaintext).join("\n")}\n\n" unless input.nil?
|
40
|
+
result += response.pods.map { |p| [p.title, p.subpods.map(&:plaintext).join("\n")].join(":\n") }.join("\n\n")
|
41
|
+
images = []
|
42
|
+
%w[Plots Result Image].each do |title|
|
43
|
+
plot = response.find { |pod| pod.title == title }
|
44
|
+
images += plot.subpods.map { |img| img&.image } unless plot.nil?
|
45
|
+
end
|
46
|
+
images = images.compact.filter { |i| i[:type] != 'Default' }.uniq
|
47
|
+
result += "\n\n" + images.map { |img| "![#{img[:alt]}](\"#{img[:src]}\")" }.join("\n") unless images.empty?
|
48
|
+
result
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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:
|
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
|
data/lib/oxaiworkers/version.rb
CHANGED
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.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
@@ -177,6 +177,7 @@ files:
|
|
177
177
|
- lib/oxaiworkers/tool/file_system.rb
|
178
178
|
- lib/oxaiworkers/tool/pipeline.rb
|
179
179
|
- lib/oxaiworkers/tool/pixels.rb
|
180
|
+
- lib/oxaiworkers/tool/wolfram.rb
|
180
181
|
- lib/oxaiworkers/tool_definition.rb
|
181
182
|
- lib/oxaiworkers/version.rb
|
182
183
|
- lib/ruby/ox-ai-workers.rb
|