ox-ai-workers 0.5.2 → 0.5.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 +6 -0
- data/README.md +23 -40
- data/lib/ox-ai-workers.rb +3 -1
- data/lib/oxaiworkers/assistant/module_base.rb +4 -0
- data/lib/oxaiworkers/iterator.rb +13 -19
- data/lib/oxaiworkers/version.rb +1 -1
- data/locales/en.iterator.yml +14 -14
- data/locales/ru.assistant.yml +1 -1
- data/locales/ru.iterator.yml +13 -13
- data/template/my_assistant.rb +9 -0
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34c154dd79d968e939b91f26e410e0f7a4e51c5099347b3577dc05708ab8b341
|
4
|
+
data.tar.gz: 294f14527bb5ef82e885ee5c93e6577d93c1820f844baad1139fbd385cb895c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2c528093acd8ef4a6214ef65898807f72172f10e211096cbd490589d04e55220ff679c57cc04dd677ab04a211445fe4eb8cfefbc0beb1b453fcb7282dfabd0
|
7
|
+
data.tar.gz: 14f317606790d54f1c735f437145da15243a86af05c28bfcaf63464929c841df1b4de02cc6326b94571ddb0334a3bd13298ffe78078e39e1c24e7314d386fea7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -88,6 +88,7 @@ OxAiWorkers.configure do |config|
|
|
88
88
|
config.model = "gpt-4o"
|
89
89
|
config.max_tokens = 4096
|
90
90
|
config.temperature = 0.7
|
91
|
+
config.auto_execute = true
|
91
92
|
end
|
92
93
|
```
|
93
94
|
|
@@ -124,6 +125,28 @@ iterator.add_task("linux")
|
|
124
125
|
|
125
126
|
This way, you have the flexibility to choose between a higher-level assistant for simplicity or a lower-level iterator for finer control over the tasks and tools used.
|
126
127
|
|
128
|
+
### Advanced instructions for your Assistant
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
steps = []
|
132
|
+
steps << 'Step 1. Develop your own solution to the problem, taking initiative and making assumptions.'
|
133
|
+
steps << 'Step 2. Enclose all your developments from the previous step in the ox_ai_workers_iterator__inner_monologue function.'
|
134
|
+
steps << 'Step 3. Call the necessary functions one after another until the desired result is achieved.'
|
135
|
+
steps << 'Step 4. When all intermediate steps are completed and the exact content of previous messages is no longer relevant, use the ox_ai_workers_iterator__pack_history function.'
|
136
|
+
steps << "Step 5. When the solution is ready, notify about it and wait for the user's response."
|
137
|
+
|
138
|
+
@iterator = OxAiWorkers::Iterator.new(
|
139
|
+
worker: init_worker(delayed: delayed, model: model),
|
140
|
+
role: 'You are a software agent inside my computer',
|
141
|
+
tools: [MyTool.new],
|
142
|
+
steps: steps,
|
143
|
+
on_inner_monologue: ->(text:) { puts "monologue: #{text}".colorize(:yellow) },
|
144
|
+
on_outer_voice: ->(text:) { puts "voice: #{text}".colorize(:green) },
|
145
|
+
on_action_request: ->(text:) { puts "action: #{text}".colorize(:red) },
|
146
|
+
on_pack_history: ->(text:) { puts "summary: #{text}".colorize(:blue) }
|
147
|
+
)
|
148
|
+
```
|
149
|
+
|
127
150
|
### Worker Options
|
128
151
|
|
129
152
|
As a worker, you can use different classes depending on your needs:
|
@@ -174,46 +197,6 @@ OxAiWorkers.logger.level = :debug
|
|
174
197
|
- **External Tools**: Integrates with external tools and services to complete tasks.
|
175
198
|
- **Finite State Machine**: Implements a robust state machine to manage task states and transitions.
|
176
199
|
|
177
|
-
## Configuration
|
178
|
-
|
179
|
-
OxAiWorkers uses YAML files for configuration. Below is an example configuration:
|
180
|
-
|
181
|
-
```yaml
|
182
|
-
en:
|
183
|
-
oxaiworkers:
|
184
|
-
iterator:
|
185
|
-
inner_monologue:
|
186
|
-
description: "Use inner monologue to plan the response and articulate main points"
|
187
|
-
speech: "Text"
|
188
|
-
outer_voice:
|
189
|
-
description: "Provide the user with necessary information without expecting a response"
|
190
|
-
text: "Text"
|
191
|
-
action_request:
|
192
|
-
description: "Ask a clarifying question or request an action with a response from the user"
|
193
|
-
action: "Text"
|
194
|
-
pack_history:
|
195
|
-
description: "Save facts, nuances, and actions before clearing messages"
|
196
|
-
text: "Listing important facts and nuances"
|
197
|
-
monologue:
|
198
|
-
- "Step 1: Develop your own solution to the problem. Take initiative and make assumptions."
|
199
|
-
- "Step 1.1: Wrap all your work for this step in the inner_monologue function."
|
200
|
-
- "Step 2: Relate your solution to the task, improve it, and call the necessary functions step by step."
|
201
|
-
- "Step 2.1: Interact with the user using the outer_voice and action_request functions during the process."
|
202
|
-
- "Step 3: When the solution is ready, report it using the outer_voice function."
|
203
|
-
- "Step 4: Save facts, nuances, and actions using the summarize function."
|
204
|
-
tool:
|
205
|
-
eval:
|
206
|
-
ruby:
|
207
|
-
description: "Execute Ruby code and return the result of the last expression"
|
208
|
-
input: "Ruby source code"
|
209
|
-
sh:
|
210
|
-
description: "Execute a sh command and get the result (stdout + stderr)"
|
211
|
-
input: "Source command"
|
212
|
-
assistant:
|
213
|
-
sysop:
|
214
|
-
role: "You are a software agent inside my computer"
|
215
|
-
```
|
216
|
-
|
217
200
|
## Contributing
|
218
201
|
|
219
202
|
Bug reports and pull requests are welcome on GitHub at https://github.com/neonix20b/ox-ai-workers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/neonix20b/ox-ai-workers/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/ox-ai-workers.rb
CHANGED
@@ -28,6 +28,7 @@ require_relative 'oxaiworkers/tool/file_system'
|
|
28
28
|
require_relative 'oxaiworkers/assistant/module_base'
|
29
29
|
require_relative 'oxaiworkers/assistant/sysop'
|
30
30
|
require_relative 'oxaiworkers/assistant/coder'
|
31
|
+
require_relative 'oxaiworkers/assistant/localizer'
|
31
32
|
|
32
33
|
module OxAiWorkers
|
33
34
|
DEFAULT_MODEL = 'gpt-4o-mini'
|
@@ -38,13 +39,14 @@ module OxAiWorkers
|
|
38
39
|
class ConfigurationError < Error; end
|
39
40
|
|
40
41
|
class Configuration
|
41
|
-
attr_accessor :model, :max_tokens, :temperature, :access_token
|
42
|
+
attr_accessor :model, :max_tokens, :temperature, :access_token, :auto_execute
|
42
43
|
|
43
44
|
def initialize
|
44
45
|
@access_token = nil
|
45
46
|
@model = DEFAULT_MODEL
|
46
47
|
@max_tokens = DEFAULT_MAX_TOKEN
|
47
48
|
@temperature = DEFAULT_TEMPERATURE
|
49
|
+
@auto_execute = true
|
48
50
|
|
49
51
|
[Array, NilClass, String, Symbol, Hash].each do |c|
|
50
52
|
c.send(:include, OxAiWorkers::PresentCompat) unless c.method_defined?(:present?)
|
data/lib/oxaiworkers/iterator.rb
CHANGED
@@ -25,12 +25,12 @@ module OxAiWorkers
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def initialize(worker:, role: nil, tools: [], on_inner_monologue: nil, on_outer_voice: nil, on_action_request: nil,
|
28
|
-
on_pack_history: nil)
|
28
|
+
on_pack_history: nil, steps: nil)
|
29
29
|
@worker = worker
|
30
30
|
@tools = [self] + tools
|
31
31
|
@role = role
|
32
32
|
@context = []
|
33
|
-
@monologue = I18n.t('oxaiworkers.iterator.monologue')
|
33
|
+
@monologue = steps || I18n.t('oxaiworkers.iterator.monologue')
|
34
34
|
|
35
35
|
@on_inner_monologue = on_inner_monologue
|
36
36
|
@on_outer_voice = on_outer_voice
|
@@ -53,14 +53,14 @@ module OxAiWorkers
|
|
53
53
|
|
54
54
|
def inner_monologue(speach:)
|
55
55
|
# @queue.pop
|
56
|
-
@queue << { role: :
|
56
|
+
@queue << { role: :assistant, content: speach.to_s }
|
57
57
|
@on_inner_monologue&.call(text: speach)
|
58
58
|
nil
|
59
59
|
end
|
60
60
|
|
61
61
|
def outer_voice(text:)
|
62
62
|
# @queue.pop
|
63
|
-
@queue << { role: :
|
63
|
+
@queue << { role: :assistant, content: text.to_s }
|
64
64
|
@on_outer_voice&.call(text: text)
|
65
65
|
nil
|
66
66
|
end
|
@@ -68,7 +68,7 @@ module OxAiWorkers
|
|
68
68
|
def action_request(action:)
|
69
69
|
@result = action
|
70
70
|
# @queue.pop
|
71
|
-
@messages << { role: :
|
71
|
+
@messages << { role: :assistant, content: action.to_s }
|
72
72
|
complete! if can_complete?
|
73
73
|
@on_action_request&.call(text: action)
|
74
74
|
nil
|
@@ -77,6 +77,7 @@ module OxAiWorkers
|
|
77
77
|
def summarize(text:)
|
78
78
|
@milestones << text.to_s
|
79
79
|
@messages = []
|
80
|
+
@queue << { role: :assistant, content: I18n.t('oxaiworkers.iterator.pack_history.result') }
|
80
81
|
@worker.finish
|
81
82
|
rebuild_worker
|
82
83
|
# complete! if can_complete?
|
@@ -91,13 +92,13 @@ module OxAiWorkers
|
|
91
92
|
|
92
93
|
def rebuild_worker
|
93
94
|
@worker.messages = []
|
94
|
-
@worker.append(role: :system, content: @role) if
|
95
|
+
@worker.append(role: :system, content: @role) if @role.present?
|
95
96
|
@worker.append(role: :system, content: @monologue.join("\n"))
|
96
|
-
@worker.append(messages: @context) if
|
97
|
+
@worker.append(messages: @context) if @context.present?
|
97
98
|
@tasks.each { |task| @worker.append(role: :user, content: task) }
|
98
|
-
@milestones.each { |milestone| @worker.append(role: :
|
99
|
+
@milestones.each { |milestone| @worker.append(role: :assistant, content: milestone) }
|
99
100
|
@worker.append(messages: @messages)
|
100
|
-
@worker.tools = @tools.map { |tool| tool.class.function_schemas.to_openai_format }.flatten if @tools.
|
101
|
+
@worker.tools = @tools.map { |tool| tool.class.function_schemas.to_openai_format }.flatten if @tools.present?
|
101
102
|
end
|
102
103
|
|
103
104
|
def next_iteration
|
@@ -127,18 +128,11 @@ module OxAiWorkers
|
|
127
128
|
end.first
|
128
129
|
unless tool.nil?
|
129
130
|
out = tool.send(external_call[:name], **external_call[:args])
|
130
|
-
@queue << { role: :
|
131
|
+
@queue << { role: :user, content: out.to_s } if out.present?
|
131
132
|
end
|
132
133
|
end
|
133
134
|
@worker.finish
|
134
135
|
iterate! if can_iterate?
|
135
|
-
|
136
|
-
# tool = @tools.select{|t| t.class.tool_name == @worker.external_call[:class] && t.respond_to?(@worker.external_call[:name]) }.first
|
137
|
-
# out = tool.send(@worker.external_call[:name], **@worker.external_call[:args])
|
138
|
-
# if can_iterate?
|
139
|
-
# @queue << {role: :system, content: out.to_s} if out.present?
|
140
|
-
# iterate!
|
141
|
-
# end
|
142
136
|
elsif @worker.result.present?
|
143
137
|
action_request action: @worker.result
|
144
138
|
end
|
@@ -149,10 +143,10 @@ module OxAiWorkers
|
|
149
143
|
@worker.finish
|
150
144
|
end
|
151
145
|
|
152
|
-
def add_task(task
|
146
|
+
def add_task(task)
|
153
147
|
@tasks << task
|
154
148
|
@messages << { role: :user, content: task }
|
155
|
-
execute if auto_execute
|
149
|
+
execute if OxAiWorkers.configuration.auto_execute
|
156
150
|
end
|
157
151
|
|
158
152
|
def add_context(text, role: :system)
|
data/lib/oxaiworkers/version.rb
CHANGED
data/locales/en.iterator.yml
CHANGED
@@ -2,21 +2,21 @@ en:
|
|
2
2
|
oxaiworkers:
|
3
3
|
iterator:
|
4
4
|
inner_monologue:
|
5
|
-
description:
|
6
|
-
|
5
|
+
description: A function for internal monologue, allowing the AI to ponder and formulate its thoughts without user involvement. Used for intermediate reflections and recording data that do not require immediate response or action from the user.
|
6
|
+
speach: Text of reflections or conclusions
|
7
7
|
outer_voice:
|
8
|
-
description:
|
9
|
-
text:
|
8
|
+
description: Inform the user of the necessary information without expecting a response.
|
9
|
+
text: Content of the message
|
10
10
|
action_request:
|
11
|
-
description:
|
12
|
-
action:
|
11
|
+
description: A function for interactive interaction with the user. Allows you to ask a clarifying question, request actions, or complete the current step. The function waits for the user's response and returns it.
|
12
|
+
action: Text of the request or action
|
13
13
|
pack_history:
|
14
|
-
description:
|
15
|
-
text:
|
14
|
+
description: The function saves key facts, nuances, and actions from previous messages, including the provided response. After calling this function, all previous messages will be deleted. Use it only after all intermediate steps are completed and when the exact content of previous messages is no longer relevant.
|
15
|
+
text: Enumeration of important facts and nuances
|
16
|
+
result: Messages deleted
|
16
17
|
monologue:
|
17
|
-
-
|
18
|
-
-
|
19
|
-
-
|
20
|
-
-
|
21
|
-
-
|
22
|
-
- "Step 4: Save facts, nuances, and actions using the ox_ai_workers_iterator__summarize function."
|
18
|
+
- Step 1. Develop your own solution to the problem, taking initiative and making assumptions.
|
19
|
+
- Step 2. Enclose all your developments from the previous step in the ox_ai_workers_iterator__inner_monologue function.
|
20
|
+
- Step 3. Call the necessary functions one after another until the desired result is achieved.
|
21
|
+
- Step 4. When all intermediate steps are completed and the exact content of previous messages is no longer relevant, use the ox_ai_workers_iterator__pack_history function.
|
22
|
+
- Step 5. When the solution is ready, notify about it and wait for the user's response.
|
data/locales/ru.assistant.yml
CHANGED
@@ -8,4 +8,4 @@ ru:
|
|
8
8
|
localizer:
|
9
9
|
role: "Ты профессиональный локализатор (переводчик) на %s язык внутри моего компьютера. Твоя задача корректно локализовать файлы (создать по аналогии новые на нужном языке), которые предоставит пользователь."
|
10
10
|
source: "Возьми за основу %s язык"
|
11
|
-
locale: "
|
11
|
+
locale: "%s язык имеет локаль :%s"
|
data/locales/ru.iterator.yml
CHANGED
@@ -2,21 +2,21 @@ ru:
|
|
2
2
|
oxaiworkers:
|
3
3
|
iterator:
|
4
4
|
inner_monologue:
|
5
|
-
description:
|
6
|
-
speach: Текст
|
5
|
+
description: Функция для внутреннего монолога, позволяющая ИИ обдумывать и формулировать свои мысли без участия пользователя. Используется для промежуточных размышлений и фиксации данных, которые не требуют немедленного ответа или действия от пользователя.
|
6
|
+
speach: Текст размышлений или выводов
|
7
7
|
outer_voice:
|
8
|
-
description: Сообщить пользователю необходимую информацию без ожидания
|
9
|
-
text:
|
8
|
+
description: Сообщить пользователю необходимую информацию без ожидания ответа.
|
9
|
+
text: Содержимое сообщения
|
10
10
|
action_request:
|
11
|
-
description:
|
12
|
-
action: Текст
|
11
|
+
description: Функция для интерактивного взаимодействия с пользователем. Позволяет задать уточняющий вопрос, запросить выполнение действий или завершить текущий шаг. Функция ожидает ответ пользователя и возвращает его.
|
12
|
+
action: Текст запроса или действия
|
13
13
|
pack_history:
|
14
|
-
description:
|
14
|
+
description: Функция сохраняет ключевые факты, нюансы и действия из предыдущих сообщений, включая предоставленный ответ. После вызова этой функции все предыдущие сообщения будут удалены. Используйте её только после завершения всех промежуточных шагов и когда точное содержание предыдущих сообщений больше не имеет значения.
|
15
15
|
text: Перечисление важных фактов и нюансов
|
16
|
+
result: Сообщения удалены
|
16
17
|
monologue:
|
17
|
-
- Шаг 1. Разработай собственное решение
|
18
|
-
- Шаг
|
19
|
-
- Шаг
|
20
|
-
- Шаг
|
21
|
-
- Шаг
|
22
|
-
- Шаг 4. Сохрани факты, нюансы и действия с помощью функции ox_ai_workers_iterator__summarize и предложи дальнейшие действия с помощью функции ox_ai_workers_iterator__action_request.
|
18
|
+
- Шаг 1. Разработай собственное решение проблемы, проявляя инициативу и делая предположения.
|
19
|
+
- Шаг 2. Заключи все свои наработки из предыдущего шага в функцию ox_ai_workers_iterator__inner_monologue.
|
20
|
+
- Шаг 3. Вызывай необходимые функции друг за другом, пока желаемый результат не будет достигнут.
|
21
|
+
- Шаг 4. Когда все промежуточные шаги завершены и точное содержание предыдущих сообщений больше не имеет значения, используй функцию ox_ai_workers_iterator__pack_history.
|
22
|
+
- Шаг 5. Когда решение готово, сообщи об этом и ожидай ответ пользователя.
|
data/template/my_assistant.rb
CHANGED
@@ -7,10 +7,19 @@ class MyAssistant
|
|
7
7
|
include OxAiWorkers::Assistant::ModuleBase
|
8
8
|
|
9
9
|
def initialize(delayed: false, model: nil)
|
10
|
+
# Optional instructions
|
11
|
+
# steps = []
|
12
|
+
# steps << 'Step 1. Develop your own solution to the problem, taking initiative and making assumptions.'
|
13
|
+
# steps << 'Step 2. Enclose all your developments from the previous step in the ox_ai_workers_iterator__inner_monologue function.'
|
14
|
+
# steps << 'Step 3. Call the necessary functions one after another until the desired result is achieved.'
|
15
|
+
# steps << 'Step 4. When all intermediate steps are completed and the exact content of previous messages is no longer relevant, use the ox_ai_workers_iterator__pack_history function.'
|
16
|
+
# steps << "Step 5. When the solution is ready, notify about it and wait for the user's response."
|
17
|
+
|
10
18
|
@iterator = OxAiWorkers::Iterator.new(
|
11
19
|
worker: init_worker(delayed: delayed, model: model),
|
12
20
|
role: 'You are a software agent inside my computer',
|
13
21
|
tools: [MyTool.new],
|
22
|
+
# steps: steps,
|
14
23
|
on_inner_monologue: ->(text:) { puts "monologue: #{text}".colorize(:yellow) },
|
15
24
|
on_outer_voice: ->(text:) { puts "voice: #{text}".colorize(:green) },
|
16
25
|
on_action_request: ->(text:) { puts "action: #{text}".colorize(:red) },
|
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.5.
|
4
|
+
version: 0.5.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
@@ -108,17 +108,17 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1'
|
111
|
-
description: |
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
111
|
+
description: |
|
112
|
+
OxAiWorkers (ox-ai-workers) is a Ruby gem that provides a powerful and flexible state machine with
|
113
|
+
integration of generative intelligence using the ruby-openai gem. This gem allows you to create state
|
114
|
+
machines for solving complex tasks, enhancing the final result by leveraging internal logic (state machine)
|
115
|
+
and external tools (OpenAI generative intelligence).
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
117
|
+
Features:
|
118
|
+
- State Machine: Easily create and manage state machines to model various states and transitions in your application.
|
119
|
+
- OpenAI Integration: Utilize the capabilities of generative intelligence to make decisions and perform tasks, improving the quality and accuracy of results.
|
120
|
+
- Flexibility and Extensibility: Customize the behavior of the state machine and OpenAI integration according to your needs.
|
121
|
+
- Ease of Use: Intuitive syntax and documentation make it easy to get started with the gem.
|
122
122
|
email:
|
123
123
|
- smolev@me.com
|
124
124
|
executables:
|