ox-ai-workers 0.2.2 → 0.2.4
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 +20 -9
- data/README.md +57 -10
- data/exe/oxaiworkers +21 -15
- data/exe/start +11 -5
- data/lib/oxaiworkers/assistant/sysop.rb +8 -6
- data/lib/oxaiworkers/tool/eval.rb +8 -7
- data/lib/oxaiworkers/version.rb +1 -2
- data/template/my_assistant.rb +15 -0
- data/template/start +22 -0
- data/template/tools/my_tool.rb +14 -0
- metadata +14 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68e329b2bdf72c3b0d75acc50542f1af17bfde774f5e1ad26b4d28ae8b2eb3d4
|
4
|
+
data.tar.gz: 7e233262b802841e7a3c6241864376d5d25668391a9b482f441b47617e556703
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed6cb48bbf7ed1069fc29a4e3ca8e288f8c4e7af4fd08cd4ef4cf1a599de3720edb220afe52cb56db3b01f694cff197924b7d66908a7513979a64d818672b7c0
|
7
|
+
data.tar.gz: bceb85175f975cd69100186012a4429f37e78e01f91962921979d7c27bf4e09dd0150dc8fa83d20711a62073ffb6ad58bf99bac756fdb6cf8c34de785bdf2c37
|
data/CHANGELOG.md
CHANGED
@@ -1,20 +1,31 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.4] - 2024-07-30
|
4
|
+
|
5
|
+
- Complete template for initialization: `oxaiworkers init full`
|
6
|
+
- Fix missing require_relative
|
7
|
+
|
8
|
+
## [0.2.3] - 2024-07-30
|
9
|
+
|
10
|
+
- Added start script with configuration section
|
11
|
+
|
3
12
|
## [0.2.2] - 2024-07-30
|
4
|
-
|
5
|
-
-
|
13
|
+
|
14
|
+
- Fixed CLI issues
|
15
|
+
- Improved start script (CLI: .oxaiworkers-local/start)
|
16
|
+
- Enhanced initialization script
|
6
17
|
|
7
18
|
## [0.2.0] - 2024-07-30
|
8
|
-
|
9
|
-
-
|
10
|
-
-
|
19
|
+
|
20
|
+
- Fixed missing require 'open3'
|
21
|
+
- Corrected execution steps
|
22
|
+
- CLI: added command `oxaiworkers init`
|
11
23
|
|
12
24
|
## [0.1.1] - 2024-07-29
|
13
25
|
|
14
|
-
-
|
15
|
-
-
|
26
|
+
- Fixed delayed requests
|
27
|
+
- Added configurable parameters for model, max_tokens, temperature
|
16
28
|
|
17
29
|
## [0.1.0] - 2024-07-29
|
18
30
|
|
19
|
-
- Initial release
|
20
|
-
|
31
|
+
- Initial release
|
data/README.md
CHANGED
@@ -27,28 +27,52 @@ gem install ox-ai-workers
|
|
27
27
|
Here's a basic example of how to use OxAiWorkers:
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
|
31
|
-
I18n.
|
30
|
+
# Load localization files and set default locale
|
31
|
+
I18n.load_path += Dir[File.expand_path("locales") + "/*.yml"] # only for pure Ruby
|
32
|
+
I18n.default_locale = :en # only for pure Ruby
|
33
|
+
|
34
|
+
# Require the main gem
|
32
35
|
require 'ox-ai-workers'
|
33
36
|
|
34
37
|
# Initialize the assistant
|
35
38
|
sysop = OxAiWorkers::Assistant::Sysop.new(delayed: false, model: "gpt-4o")
|
36
39
|
|
37
|
-
# Add a task
|
40
|
+
# Add a task to the assistant
|
38
41
|
sysop.setTask("Add a cron job to synchronize files daily.")
|
39
42
|
|
40
|
-
#
|
43
|
+
# Provide a response to the assistant's question
|
41
44
|
sysop.addResponse("blah-blah-blah")
|
42
45
|
```
|
43
46
|
|
47
|
+
Alternatively, you can use a lower-level approach for more control:
|
48
|
+
|
44
49
|
```ruby
|
45
|
-
|
46
|
-
|
47
|
-
|
50
|
+
# Initialize a worker for delayed requests
|
51
|
+
worker = OxAiWorkers::DelayedRequest.new(
|
52
|
+
model: "gpt-4o-mini",
|
53
|
+
max_tokens: 4096,
|
54
|
+
temperature: 0.7 )
|
55
|
+
|
56
|
+
# Alternatively, initialize a worker for immediate requests
|
57
|
+
worker = OxAiWorkers::Request.new(
|
58
|
+
model: "gpt-4o-mini",
|
59
|
+
max_tokens: 4096,
|
60
|
+
temperature: 0.7 )
|
61
|
+
|
62
|
+
# Initialize a tool
|
48
63
|
my_tool = OxAiWorkers::Tool::Eval.new()
|
49
|
-
|
64
|
+
|
65
|
+
# Create an iterator with the worker and tool
|
66
|
+
iterator = OxAiWorkers::Iterator.new(
|
67
|
+
worker: worker,
|
68
|
+
tools: [my_tool] )
|
50
69
|
iterator.role = "You are a software agent inside my computer"
|
70
|
+
|
71
|
+
# Add a task to the iterator
|
51
72
|
iterator.addTask("Show files in current dir")
|
73
|
+
|
74
|
+
# Provide a response to the gpt's question
|
75
|
+
iterator.addTask("linux")
|
52
76
|
```
|
53
77
|
|
54
78
|
### With Config
|
@@ -68,18 +92,35 @@ Then you can create an assistant like this:
|
|
68
92
|
|
69
93
|
```ruby
|
70
94
|
assistant = OxAiWorkers::Assistant::Sysop.new()
|
95
|
+
assistant.setTask("your task")
|
96
|
+
|
97
|
+
# Provide a response to the assistant's question
|
98
|
+
assistant.addResponse("blah-blah-blah")
|
71
99
|
```
|
72
100
|
|
101
|
+
Or you can create a lower-level iterator for more control:
|
102
|
+
|
73
103
|
```ruby
|
74
104
|
iterator = OxAiWorkers::Iterator.new(
|
75
105
|
worker: OxAiWorkers::Request.new,
|
76
106
|
tools: [OxAiWorkers::Tool::Eval.new],
|
77
|
-
role: "You are a software agent inside my computer"
|
78
|
-
)
|
107
|
+
role: "You are a software agent inside my computer" )
|
79
108
|
|
80
109
|
iterator.addTask("Show files in current directory.")
|
110
|
+
# ...
|
111
|
+
iterator.addTask("linux")
|
81
112
|
```
|
82
113
|
|
114
|
+
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.
|
115
|
+
|
116
|
+
### Worker Options
|
117
|
+
|
118
|
+
As a worker, you can use different classes depending on your needs:
|
119
|
+
|
120
|
+
- `OxAiWorkers::Request`: This class is used for immediate request execution. It is suitable for operations that require instant responses.
|
121
|
+
|
122
|
+
- `OxAiWorkers::DelayedRequest`: This class is used for batch API requests, ideal for operations that do not require immediate execution. Using `DelayedRequest` can save up to 50% on costs as requests are executed when the remote server is less busy, but no later than within 24 hours.
|
123
|
+
|
83
124
|
## Command Line Interface (CLI)
|
84
125
|
|
85
126
|
1. Navigate to the required directory.
|
@@ -90,6 +131,12 @@ iterator.addTask("Show files in current directory.")
|
|
90
131
|
oxaiworkers init
|
91
132
|
```
|
92
133
|
|
134
|
+
or
|
135
|
+
|
136
|
+
```sh
|
137
|
+
oxaiworkers init full
|
138
|
+
```
|
139
|
+
|
93
140
|
This will create a `.oxaiworkers-local` directory with the necessary initial settings.
|
94
141
|
|
95
142
|
3. Modify the settings as needed and run:
|
data/exe/oxaiworkers
CHANGED
@@ -1,20 +1,26 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'fileutils'
|
4
5
|
|
5
|
-
|
6
|
-
dir = '.oxaiworkers-local'
|
7
|
-
dest = "#{Dir.pwd}/#{dir}"
|
8
|
-
source = File.expand_path('../../', __FILE__)
|
6
|
+
puts 'Welcome to OxAiWorkers!'
|
9
7
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
8
|
+
if ARGV.first == 'init'
|
9
|
+
dir = '.oxaiworkers-local'
|
10
|
+
dest = "#{Dir.pwd}/#{dir}"
|
11
|
+
source = File.expand_path('..', __dir__)
|
12
|
+
|
13
|
+
if Dir.exist? dir
|
14
|
+
puts "Error: The #{dir} directory already exists."
|
15
|
+
else
|
16
|
+
FileUtils.mkdir_p "#{dir}/locales"
|
17
|
+
FileUtils.copy_entry "#{source}/locales", "#{dest}/locales"
|
18
|
+
if ARGV.last == 'full'
|
19
|
+
FileUtils.copy_entry "#{source}/template", dest.to_s
|
20
|
+
else
|
21
|
+
FileUtils.cp("#{source}/exe/start", dest)
|
22
|
+
end
|
23
|
+
puts "A #{dir} directory was created with the necessary initial settings."
|
24
|
+
puts "Modify the settings as needed and run: #{dir}/start"
|
25
|
+
end
|
26
|
+
end
|
data/exe/start
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
require 'i18n'
|
5
|
+
I18n.load_path += Dir["#{File.expand_path('.oxaiworkers-local/locales')}/*.yml"]
|
5
6
|
I18n.default_locale = :en
|
6
7
|
|
7
8
|
# Start your code here
|
8
|
-
require
|
9
|
-
require
|
9
|
+
require 'ox-ai-workers'
|
10
|
+
require 'irb'
|
10
11
|
|
11
12
|
puts "OxAiWorkers #{OxAiWorkers::VERSION}"
|
12
13
|
|
13
|
-
|
14
|
+
OxAiWorkers.configure do |config|
|
15
|
+
config.access_token = ENV.fetch('OPENAI')
|
16
|
+
config.model = 'gpt-4o-mini'
|
17
|
+
end
|
18
|
+
|
19
|
+
@assistant = OxAiWorkers::Assistant::Sysop.new
|
14
20
|
|
15
21
|
IRB.start(__FILE__)
|
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module OxAiWorkers
|
2
4
|
module Assistant
|
3
5
|
class Sysop
|
4
6
|
include OxAiWorkers::Assistant::ModuleBase
|
5
7
|
|
6
|
-
def initialize
|
8
|
+
def initialize(delayed: false, model: nil)
|
7
9
|
@iterator = OxAiWorkers::Iterator.new(
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
worker: initWorker(delayed: delayed, model: model),
|
11
|
+
role: I18n.t('oxaiworkers.assistant.sysop.role'),
|
12
|
+
tools: [OxAiWorkers::Tool::Eval.new]
|
13
|
+
)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
15
|
-
end
|
17
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'open3'
|
3
4
|
|
4
5
|
module OxAiWorkers::Tool
|
@@ -6,12 +7,12 @@ module OxAiWorkers::Tool
|
|
6
7
|
extend OxAiWorkers::ToolDefinition
|
7
8
|
include OxAiWorkers::DependencyHelper
|
8
9
|
|
9
|
-
define_function :ruby, description: I18n.t(
|
10
|
-
property :input, type:
|
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
|
11
12
|
end
|
12
13
|
|
13
|
-
define_function :sh, description: I18n.t(
|
14
|
-
property :input, type:
|
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
|
15
16
|
end
|
16
17
|
|
17
18
|
def ruby(input:)
|
@@ -21,8 +22,8 @@ module OxAiWorkers::Tool
|
|
21
22
|
|
22
23
|
def sh(input:)
|
23
24
|
puts Rainbow("Executing sh: \"#{input}\"").red
|
24
|
-
stdout_and_stderr_s,
|
25
|
-
|
25
|
+
stdout_and_stderr_s, = Open3.capture2e(input)
|
26
|
+
stdout_and_stderr_s
|
26
27
|
end
|
27
28
|
end
|
28
|
-
end
|
29
|
+
end
|
data/lib/oxaiworkers/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'tools/my_tool'
|
4
|
+
|
5
|
+
class MyAssistant
|
6
|
+
include OxAiWorkers::Assistant::ModuleBase
|
7
|
+
|
8
|
+
def initialize(delayed: false, model: nil)
|
9
|
+
@iterator = OxAiWorkers::Iterator.new(
|
10
|
+
worker: initWorker(delayed: delayed, model: model),
|
11
|
+
role: 'You are a helpful assistant',
|
12
|
+
tools: [MyTool.new]
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
data/template/start
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'i18n'
|
5
|
+
I18n.load_path += Dir["#{File.expand_path('.oxaiworkers-local/locales')}/*.yml"]
|
6
|
+
I18n.default_locale = :en
|
7
|
+
|
8
|
+
# Start your code here
|
9
|
+
require 'ox-ai-workers'
|
10
|
+
require 'irb'
|
11
|
+
require_relative 'my_assistant'
|
12
|
+
|
13
|
+
puts "OxAiWorkers #{OxAiWorkers::VERSION}"
|
14
|
+
|
15
|
+
OxAiWorkers.configure do |config|
|
16
|
+
config.access_token = ENV.fetch('OPENAI')
|
17
|
+
config.model = 'gpt-4o-mini'
|
18
|
+
end
|
19
|
+
|
20
|
+
@assistant = MyAssistant.new
|
21
|
+
|
22
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class MyTool
|
4
|
+
extend OxAiWorkers::ToolDefinition
|
5
|
+
include OxAiWorkers::DependencyHelper
|
6
|
+
|
7
|
+
define_function :printHello, description: 'Print hello' do
|
8
|
+
property :name, type: 'string', description: 'Your name', required: true
|
9
|
+
end
|
10
|
+
|
11
|
+
def printHello(name:)
|
12
|
+
puts "Hello #{name}"
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ox-ai-workers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: i18n
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,35 +53,35 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rainbow
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: ruby-openai
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '7'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '7'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: state_machine
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -138,6 +138,9 @@ files:
|
|
138
138
|
- lib/ruby/ox-ai-workers.rb
|
139
139
|
- locales/en.system.yml
|
140
140
|
- locales/ru.system.yml
|
141
|
+
- template/my_assistant.rb
|
142
|
+
- template/start
|
143
|
+
- template/tools/my_tool.rb
|
141
144
|
homepage: https://ai.oxteam.me
|
142
145
|
licenses:
|
143
146
|
- MIT
|
@@ -153,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
156
|
requirements:
|
154
157
|
- - ">="
|
155
158
|
- !ruby/object:Gem::Version
|
156
|
-
version: 2.
|
159
|
+
version: 2.7.0
|
157
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
161
|
requirements:
|
159
162
|
- - ">="
|