ox-ai-workers 0.3.2 → 0.4.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 +9 -0
- data/exe/oxaiworkers +0 -1
- data/lib/ox-ai-workers.rb +4 -0
- data/lib/oxaiworkers/assistant/coder.rb +21 -0
- data/lib/oxaiworkers/assistant/module_base.rb +15 -15
- data/lib/oxaiworkers/assistant/sysop.rb +2 -2
- data/lib/oxaiworkers/module_request.rb +2 -2
- data/lib/oxaiworkers/tool/database.rb +119 -0
- data/lib/oxaiworkers/tool/eval.rb +7 -7
- data/lib/oxaiworkers/tool/file_system.rb +66 -0
- data/lib/oxaiworkers/version.rb +1 -1
- data/locales/en.assistant.yml +3 -1
- data/locales/en.tool.yml +23 -1
- data/locales/ru.assistant.yml +2 -0
- data/locales/ru.tool.yml +22 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec4ac0192d833a4e69e1fb10138d2668ea67d36aed5dd5de59b5a0046a08b38e
|
4
|
+
data.tar.gz: f1de881044ac1389e781cb59816b2ea8f1c36d0c00340f770c486fb622467b9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 780a288aa72d7b548eb8ebe64067d7b79a5d354855f3f1912afa5843a3190c78d40803ca73d1a4be0aa95dab7ca26ad3fc72106642fd24d76a2a39dc3985617f
|
7
|
+
data.tar.gz: 492959e288c68c01d786c5be0bd87ed88f6d6b77b9efa22a623d7283b6560dfa55a3e10f280f659502b158ec848da23f654560810fdfc9c6fa7af0272733152b
|
data/CHANGELOG.md
CHANGED
data/exe/oxaiworkers
CHANGED
data/lib/ox-ai-workers.rb
CHANGED
@@ -19,10 +19,14 @@ require_relative 'oxaiworkers/delayed_request'
|
|
19
19
|
require_relative 'oxaiworkers/dependency_helper'
|
20
20
|
require_relative 'oxaiworkers/iterator'
|
21
21
|
require_relative 'oxaiworkers/request'
|
22
|
+
|
22
23
|
require_relative 'oxaiworkers/tool/eval'
|
24
|
+
require_relative 'oxaiworkers/tool/database'
|
25
|
+
require_relative 'oxaiworkers/tool/file_system'
|
23
26
|
|
24
27
|
require_relative 'oxaiworkers/assistant/module_base'
|
25
28
|
require_relative 'oxaiworkers/assistant/sysop'
|
29
|
+
require_relative 'oxaiworkers/assistant/coder'
|
26
30
|
|
27
31
|
module OxAiWorkers
|
28
32
|
DEFAULT_MODEL = 'gpt-4o-mini'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OxAiWorkers
|
4
|
+
module Assistant
|
5
|
+
class Coder
|
6
|
+
include OxAiWorkers::Assistant::ModuleBase
|
7
|
+
|
8
|
+
def initialize(delayed: false, model: nil, language: 'ruby')
|
9
|
+
@iterator = Iterator.new(
|
10
|
+
worker: initWorker(delayed: delayed, model: model),
|
11
|
+
role: format(I18n.t('oxaiworkers.assistant.coder.role'), language),
|
12
|
+
tools: [Tool::Eval.new, Tool::FileSystem.new],
|
13
|
+
on_inner_monologue: ->(text:) { puts Rainbow("monologue: #{text}").yellow },
|
14
|
+
on_outer_voice: ->(text:) { puts Rainbow("voice: #{text}").green },
|
15
|
+
on_action_request: ->(text:) { puts Rainbow("action: #{text}").red },
|
16
|
+
on_pack_history: ->(text:) { puts Rainbow("summary: #{text}").blue }
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module OxAiWorkers
|
2
2
|
module Assistant
|
3
3
|
module ModuleBase
|
4
|
-
|
5
|
-
|
6
|
-
def setTask task
|
7
|
-
@iterator.cleanup()
|
8
|
-
@iterator.addTask task
|
9
|
-
end
|
4
|
+
attr_accessor :iterator
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
def setTask(task)
|
7
|
+
@iterator.cleanup
|
8
|
+
@iterator.addTask task
|
9
|
+
end
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
def addResponse(text)
|
12
|
+
@iterator.addTask text
|
13
|
+
end
|
14
|
+
|
15
|
+
def initWorker(delayed:, model:)
|
16
|
+
worker = delayed ? DelayedRequest.new : Request.new
|
17
|
+
worker.model = model || OxAiWorkers.configuration.model
|
18
|
+
worker
|
19
|
+
end
|
20
20
|
end
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
@@ -6,10 +6,10 @@ module OxAiWorkers
|
|
6
6
|
include OxAiWorkers::Assistant::ModuleBase
|
7
7
|
|
8
8
|
def initialize(delayed: false, model: nil)
|
9
|
-
@iterator =
|
9
|
+
@iterator = Iterator.new(
|
10
10
|
worker: initWorker(delayed: delayed, model: model),
|
11
11
|
role: I18n.t('oxaiworkers.assistant.sysop.role'),
|
12
|
-
tools: [
|
12
|
+
tools: [Tool::Eval.new],
|
13
13
|
on_inner_monologue: ->(text:) { puts Rainbow("monologue: #{text}").yellow },
|
14
14
|
on_outer_voice: ->(text:) { puts Rainbow("voice: #{text}").green },
|
15
15
|
on_action_request: ->(text:) { puts Rainbow("action: #{text}").red },
|
@@ -6,7 +6,7 @@ module OxAiWorkers
|
|
6
6
|
:tool_calls_raw, :tool_calls
|
7
7
|
|
8
8
|
def initializeRequests(model: nil, max_tokens: nil, temperature: nil)
|
9
|
-
puts "call: ModuleRequest::#{__method__}"
|
9
|
+
# puts "call: ModuleRequest::#{__method__}"
|
10
10
|
@max_tokens = max_tokens || OxAiWorkers.configuration.max_tokens
|
11
11
|
@custom_id = SecureRandom.uuid
|
12
12
|
@model = model || OxAiWorkers.configuration.model
|
@@ -23,7 +23,7 @@ module OxAiWorkers
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def cleanup
|
26
|
-
puts "call: ModuleRequest::#{__method__}"
|
26
|
+
# puts "call: ModuleRequest::#{__method__}"
|
27
27
|
@client ||= OpenAI::Client.new(
|
28
28
|
access_token: OxAiWorkers.configuration.access_token,
|
29
29
|
log_errors: true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production because it could leak private data to your logs.
|
@@ -0,0 +1,119 @@
|
|
1
|
+
module OxAiWorkers
|
2
|
+
module Tool
|
3
|
+
#
|
4
|
+
# Connects to a database, executes SQL queries, and outputs DB schema for Agents to use
|
5
|
+
#
|
6
|
+
# Gem requirements:
|
7
|
+
# gem "sequel", "~> 5.68.0"
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
# database = OxAiWorkers::Tool::Database.new(connection_string: "postgres://user:password@localhost:5432/db_name")
|
11
|
+
#
|
12
|
+
class Database
|
13
|
+
extend OxAiWorkers::ToolDefinition
|
14
|
+
include OxAiWorkers::DependencyHelper
|
15
|
+
|
16
|
+
define_function :list_tables,
|
17
|
+
description: I18n.t('oxaiworkers.tool.database_tool.list_tables.description')
|
18
|
+
|
19
|
+
define_function :describe_tables,
|
20
|
+
description: I18n.t('oxaiworkers.tool.database_tool.describe_tables.description') do
|
21
|
+
property :tables, type: 'string',
|
22
|
+
description: I18n.t('oxaiworkers.tool.database_tool.describe_tables.tables'),
|
23
|
+
required: true
|
24
|
+
end
|
25
|
+
|
26
|
+
define_function :dump_schema,
|
27
|
+
description: I18n.t('oxaiworkers.tool.database_tool.dump_schema.description')
|
28
|
+
|
29
|
+
define_function :execute,
|
30
|
+
description: I18n.t('oxaiworkers.tool.database_tool.execute.description') do
|
31
|
+
property :input, type: 'string',
|
32
|
+
description: I18n.t('oxaiworkers.tool.database_tool.execute.input'),
|
33
|
+
required: true
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_reader :db, :requested_tables, :excluded_tables
|
37
|
+
|
38
|
+
# Establish a database connection
|
39
|
+
#
|
40
|
+
# @param connection_string [String] Database connection info, e.g. 'postgres://user:password@localhost:5432/db_name'
|
41
|
+
# @param tables [Array<Symbol>] The tables to use. Will use all if empty.
|
42
|
+
# @param except_tables [Array<Symbol>] The tables to exclude. Will exclude none if empty.
|
43
|
+
# @return [Database] Database object
|
44
|
+
def initialize(connection_string:, tables: [], exclude_tables: [])
|
45
|
+
depends_on 'sequel'
|
46
|
+
|
47
|
+
raise StandardError, 'connection_string parameter cannot be blank' if connection_string.empty?
|
48
|
+
|
49
|
+
@db = Sequel.connect(connection_string)
|
50
|
+
@requested_tables = tables
|
51
|
+
@excluded_tables = exclude_tables
|
52
|
+
end
|
53
|
+
|
54
|
+
# Database Tool: Returns a list of tables in the database
|
55
|
+
def list_tables
|
56
|
+
db.tables
|
57
|
+
end
|
58
|
+
|
59
|
+
# Database Tool: Returns the schema for a list of tables
|
60
|
+
#
|
61
|
+
# @param tables [String] The tables to describe.
|
62
|
+
# @return [String] Database schema for the tables
|
63
|
+
def describe_tables(tables:)
|
64
|
+
schema = ''
|
65
|
+
tables.split(',').each do |table|
|
66
|
+
describe_table(table, schema)
|
67
|
+
end
|
68
|
+
schema
|
69
|
+
end
|
70
|
+
|
71
|
+
# Database Tool: Returns the database schema
|
72
|
+
#
|
73
|
+
# @return [String] Database schema
|
74
|
+
def dump_schema
|
75
|
+
puts('Dumping schema tables and keys', for: self.class)
|
76
|
+
schema = ''
|
77
|
+
db.tables.each do |table|
|
78
|
+
describe_table(table, schema)
|
79
|
+
end
|
80
|
+
schema
|
81
|
+
end
|
82
|
+
|
83
|
+
def describe_table(table, schema)
|
84
|
+
primary_key_columns = []
|
85
|
+
primary_key_column_count = db.schema(table).count { |column| column[1][:primary_key] == true }
|
86
|
+
|
87
|
+
schema << "CREATE TABLE #{table}(\n"
|
88
|
+
db.schema(table).each do |column|
|
89
|
+
schema << "#{column[0]} #{column[1][:type]}"
|
90
|
+
if column[1][:primary_key] == true
|
91
|
+
schema << ' PRIMARY KEY' if primary_key_column_count == 1
|
92
|
+
else
|
93
|
+
primary_key_columns << column[0]
|
94
|
+
end
|
95
|
+
schema << ",\n" unless column == db.schema(table).last && primary_key_column_count == 1
|
96
|
+
end
|
97
|
+
schema << "PRIMARY KEY (#{primary_key_columns.join(',')})" if primary_key_column_count > 1
|
98
|
+
db.foreign_key_list(table).each do |fk|
|
99
|
+
schema << ",\n" if fk == db.foreign_key_list(table).first
|
100
|
+
schema << "FOREIGN KEY (#{fk[:columns][0]}) REFERENCES #{fk[:table]}(#{fk[:key][0]})"
|
101
|
+
schema << ",\n" unless fk == db.foreign_key_list(table).last
|
102
|
+
end
|
103
|
+
schema << ");\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
# Database Tool: Executes a SQL query and returns the results
|
107
|
+
#
|
108
|
+
# @param input [String] SQL query to be executed
|
109
|
+
# @return [Array] Results from the SQL query
|
110
|
+
def execute(input:)
|
111
|
+
puts("Executing \"#{input}\"", for: self.class)
|
112
|
+
|
113
|
+
db[input].to_a
|
114
|
+
rescue Sequel::DatabaseError => e
|
115
|
+
e.message
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -8,18 +8,18 @@ module OxAiWorkers
|
|
8
8
|
extend OxAiWorkers::ToolDefinition
|
9
9
|
include OxAiWorkers::DependencyHelper
|
10
10
|
|
11
|
-
define_function :ruby, description: I18n.t('oxaiworkers.tool.eval.ruby.description') do
|
12
|
-
|
13
|
-
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
|
14
14
|
|
15
15
|
define_function :sh, description: I18n.t('oxaiworkers.tool.eval.sh.description') do
|
16
16
|
property :input, type: 'string', description: I18n.t('oxaiworkers.tool.eval.sh.input'), required: true
|
17
17
|
end
|
18
18
|
|
19
|
-
def ruby(input:)
|
20
|
-
|
21
|
-
|
22
|
-
end
|
19
|
+
# def ruby(input:)
|
20
|
+
# puts Rainbow("Executing ruby: \"#{input}\"").red
|
21
|
+
# eval(input)
|
22
|
+
# end
|
23
23
|
|
24
24
|
def sh(input:)
|
25
25
|
puts Rainbow("Executing sh: \"#{input}\"").red
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ptools'
|
4
|
+
|
5
|
+
module OxAiWorkers
|
6
|
+
module Tool
|
7
|
+
#
|
8
|
+
# A tool that wraps the Ruby file system classes.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
# file_system = OxAiWorkers::Tool::FileSystem.new
|
12
|
+
#
|
13
|
+
class FileSystem
|
14
|
+
extend OxAiWorkers::ToolDefinition
|
15
|
+
|
16
|
+
define_function :list_directory,
|
17
|
+
description: I18n.t('oxaiworkers.tool.file_system.list_directory.description') do
|
18
|
+
property :directory_path, type: 'string',
|
19
|
+
description: I18n.t('oxaiworkers.tool.file_system.list_directory.directory_path'),
|
20
|
+
required: true
|
21
|
+
end
|
22
|
+
|
23
|
+
define_function :read_file, description: I18n.t('oxaiworkers.tool.file_system.read_file.description') do
|
24
|
+
property :file_path, type: 'string', description: I18n.t('oxaiworkers.tool.file_system.read_file.file_path'),
|
25
|
+
required: true
|
26
|
+
end
|
27
|
+
|
28
|
+
define_function :write_to_file, description: I18n.t('oxaiworkers.tool.file_system.write_to_file.description') do
|
29
|
+
property :file_path, type: 'string',
|
30
|
+
description: I18n.t('oxaiworkers.tool.file_system.write_to_file.file_path'), required: true
|
31
|
+
property :content, type: 'string', description: I18n.t('oxaiworkers.tool.file_system.write_to_file.content'),
|
32
|
+
required: true
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize
|
36
|
+
depends_on 'ptools'
|
37
|
+
end
|
38
|
+
|
39
|
+
def list_directory(directory_path:)
|
40
|
+
puts Rainbow("Listing directory: #{directory_path}").magenta
|
41
|
+
Dir.entries(directory_path)
|
42
|
+
rescue Errno::ENOENT
|
43
|
+
"No such directory: #{directory_path}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def read_file(file_path:)
|
47
|
+
puts Rainbow("Reading file: #{file_path}").magenta
|
48
|
+
if File.binary?(file)
|
49
|
+
"File is binary: #{file_path}"
|
50
|
+
else
|
51
|
+
File.read(file_path).to_s
|
52
|
+
end
|
53
|
+
rescue Errno::ENOENT
|
54
|
+
"No such file: #{file_path}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def write_to_file(file_path:, content:)
|
58
|
+
puts Rainbow("Writing to file: #{file_path}").magenta
|
59
|
+
File.write(file_path, content)
|
60
|
+
"Content was successfully written to the file: #{file_path}"
|
61
|
+
rescue Errno::EACCES
|
62
|
+
"Permission denied: #{file_path}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/oxaiworkers/version.rb
CHANGED
data/locales/en.assistant.yml
CHANGED
data/locales/en.tool.yml
CHANGED
@@ -7,4 +7,26 @@ en:
|
|
7
7
|
input: "Ruby source code"
|
8
8
|
sh:
|
9
9
|
description: "Execute a sh command and get the result (stdout + stderr)"
|
10
|
-
input: "Source command"
|
10
|
+
input: "Source command"
|
11
|
+
file_system:
|
12
|
+
list_directory:
|
13
|
+
description: 'File System Tool: Lists out the content of a specified directory'
|
14
|
+
directory_path: 'Directory path to list'
|
15
|
+
read_file:
|
16
|
+
description: 'File System Tool: Reads the contents of a text file'
|
17
|
+
file_path: 'Path to the file to read from'
|
18
|
+
write_to_file:
|
19
|
+
description: 'File System Tool: Write content to a file'
|
20
|
+
file_path: 'Path to the file to write'
|
21
|
+
content: 'Content to write to the file'
|
22
|
+
database_tool:
|
23
|
+
list_tables:
|
24
|
+
description: 'Database Tool: Returns a list of tables in the database'
|
25
|
+
describe_tables:
|
26
|
+
description: 'Database Tool: Returns the schema for a list of tables'
|
27
|
+
tables: 'The tables to describe'
|
28
|
+
dump_schema:
|
29
|
+
description: 'Database Tool: Returns the database schema'
|
30
|
+
execute:
|
31
|
+
description: 'Database Tool: Executes a SQL query and returns the results'
|
32
|
+
input: 'SQL query to be executed'
|
data/locales/ru.assistant.yml
CHANGED
data/locales/ru.tool.yml
CHANGED
@@ -8,3 +8,25 @@ ru:
|
|
8
8
|
sh:
|
9
9
|
description: Выполнить sh-команду и получить результат (stdout + stderr)
|
10
10
|
input: Исходная команда
|
11
|
+
file_system:
|
12
|
+
list_directory:
|
13
|
+
description: 'Инструмент файловой системы: Выводит содержимое указанного каталога'
|
14
|
+
directory_path: 'Путь к каталогу для вывода содержимого'
|
15
|
+
read_file:
|
16
|
+
description: 'Инструмент файловой системы: Считывает содержимое текстового файла'
|
17
|
+
file_path: 'Путь к файлу для считывания'
|
18
|
+
write_to_file:
|
19
|
+
description: 'Инструмент файловой системы: Записывает содержимое в файл'
|
20
|
+
file_path: 'Путь к файлу для записи'
|
21
|
+
content: 'Содержимое для записи в файл'
|
22
|
+
database_tool:
|
23
|
+
list_tables:
|
24
|
+
description: 'Инструмент базы данных: Возвращает список таблиц в базе данных'
|
25
|
+
describe_tables:
|
26
|
+
description: 'Инструмент базы данных: Возвращает схему для списка таблиц'
|
27
|
+
tables: 'Таблицы для описания'
|
28
|
+
dump_schema:
|
29
|
+
description: 'Инструмент базы данных: Возвращает схему базы данных'
|
30
|
+
execute:
|
31
|
+
description: 'Инструмент базы данных: Выполняет SQL-запрос и возвращает результаты'
|
32
|
+
input: 'SQL-запрос для выполнения'
|
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.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Smolev
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- exe/oxaiworkers
|
121
121
|
- exe/start
|
122
122
|
- lib/ox-ai-workers.rb
|
123
|
+
- lib/oxaiworkers/assistant/coder.rb
|
123
124
|
- lib/oxaiworkers/assistant/module_base.rb
|
124
125
|
- lib/oxaiworkers/assistant/sysop.rb
|
125
126
|
- lib/oxaiworkers/compatibility.rb
|
@@ -133,7 +134,9 @@ files:
|
|
133
134
|
- lib/oxaiworkers/state_batch.rb
|
134
135
|
- lib/oxaiworkers/state_helper.rb
|
135
136
|
- lib/oxaiworkers/state_tools.rb
|
137
|
+
- lib/oxaiworkers/tool/database.rb
|
136
138
|
- lib/oxaiworkers/tool/eval.rb
|
139
|
+
- lib/oxaiworkers/tool/file_system.rb
|
137
140
|
- lib/oxaiworkers/tool_definition.rb
|
138
141
|
- lib/oxaiworkers/version.rb
|
139
142
|
- lib/ruby/ox-ai-workers.rb
|