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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e563672ebb8a323e88e6254ba417bdda3f602d133fc99fcc73d366a21065f95
4
- data.tar.gz: 74c196334483c2e1d4b4222cb15ce927be00c33361c92c24f599f21cceaaf1c6
3
+ metadata.gz: 68e329b2bdf72c3b0d75acc50542f1af17bfde774f5e1ad26b4d28ae8b2eb3d4
4
+ data.tar.gz: 7e233262b802841e7a3c6241864376d5d25668391a9b482f441b47617e556703
5
5
  SHA512:
6
- metadata.gz: ac84a177aa2fc34a8540938a578cfdd6e72dfb8529e0e2ba1dc85a3761e95f7397bdd7433c0a27b140b0eed5f8a569bde42f454d628788659ec9e8999cbe98d2
7
- data.tar.gz: 007e58b6fa9b71959efde9ab05aab150df41d98857b9eb582a0858bd1156df84f05fb4e4b9d2e9c519b8445c04190478621497522bdf259551eadf7b1bc4542d
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
- - fix cli
5
- - better start script (cli: .oxaiworkers-local/start)
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
- - fix missing require 'open3'
9
- - fix Steps
10
- - cli: oxaiworkers init
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
- - Fix Delayed Requests
15
- - Configurable model, max_tokens, temperature
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
- I18n.load_path += Dir[File.expand_path("locales") + "/*.yml"] # for pure Ruby
31
- I18n.default_locale = :en # for pure Ruby
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
- # Add a response to the assistant's question.
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
- worker = OxAiWorkers::DelayedRequest.new(model: "gpt-4o-mini", max_tokens: 4096, temperature: 0.7)
46
- # or
47
- # worker = OxAiWorkers::Request.new(model: "gpt-4o-mini", max_tokens: 4096, temperature: 0.7)
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
- iterator = OxAiWorkers::Iterator.new(worker: worker, tools: [my_tool])
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
- if ARGV.first == "init"
6
- dir = '.oxaiworkers-local'
7
- dest = "#{Dir.pwd}/#{dir}"
8
- source = File.expand_path('../../', __FILE__)
6
+ puts 'Welcome to OxAiWorkers!'
9
7
 
10
- unless Dir.exist? dir
11
- FileUtils.mkdir_p dir + "/locales"
12
- FileUtils.copy_entry source + "/locales", dest + "/locales"
13
- FileUtils.cp(source+"/exe/start", dest)
14
- puts "A #{dir} directory was created with the necessary initial settings."
15
- puts "Modify the settings as needed and run:"
16
- puts "#{dir}/start"
17
- else
18
- puts "Error: The #{dir} directory already exists."
19
- end
20
- end
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
- require "i18n"
4
- I18n.load_path += Dir[File.expand_path(".oxaiworkers-local/locales") + "/*.yml"]
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 "ox-ai-workers"
9
- require "irb"
9
+ require 'ox-ai-workers'
10
+ require 'irb'
10
11
 
11
12
  puts "OxAiWorkers #{OxAiWorkers::VERSION}"
12
13
 
13
- @assistant = OxAiWorkers::Assistant::Sysop.new()
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 delayed: false, model: nil
8
+ def initialize(delayed: false, model: nil)
7
9
  @iterator = OxAiWorkers::Iterator.new(
8
- worker: initWorker(delayed: delayed, model: model),
9
- role: I18n.t("oxaiworkers.assistant.sysop.role"),
10
- tools: [OxAiWorkers::Tool::Eval.new]
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("oxaiworkers.tool.eval.ruby.description") do
10
- property :input, type: "string", description: I18n.t("oxaiworkers.tool.eval.ruby.input"), required: true
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("oxaiworkers.tool.eval.sh.description") do
14
- property :input, type: "string", description: I18n.t("oxaiworkers.tool.eval.sh.input"), required: true
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, _ = Open3.capture2e(input)
25
- return stdout_and_stderr_s
25
+ stdout_and_stderr_s, = Open3.capture2e(input)
26
+ stdout_and_stderr_s
26
27
  end
27
28
  end
28
- end
29
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OxAiWorkers
4
- VERSION = "0.2.2"
4
+ VERSION = '0.2.4'
5
5
  end
6
-
@@ -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.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-29 00:00:00.000000000 Z
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: state_machine
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: ruby-openai
56
+ name: rainbow
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '7'
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: '7'
68
+ version: '3'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rainbow
70
+ name: ruby-openai
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3'
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: '3'
82
+ version: '7'
83
83
  - !ruby/object:Gem::Dependency
84
- name: i18n
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.6.0
159
+ version: 2.7.0
157
160
  required_rubygems_version: !ruby/object:Gem::Requirement
158
161
  requirements:
159
162
  - - ">="