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.
@@ -1,61 +1,65 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'state_machine/core'
2
4
 
3
- class OxAiWorkers::StateBatch < OxAiWorkers::ModuleRequest
4
- include OxAiWorkers::StateHelper
5
- extend StateMachine::MacroMethods
5
+ module OxAiWorkers
6
+ class StateBatch < OxAiWorkers::ModuleRequest
7
+ include OxAiWorkers::StateHelper
8
+ extend StateMachine::MacroMethods
6
9
 
7
- alias_method :state_initialize, :initialize
8
- attr_accessor :file_id, :batch_id
10
+ alias state_initialize initialize
11
+ attr_accessor :file_id, :batch_id
9
12
 
10
- state_machine :batch_state, initial: ->(t){t.batch_id.present? ? :requested : :idle}, namespace: :batch do
11
- before_transition from: any, do: :log_me
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
- after_transition on: :end, do: :cleanup
14
- before_transition on: :process, do: :postBatch
15
- after_transition on: :cancel, do: [:cancelBatch, :complete_batch!]
16
- after_transition on: :complete, do: [:cleanStorage]
17
- after_transition on: :prepare, do: :uploadToStorage
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
- event :end do
20
- transition [:finished, :canceled] => :idle
21
- end
22
+ event :end do
23
+ transition %i[finished canceled] => :idle
24
+ end
22
25
 
23
- event :prepare do
24
- transition :idle => :prepared
25
- end
26
+ event :prepare do
27
+ transition idle: :prepared
28
+ end
26
29
 
27
- event :process do
28
- transition :prepared => :requested
29
- end
30
+ event :process do
31
+ transition prepared: :requested
32
+ end
30
33
 
31
- event :complete do
32
- transition [:requested, :failed] => :finished
33
- end
34
+ event :complete do
35
+ transition %i[requested failed] => :finished
36
+ end
34
37
 
35
- event :cancel do
36
- transition [:requested, :failed, :prepared] => :canceled
37
- end
38
+ event :cancel do
39
+ transition %i[requested failed prepared] => :canceled
40
+ end
38
41
 
39
- event :fail do
40
- transition [:requested, :prepared] => :failed
41
- end
42
+ event :fail do
43
+ transition %i[requested prepared] => :failed
44
+ end
42
45
 
43
- state :requested
44
- state :idle
45
- state :prepared
46
- state :canceled
47
- state :finished
48
- state :failed
49
- end
46
+ state :requested
47
+ state :idle
48
+ state :prepared
49
+ state :canceled
50
+ state :finished
51
+ state :failed
52
+ end
50
53
 
51
- def cleanup
52
- @file_id = nil
53
- @batch_id = nil
54
- super()
55
- end
54
+ def cleanup
55
+ @file_id = nil
56
+ @batch_id = nil
57
+ super()
58
+ end
56
59
 
57
- def initialize
58
- puts "call: StateBatch::#{__method__}"
59
- super()
60
+ def initialize
61
+ puts "call: StateBatch::#{__method__}"
62
+ super()
63
+ end
60
64
  end
61
- end
65
+ end
@@ -1,5 +1,9 @@
1
- module OxAiWorkers::StateHelper
2
- def log_me(transition)
3
- # puts "`#{transition.event}` was called to transition from :#{transition.from} to :#{transition.to}"
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
- require 'state_machine/core'
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
- event :iterate do
33
- transition :analyzed => :prepared
34
- end
3
+ require 'state_machine/core'
35
4
 
36
- event :end do
37
- transition :finished => :idle
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::Tool
6
- class Eval
7
- extend OxAiWorkers::ToolDefinition
8
- include OxAiWorkers::DependencyHelper
5
+ module OxAiWorkers
6
+ module Tool
7
+ class Eval
8
+ extend OxAiWorkers::ToolDefinition
9
+ include OxAiWorkers::DependencyHelper
9
10
 
10
- define_function :ruby, description: I18n.t('oxaiworkers.tool.eval.ruby.description') do
11
- property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.ruby.input'), required: true
12
- end
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
- define_function :sh, description: I18n.t('oxaiworkers.tool.eval.sh.description') do
15
- property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.sh.input'), required: true
16
- end
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
- def ruby(input:)
19
- puts Rainbow("Executing ruby: \"#{input}\"").red
20
- eval(input)
21
- end
19
+ def ruby(input:)
20
+ puts Rainbow("Executing ruby: \"#{input}\"").red
21
+ eval(input)
22
+ end
22
23
 
23
- def sh(input:)
24
- puts Rainbow("Executing sh: \"#{input}\"").red
25
- stdout_and_stderr_s, = Open3.capture2e(input)
26
- stdout_and_stderr_s
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = '0.2.5'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -0,0 +1,5 @@
1
+ en:
2
+ oxaiworkers:
3
+ assistant:
4
+ sysop:
5
+ role: "You are a software agent inside my computer"
@@ -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"
@@ -0,0 +1,10 @@
1
+ en:
2
+ oxaiworkers:
3
+ tool:
4
+ eval:
5
+ ruby:
6
+ description: "Execute Ruby code and return the result of the last expression"
7
+ input: "Ruby source code"
8
+ sh:
9
+ description: "Execute a sh command and get the result (stdout + stderr)"
10
+ input: "Source command"
@@ -0,0 +1,5 @@
1
+ ru:
2
+ oxaiworkers:
3
+ assistant:
4
+ sysop:
5
+ role: Ты программный агент внутри моего компьютера
@@ -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: Ты программный агент внутри моего компьютера
@@ -0,0 +1,10 @@
1
+ ru:
2
+ oxaiworkers:
3
+ tool:
4
+ eval:
5
+ ruby:
6
+ description: Выполнить код на ruby и вернуть результат последней строки
7
+ input: Исходный код на Ruby
8
+ sh:
9
+ description: Выполнить sh-команду и получить результат (stdout + stderr)
10
+ input: Исходная команда
@@ -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
- require 'i18n'
5
- I18n.load_path += Dir["#{File.expand_path('.oxaiworkers-local/locales')}/*.yml"]
6
- I18n.default_locale = :en
4
+ # Uncomment this if you want to change the locale
5
+ # require 'oxaiworkers/load_i18n'
6
+ # I18n.default_locale = :ru
7
7
 
8
- # Start your code here
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.2.5
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.system.yml
140
- - locales/ru.system.yml
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