ox-ai-workers 0.2.5 → 0.3.1
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 +11 -0
- data/README.md +15 -6
- data/exe/oxaiworkers +1 -1
- data/exe/start +3 -3
- data/lib/ox-ai-workers.rb +28 -34
- data/lib/oxaiworkers/assistant/sysop.rb +5 -1
- data/lib/oxaiworkers/compatibility.rb +2 -0
- data/lib/oxaiworkers/delayed_request.rb +95 -93
- data/lib/oxaiworkers/iterator.rb +154 -159
- data/lib/oxaiworkers/load_i18n.rb +4 -0
- data/lib/oxaiworkers/module_request.rb +62 -62
- data/lib/oxaiworkers/present_compat.rb +31 -27
- data/lib/oxaiworkers/request.rb +15 -13
- data/lib/oxaiworkers/state_batch.rb +50 -46
- data/lib/oxaiworkers/state_helper.rb +8 -4
- data/lib/oxaiworkers/state_tools.rb +46 -43
- data/lib/oxaiworkers/tool/eval.rb +20 -18
- data/lib/oxaiworkers/version.rb +1 -1
- data/locales/en.assistant.yml +5 -0
- data/locales/{en.system.yml → en.iterator.yml} +0 -11
- data/locales/en.tool.yml +10 -0
- data/locales/ru.assistant.yml +5 -0
- data/locales/{ru.system.yml → ru.iterator.yml} +0 -11
- data/locales/ru.tool.yml +10 -0
- data/template/my_assistant.rb +6 -1
- data/template/start +10 -4
- metadata +8 -3
@@ -1,61 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'state_machine/core'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
module OxAiWorkers
|
6
|
+
class StateBatch < OxAiWorkers::ModuleRequest
|
7
|
+
include OxAiWorkers::StateHelper
|
8
|
+
extend StateMachine::MacroMethods
|
6
9
|
|
7
|
-
|
8
|
-
|
10
|
+
alias state_initialize initialize
|
11
|
+
attr_accessor :file_id, :batch_id
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
state_machine :batch_state, initial: ->(t) { t.batch_id.present? ? :requested : :idle }, namespace: :batch do
|
14
|
+
before_transition from: any, do: :log_me
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
after_transition on: :end, do: :cleanup
|
17
|
+
before_transition on: :process, do: :postBatch
|
18
|
+
after_transition on: :cancel, do: %i[cancelBatch complete_batch!]
|
19
|
+
after_transition on: :complete, do: [:cleanStorage]
|
20
|
+
after_transition on: :prepare, do: :uploadToStorage
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
event :end do
|
23
|
+
transition %i[finished canceled] => :idle
|
24
|
+
end
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
event :prepare do
|
27
|
+
transition idle: :prepared
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
event :process do
|
31
|
+
transition prepared: :requested
|
32
|
+
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
event :complete do
|
35
|
+
transition %i[requested failed] => :finished
|
36
|
+
end
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
event :cancel do
|
39
|
+
transition %i[requested failed prepared] => :canceled
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
+
event :fail do
|
43
|
+
transition %i[requested prepared] => :failed
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
state :requested
|
47
|
+
state :idle
|
48
|
+
state :prepared
|
49
|
+
state :canceled
|
50
|
+
state :finished
|
51
|
+
state :failed
|
52
|
+
end
|
50
53
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
def cleanup
|
55
|
+
@file_id = nil
|
56
|
+
@batch_id = nil
|
57
|
+
super()
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
+
def initialize
|
61
|
+
puts "call: StateBatch::#{__method__}"
|
62
|
+
super()
|
63
|
+
end
|
60
64
|
end
|
61
|
-
end
|
65
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OxAiWorkers
|
4
|
+
module StateHelper
|
5
|
+
def log_me(transition)
|
6
|
+
# puts "`#{transition.event}` was called to transition from :#{transition.from} to :#{transition.to}"
|
7
|
+
end
|
4
8
|
end
|
5
|
-
end
|
9
|
+
end
|
@@ -1,47 +1,50 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class OxAiWorkers::StateTools
|
4
|
-
include OxAiWorkers::StateHelper
|
5
|
-
extend StateMachine::MacroMethods
|
6
|
-
|
7
|
-
state_machine :state, initial: :idle do
|
8
|
-
before_transition from: any, do: :log_me
|
9
|
-
|
10
|
-
after_transition on: :iterate, do: :nextIteration
|
11
|
-
after_transition on: :request, do: :externalRequest
|
12
|
-
after_transition on: :prepare, do: :init
|
13
|
-
after_transition on: :analyze, do: :processResult
|
14
|
-
after_transition on: :complete, do: :completeIteration
|
15
|
-
|
16
|
-
event :prepare do
|
17
|
-
transition [:idle, :finished] => :prepared
|
18
|
-
end
|
19
|
-
|
20
|
-
event :request do
|
21
|
-
transition :prepared => :requested
|
22
|
-
end
|
23
|
-
|
24
|
-
event :analyze do
|
25
|
-
transition [:requested] => :analyzed
|
26
|
-
end
|
27
|
-
|
28
|
-
event :complete do
|
29
|
-
transition [:analyzed] => :finished
|
30
|
-
end
|
1
|
+
# frozen_string_literal: true
|
31
2
|
|
32
|
-
|
33
|
-
transition :analyzed => :prepared
|
34
|
-
end
|
3
|
+
require 'state_machine/core'
|
35
4
|
|
36
|
-
|
37
|
-
|
5
|
+
module OxAiWorkers
|
6
|
+
class StateTools
|
7
|
+
include OxAiWorkers::StateHelper
|
8
|
+
extend StateMachine::MacroMethods
|
9
|
+
|
10
|
+
state_machine :state, initial: :idle do
|
11
|
+
before_transition from: any, do: :log_me
|
12
|
+
|
13
|
+
after_transition on: :iterate, do: :nextIteration
|
14
|
+
after_transition on: :request, do: :externalRequest
|
15
|
+
after_transition on: :prepare, do: :init
|
16
|
+
after_transition on: :analyze, do: :processResult
|
17
|
+
after_transition on: :complete, do: :completeIteration
|
18
|
+
|
19
|
+
event :prepare do
|
20
|
+
transition %i[idle finished] => :prepared
|
21
|
+
end
|
22
|
+
|
23
|
+
event :request do
|
24
|
+
transition prepared: :requested
|
25
|
+
end
|
26
|
+
|
27
|
+
event :analyze do
|
28
|
+
transition [:requested] => :analyzed
|
29
|
+
end
|
30
|
+
|
31
|
+
event :complete do
|
32
|
+
transition [:analyzed] => :finished
|
33
|
+
end
|
34
|
+
|
35
|
+
event :iterate do
|
36
|
+
transition analyzed: :prepared
|
37
|
+
end
|
38
|
+
|
39
|
+
event :end do
|
40
|
+
transition finished: :idle
|
41
|
+
end
|
42
|
+
|
43
|
+
state :idle
|
44
|
+
state :prepared
|
45
|
+
state :requested
|
46
|
+
state :analyzed
|
47
|
+
state :finished
|
38
48
|
end
|
39
|
-
|
40
|
-
state :idle
|
41
|
-
state :prepared
|
42
|
-
state :requested
|
43
|
-
state :analyzed
|
44
|
-
state :finished
|
45
49
|
end
|
46
|
-
|
47
|
-
end
|
50
|
+
end
|
@@ -2,28 +2,30 @@
|
|
2
2
|
|
3
3
|
require 'open3'
|
4
4
|
|
5
|
-
module OxAiWorkers
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module OxAiWorkers
|
6
|
+
module Tool
|
7
|
+
class Eval
|
8
|
+
extend OxAiWorkers::ToolDefinition
|
9
|
+
include OxAiWorkers::DependencyHelper
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
define_function :ruby, description: I18n.t('oxaiworkers.tool.eval.ruby.description') do
|
12
|
+
property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.ruby.input'), required: true
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
define_function :sh, description: I18n.t('oxaiworkers.tool.eval.sh.description') do
|
16
|
+
property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.sh.input'), required: true
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def ruby(input:)
|
20
|
+
puts Rainbow("Executing ruby: \"#{input}\"").red
|
21
|
+
eval(input)
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def sh(input:)
|
25
|
+
puts Rainbow("Executing sh: \"#{input}\"").red
|
26
|
+
stdout_and_stderr_s, = Open3.capture2e(input)
|
27
|
+
stdout_and_stderr_s
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
data/lib/oxaiworkers/version.rb
CHANGED
@@ -20,14 +20,3 @@ en:
|
|
20
20
|
- "Step 2.1: Interact with the user using the ox_ai_workers_iterator__outerVoice and ox_ai_workers_iterator__actionRequest functions during the process."
|
21
21
|
- "Step 3: When the solution is ready, report it using the ox_ai_workers_iterator__outerVoice function."
|
22
22
|
- "Step 4: Save facts, nuances, and actions using the ox_ai_workers_iterator__packHistory function."
|
23
|
-
tool:
|
24
|
-
eval:
|
25
|
-
ruby:
|
26
|
-
description: "Execute Ruby code and return the result of the last expression"
|
27
|
-
input: "Ruby source code"
|
28
|
-
sh:
|
29
|
-
description: "Execute a sh command and get the result (stdout + stderr)"
|
30
|
-
input: "Source command"
|
31
|
-
assistant:
|
32
|
-
sysop:
|
33
|
-
role: "You are a software agent inside my computer"
|
data/locales/en.tool.yml
ADDED
@@ -20,14 +20,3 @@ ru:
|
|
20
20
|
- Шаг 2.1. Во время работы используй функции ox_ai_workers_iterator__outerVoice и ox_ai_workers_iterator__actionRequest.
|
21
21
|
- Шаг 3. Когда решение готово, сообщи о нем с помощью функции ox_ai_workers_iterator__outerVoice
|
22
22
|
- Шаг 4. Сохрани факты, нюансы и действия с помощью функции ox_ai_workers_iterator__packHistory и предложи дальнейшие действия с помощью функции ox_ai_workers_iterator__actionRequest.
|
23
|
-
tool:
|
24
|
-
eval:
|
25
|
-
ruby:
|
26
|
-
description: Выполнить код на ruby и вернуть результат последней строки
|
27
|
-
input: Исходный код на Ruby
|
28
|
-
sh:
|
29
|
-
description: Выполнить sh-команду и получить результат (stdout + stderr)
|
30
|
-
input: Исходная команда
|
31
|
-
assistant:
|
32
|
-
sysop:
|
33
|
-
role: Ты программный агент внутри моего компьютера
|
data/locales/ru.tool.yml
ADDED
data/template/my_assistant.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rainbow'
|
3
4
|
require_relative 'tools/my_tool'
|
4
5
|
|
5
6
|
class MyAssistant
|
@@ -9,7 +10,11 @@ class MyAssistant
|
|
9
10
|
@iterator = OxAiWorkers::Iterator.new(
|
10
11
|
worker: initWorker(delayed: delayed, model: model),
|
11
12
|
role: 'You are a software agent inside my computer',
|
12
|
-
tools: [MyTool.new]
|
13
|
+
tools: [MyTool.new],
|
14
|
+
on_inner_monologue: ->(text:) { puts Rainbow("monologue: #{text}").yellow },
|
15
|
+
on_outer_voice: ->(text:) { puts Rainbow("voice: #{text}").green },
|
16
|
+
on_action_request: ->(text:) { puts Rainbow("action: #{text}").red },
|
17
|
+
on_pack_history: ->(text:) { puts Rainbow("summary: #{text}").blue }
|
13
18
|
)
|
14
19
|
end
|
15
20
|
end
|
data/template/start
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
I18n.default_locale = :
|
4
|
+
# Uncomment this if you want to change the locale
|
5
|
+
# require 'oxaiworkers/load_i18n'
|
6
|
+
# I18n.default_locale = :ru
|
7
7
|
|
8
|
-
#
|
8
|
+
# Required external gems
|
9
9
|
require 'ox-ai-workers'
|
10
10
|
require 'irb'
|
11
|
+
|
12
|
+
# ### Start your code here ###
|
13
|
+
|
14
|
+
# Required my libs
|
11
15
|
require_relative 'my_assistant'
|
12
16
|
|
13
17
|
puts "OxAiWorkers #{OxAiWorkers::VERSION}"
|
14
18
|
|
19
|
+
# Configure
|
15
20
|
OxAiWorkers.configure do |config|
|
16
21
|
config.access_token = ENV.fetch('OPENAI')
|
17
22
|
config.model = 'gpt-4o-mini'
|
18
23
|
end
|
19
24
|
|
25
|
+
# Main algorithm
|
20
26
|
@assistant = MyAssistant.new
|
21
27
|
|
22
28
|
IRB.start(__FILE__)
|
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/oxaiworkers/delayed_request.rb
|
127
127
|
- lib/oxaiworkers/dependency_helper.rb
|
128
128
|
- lib/oxaiworkers/iterator.rb
|
129
|
+
- lib/oxaiworkers/load_i18n.rb
|
129
130
|
- lib/oxaiworkers/module_request.rb
|
130
131
|
- lib/oxaiworkers/present_compat.rb
|
131
132
|
- lib/oxaiworkers/request.rb
|
@@ -136,8 +137,12 @@ files:
|
|
136
137
|
- lib/oxaiworkers/tool_definition.rb
|
137
138
|
- lib/oxaiworkers/version.rb
|
138
139
|
- lib/ruby/ox-ai-workers.rb
|
139
|
-
- locales/en.
|
140
|
-
- locales/
|
140
|
+
- locales/en.assistant.yml
|
141
|
+
- locales/en.iterator.yml
|
142
|
+
- locales/en.tool.yml
|
143
|
+
- locales/ru.assistant.yml
|
144
|
+
- locales/ru.iterator.yml
|
145
|
+
- locales/ru.tool.yml
|
141
146
|
- template/my_assistant.rb
|
142
147
|
- template/start
|
143
148
|
- template/tools/my_tool.rb
|