ox-ai-workers 1.0.2 → 1.0.3
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 +6 -0
- data/README.md +3 -1
- data/lib/ox-ai-workers.rb +3 -1
- data/lib/oxaiworkers/iterator.rb +26 -5
- data/lib/oxaiworkers/models/anthropic_max.rb +14 -0
- data/lib/oxaiworkers/models/openai_whisper.rb +25 -0
- data/lib/oxaiworkers/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 838a2c53f4ce2423cd215d9cda21c76fe5870f709e528b3de491666b25b7b516
|
4
|
+
data.tar.gz: 7c55a9076dcbd3f4e21222a5b2300d1677e08fcdfe0d9ae0f186c88b0206585b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f642f834e477f074fffda948b505bcce54381369391e05f3ca54acb0943d87e3dc78ff050c2f9b8cb507ad2f3754fd86355dd0e32495e9bc00a04cea95d1b0d6
|
7
|
+
data.tar.gz: 55464fe188ebea0a2c73a07c1c91e381cec4d16faa24755b803c527671db6185b95fc022104db5670d2a79d65cc6ad7c28b5992655c5926a5da64d3ea3a9fd63
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -409,7 +409,9 @@ class MyTool
|
|
409
409
|
end
|
410
410
|
```
|
411
411
|
|
412
|
-
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.
|
412
|
+
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.
|
413
|
+
|
414
|
+
Tools can also implement a `context` method that returns information to be included in assistant conversations before each request, which is particularly useful when multiple assistants share a common tool to maintain shared state or history.
|
413
415
|
|
414
416
|
### Working with Files and Images
|
415
417
|
|
data/lib/ox-ai-workers.rb
CHANGED
@@ -43,6 +43,7 @@ require_relative 'oxaiworkers/models/openai_max'
|
|
43
43
|
require_relative 'oxaiworkers/models/openai_mini'
|
44
44
|
require_relative 'oxaiworkers/models/openai_nano'
|
45
45
|
require_relative 'oxaiworkers/models/deepseek_max'
|
46
|
+
require_relative 'oxaiworkers/models/openai_whisper'
|
46
47
|
|
47
48
|
require_relative 'oxaiworkers/models/images_base'
|
48
49
|
require_relative 'oxaiworkers/models/stability_images'
|
@@ -60,7 +61,7 @@ module OxAiWorkers
|
|
60
61
|
|
61
62
|
class Configuration
|
62
63
|
attr_accessor :max_tokens, :temperature, :wait_for_complete, :access_token_deepseek, :access_token_openai,
|
63
|
-
:access_token_stability, :access_token_wolfram
|
64
|
+
:access_token_stability, :access_token_wolfram, :access_token_anthropic
|
64
65
|
|
65
66
|
def initialize
|
66
67
|
@max_tokens = DEFAULT_MAX_TOKEN
|
@@ -71,6 +72,7 @@ module OxAiWorkers
|
|
71
72
|
@access_token_openai = nil
|
72
73
|
@access_token_stability = nil
|
73
74
|
@access_token_wolfram = nil
|
75
|
+
@access_token_anthropic = nil
|
74
76
|
|
75
77
|
[Array, NilClass, String, Symbol, Hash].each do |c|
|
76
78
|
c.send(:include, OxAiWorkers::PresentCompat) unless c.method_defined?(:present?)
|
data/lib/oxaiworkers/iterator.rb
CHANGED
@@ -9,13 +9,14 @@ module OxAiWorkers
|
|
9
9
|
|
10
10
|
attr_accessor :worker, :role, :messages, :context, :tools, :queue, :monologue, :tasks,
|
11
11
|
:on_inner_monologue, :on_outer_voice, :on_finish, :def_except, :def_only,
|
12
|
-
:call_stack, :stop_double_calls
|
12
|
+
:call_stack, :stop_double_calls, :call_id
|
13
13
|
|
14
14
|
def initialize(worker:, role: nil, tools: [], on_inner_monologue: nil, on_outer_voice: nil,
|
15
15
|
on_finish: nil, steps: nil, def_except: [], def_only: nil, locale: nil,
|
16
16
|
call_stack: nil, stop_double_calls: [])
|
17
17
|
|
18
18
|
@locale = locale || I18n.locale
|
19
|
+
@call_id = 0
|
19
20
|
|
20
21
|
with_locale do
|
21
22
|
define_function :inner_monologue, description: I18n.t('oxaiworkers.iterator.inner_monologue.description') do
|
@@ -71,6 +72,7 @@ module OxAiWorkers
|
|
71
72
|
@queue = []
|
72
73
|
@tasks = []
|
73
74
|
@messages = []
|
75
|
+
@call_id = 0
|
74
76
|
complete_iteration
|
75
77
|
end
|
76
78
|
|
@@ -215,7 +217,7 @@ module OxAiWorkers
|
|
215
217
|
end
|
216
218
|
|
217
219
|
if @worker.tool_calls.present?
|
218
|
-
@queue << { role: :assistant, content: @worker.tool_calls_raw.to_s }
|
220
|
+
# @queue << { role: :assistant, content: @worker.tool_calls_raw.to_s }
|
219
221
|
@worker.tool_calls.each do |external_call|
|
220
222
|
tool = ([self] + @tools).select do |t|
|
221
223
|
tool_name = t.respond_to?(:tool_name) ? t.tool_name : t.class.tool_name
|
@@ -223,10 +225,29 @@ module OxAiWorkers
|
|
223
225
|
end.first
|
224
226
|
next if tool.nil?
|
225
227
|
|
228
|
+
@call_id += 1
|
229
|
+
# Add tool call message in the correct format
|
226
230
|
out = tool.send(external_call[:name], **external_call[:args])
|
227
|
-
@queue << {
|
228
|
-
|
229
|
-
|
231
|
+
@queue << {
|
232
|
+
role: :assistant,
|
233
|
+
tool_calls: [{
|
234
|
+
id: "call_#{@call_id}",
|
235
|
+
type: 'function',
|
236
|
+
function: {
|
237
|
+
name: external_call[:name],
|
238
|
+
arguments: external_call[:args].to_json
|
239
|
+
}
|
240
|
+
}]
|
241
|
+
}
|
242
|
+
@queue << if out.present?
|
243
|
+
{ role: :tool,
|
244
|
+
content: out,
|
245
|
+
tool_call_id: "call_#{@call_id}" }
|
246
|
+
else
|
247
|
+
{ role: :tool,
|
248
|
+
content: "Tool call #{external_call[:name]} successful.",
|
249
|
+
tool_call_id: "call_#{@call_id}" }
|
250
|
+
end
|
230
251
|
end
|
231
252
|
@worker.finish
|
232
253
|
iterate! if can_iterate?
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OxAiWorkers
|
4
|
+
module Models
|
5
|
+
class AnthropicMax < LLMBase
|
6
|
+
def initialize(uri_base: nil, api_key: nil, model: nil, max_tokens: nil, temperature: nil, frequency_penalty: nil)
|
7
|
+
@model = model || 'claude-3-7-sonnet-latest'
|
8
|
+
@uri_base = uri_base || 'https://api.anthropic.com/v1/'
|
9
|
+
@api_key = api_key || OxAiWorkers.configuration.access_token_anthropic
|
10
|
+
super(uri_base:, api_key: @api_key, model: @model, max_tokens:, temperature:, frequency_penalty:)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OxAiWorkers
|
4
|
+
module Models
|
5
|
+
class OpenaiWhisper
|
6
|
+
def initialize(uri_base: nil, api_key: nil, model: 'whisper-1')
|
7
|
+
@api_key = api_key || OxAiWorkers.configuration.access_token_openai
|
8
|
+
@uri_base = uri_base
|
9
|
+
@client = OpenAI::Client.new(access_token: @api_key, uri_base:)
|
10
|
+
@model = model
|
11
|
+
end
|
12
|
+
|
13
|
+
def transcribe(binary:, language: nil)
|
14
|
+
response = @client.audio.transcribe(
|
15
|
+
parameters: {
|
16
|
+
model: @model,
|
17
|
+
file: binary,
|
18
|
+
language:
|
19
|
+
}
|
20
|
+
)
|
21
|
+
response['text']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
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: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/oxaiworkers/image_iterator.rb
|
158
158
|
- lib/oxaiworkers/iterator.rb
|
159
159
|
- lib/oxaiworkers/load_i18n.rb
|
160
|
+
- lib/oxaiworkers/models/anthropic_max.rb
|
160
161
|
- lib/oxaiworkers/models/deepseek_max.rb
|
161
162
|
- lib/oxaiworkers/models/images_base.rb
|
162
163
|
- lib/oxaiworkers/models/llm_base.rb
|
@@ -165,6 +166,7 @@ files:
|
|
165
166
|
- lib/oxaiworkers/models/openai_max.rb
|
166
167
|
- lib/oxaiworkers/models/openai_mini.rb
|
167
168
|
- lib/oxaiworkers/models/openai_nano.rb
|
169
|
+
- lib/oxaiworkers/models/openai_whisper.rb
|
168
170
|
- lib/oxaiworkers/models/stability_images.rb
|
169
171
|
- lib/oxaiworkers/module_request.rb
|
170
172
|
- lib/oxaiworkers/present_compat.rb
|
@@ -206,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
208
|
- !ruby/object:Gem::Version
|
207
209
|
version: '0'
|
208
210
|
requirements: []
|
209
|
-
rubygems_version: 3.6.
|
211
|
+
rubygems_version: 3.6.9
|
210
212
|
specification_version: 4
|
211
213
|
summary: A powerful state machine with OpenAI generative intelligence integration
|
212
214
|
test_files: []
|