ruby_bots 0.0.4 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_bots/bot.rb +1 -1
- data/lib/ruby_bots/bots/openai_bot.rb +1 -1
- data/lib/ruby_bots/bots/pipeline_bot.rb +3 -3
- data/lib/ruby_bots/bots/router_bot.rb +2 -2
- data/lib/ruby_bots/tool.rb +7 -5
- data/lib/ruby_bots/tools/openai_tool.rb +3 -4
- data/lib/ruby_bots/version.rb +1 -1
- data/lib/ruby_bots.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ae9e0cefac2b636d7dcb5e1627638ba1dd0a65193001cbe6ed143cca929bf86
|
4
|
+
data.tar.gz: e86443e3e76810dfb478f04f1727854aa4c698fdcae7d449c2181546ab4c0c3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7f38b981264422dfedab32092b4afe7ccf11fcf3beffe281d96e1f946d2737ed72b502d7fbd1fc3486430158d54298e97546f1676944209c85b6e4ec824c540
|
7
|
+
data.tar.gz: 2b7067d0f1638c7553b062d94362354d59082c4c5fd545005e1e47f80a21d8d4159c18a4688816b43b71e614043ced82dfea82af308560996e7cad4e2ec21fd1
|
data/lib/ruby_bots/bot.rb
CHANGED
@@ -2,15 +2,15 @@ module RubyBots
|
|
2
2
|
class PipelineBot < Bot
|
3
3
|
DEFAULT_DESCRIPTION = "This bot will utilize all of its tools in a syncronouse pipeline based on the order the tools are provided."
|
4
4
|
|
5
|
-
def initialize(name: "Pipeline bot",
|
5
|
+
def initialize(name: "Pipeline bot", description: DEFAULT_DESCRIPTION, tools:)
|
6
6
|
@name = name
|
7
7
|
@description = description
|
8
8
|
@tools = tools
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def run(inputs)
|
12
12
|
tools.each do |tool|
|
13
|
-
inputs = tool.
|
13
|
+
inputs = tool.run(inputs)
|
14
14
|
end
|
15
15
|
|
16
16
|
inputs
|
@@ -19,7 +19,7 @@ module RubyBots
|
|
19
19
|
PROMPT
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def run(inputs)
|
23
23
|
params = {
|
24
24
|
messages: [
|
25
25
|
{ role: :system, content: system_instructions },
|
@@ -32,7 +32,7 @@ module RubyBots
|
|
32
32
|
response_text = response.dig("choices", 0, "message", "content")
|
33
33
|
selected_tool = tools.find{|t| t.name == response_text}
|
34
34
|
if selected_tool
|
35
|
-
selected_tool.
|
35
|
+
selected_tool.response(inputs)
|
36
36
|
else
|
37
37
|
response_text
|
38
38
|
end
|
data/lib/ruby_bots/tool.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
module RubyBots
|
2
2
|
class Tool
|
3
3
|
attr_accessor :name, :description, :errors
|
4
|
-
|
4
|
+
|
5
5
|
def initialize(name:, description:)
|
6
6
|
@name = name
|
7
7
|
@description = description
|
8
8
|
@errors = []
|
9
|
-
@input_validators
|
10
|
-
@output_validators
|
9
|
+
@input_validators ||= []
|
10
|
+
@output_validators ||= []
|
11
11
|
end
|
12
12
|
|
13
|
-
def validate_inputs(method)
|
13
|
+
def self.validate_inputs(method)
|
14
|
+
@input_validators ||= []
|
14
15
|
@input_validators << method
|
15
16
|
end
|
16
17
|
|
17
|
-
def validate_outputs(method)
|
18
|
+
def self.validate_outputs(method)
|
19
|
+
@output_validators ||= []
|
18
20
|
@output_validators << method
|
19
21
|
end
|
20
22
|
|
@@ -7,12 +7,11 @@ module RubyBots
|
|
7
7
|
DEFAULT_DESCRIPTION = "This tool will use open ai to determine the output."
|
8
8
|
|
9
9
|
def initialize(name: "OpenAI Tool", description: DEFAULT_DESCRIPTION)
|
10
|
-
|
11
|
-
@description = description
|
10
|
+
super(name: name, description: description)
|
12
11
|
end
|
13
12
|
|
14
13
|
def client
|
15
|
-
@client ||= OpenAI::Client.new(access_token:
|
14
|
+
@client ||= OpenAI::Client.new(access_token: RubyBots.config.openai_api_key)
|
16
15
|
end
|
17
16
|
|
18
17
|
def default_params
|
@@ -26,7 +25,7 @@ module RubyBots
|
|
26
25
|
"You are a helpful assistant."
|
27
26
|
end
|
28
27
|
|
29
|
-
def
|
28
|
+
def run(inputs)
|
30
29
|
params = {
|
31
30
|
messages: [
|
32
31
|
{ role: :system, content: system_instructions },
|
data/lib/ruby_bots/version.rb
CHANGED
data/lib/ruby_bots.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
module RubyBots
|
2
2
|
class << self
|
3
|
+
def config
|
4
|
+
@config ||= Configuration.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def configure
|
8
|
+
yield config
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Configuration
|
13
|
+
attr_accessor :openai_api_key
|
14
|
+
def initialize()
|
15
|
+
@openai_api_key = ENV["OPENAI_ACCESS_TOKEN"]
|
16
|
+
end
|
3
17
|
end
|
4
18
|
|
5
19
|
def self.bot
|