ruby_bots 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 31af013343283ed662eea6678279251ccbd7bda130b8633f05c173cb6186fa62
4
+ data.tar.gz: b273bf6290b5c5b2cc00b2abf139b70393f5ee804a9b1e8e161a6f302a8d5c52
5
+ SHA512:
6
+ metadata.gz: cecf81c9e2d26a1f07fca2188c5f30230fd75b0040f5632b0f63416d4d177db97694ad0a66a11e084f3306772987ffa14785025ec6761503a7bfbd62413294b6
7
+ data.tar.gz: f2007a6dfbace71b3747cbe503c36fc45337806e71aa213a2fd00595f494bb431da266aa6320356801f8bc475fe13291cfb7936fc4fdb7b51946c8ab9394a7f8
@@ -0,0 +1,14 @@
1
+ module RubyBots
2
+ class Bot < Tool
3
+ attr_accessor :tools
4
+
5
+ def initialize(tools:, **kwargs)
6
+ @tools = tools
7
+ super(**kwargs)
8
+ end
9
+
10
+ def operate(inputs)
11
+ raise NotImplementedError
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module RubyBots
2
+ class OpenAIBot < OpenAITool
3
+ attr_accessor :tools
4
+
5
+ DEFAULT_DESCRIPTION = "This bot will use OpenAI to determine the appropriate tool."
6
+
7
+ def initialize(name: "OpenAI bot", description: DEFAULT_DESCRIPTION, tools:)
8
+ @name = name
9
+ @description = description
10
+ @tools = tools
11
+ end
12
+
13
+ def operate(inputs)
14
+ params = {
15
+ messages: [
16
+ { role: :system, content: system_instructions },
17
+ { role: :user, content: inputs }
18
+ ]
19
+ }.merge(default_params)
20
+
21
+ response = client.chat(parameters: params)
22
+
23
+ response.dig("choices", 0, "message", "content")
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ module RubyBots
2
+ class PipelineBot < Bot
3
+ DEFAULT_DESCRIPTION = "This bot will utilize all of its tools in a syncronouse pipeline based on the order the tools are provided."
4
+
5
+ def initialize(name: "Pipeline bot", decription: DEFAULT_DESCRIPTION, tools:)
6
+ @name = name
7
+ @description = description
8
+ @tools = tools
9
+ end
10
+
11
+ def operate(inputs)
12
+ tools.each do |tool|
13
+ inputs = tool.operate(inputs)
14
+ end
15
+
16
+ inputs
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ module RubyBots
2
+ class RouterBot < OpenAIBot
3
+ DEFAULT_DESCRIPTION = "This bot will route the user's input to the appropriate tool. It will only select and use one tool."
4
+
5
+ def initialize(name: "Router bot", decription: DEFAULT_DESCRIPTION, tools:)
6
+ @name = name
7
+ @description = description
8
+ @tools = tools
9
+ end
10
+
11
+ def system_instructions
12
+ <<~PROMPT
13
+ You are an assistant helping to route a user's input to the correct tool.
14
+ You can use the following tools (name - description):
15
+ #{tools.map{|t| t.name + " - " + t.description}.join("\n")}
16
+
17
+ Return only the name of the tool that best fits the user's request.
18
+ If no tools match the user's request respond with "I'm sorry, I am still learning." and nothing more.
19
+ PROMPT
20
+ end
21
+
22
+ def operate(inputs)
23
+ params = {
24
+ messages: [
25
+ { role: :system, content: system_instructions },
26
+ { role: :user, content: inputs }
27
+ ]
28
+ }.merge(default_params)
29
+
30
+ response = client.chat(parameters: params)
31
+
32
+ response_text = response.dig("choices", 0, "message", "content")
33
+ selected_tool = tools.find{|t| t.name == response_text}
34
+ if selected_tool
35
+ selected_tool.operate(inputs)
36
+ else
37
+ response_text
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,23 @@
1
+ module RubyBots
2
+ class Tool
3
+ attr_accessor :name, :description
4
+
5
+ def initialize(name:, description:)
6
+ @name = name
7
+ @description = description
8
+ end
9
+
10
+ def validate_inputs(inputs)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def run(inputs)
15
+ raise NotImplementedError
16
+ end
17
+
18
+ def response(inputs)
19
+ validate_inputs(inputs)
20
+ run(inputs)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ require 'openai'
2
+
3
+ module RubyBots
4
+ class OpenAITool < Tool
5
+ attr_accessor :name, :description
6
+
7
+ DEFAULT_DESCRIPTION = "This tool will use open ai to determine the output."
8
+
9
+ def initialize(name: "OpenAI Tool", description: DEFAULT_DESCRIPTION)
10
+ @name = name
11
+ @description = description
12
+ end
13
+
14
+ def client
15
+ @client ||= OpenAI::Client.new(access_token: ENV["OPENAI_ACCESS_TOKEN"])
16
+ end
17
+
18
+ def default_params
19
+ {
20
+ model: 'gpt-4',
21
+ temperature: 0
22
+ }
23
+ end
24
+
25
+ def system_instructions
26
+ "You are a helpful assistant."
27
+ end
28
+
29
+ def operate(inputs)
30
+ params = {
31
+ messages: [
32
+ { role: :system, content: system_instructions },
33
+ { role: :user, content: inputs }
34
+ ]
35
+ }.merge(default_params)
36
+
37
+ response = client.chat(parameters: params)
38
+
39
+ response.dig("choices", 0, "message", "content")
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module RubyBots
2
+ VERSION = "0.0.1".freeze
3
+ end
data/lib/ruby_bots.rb ADDED
@@ -0,0 +1,20 @@
1
+ module RubyBots
2
+ class << self
3
+ end
4
+
5
+ def self.bot
6
+ RubyBots::Bot
7
+ end
8
+
9
+ def self.tool
10
+ RubyBots::Tool
11
+ end
12
+ end
13
+
14
+ require "ruby_bots/tool"
15
+ require "ruby_bots/bot"
16
+ # require "ruby_bots/version"
17
+ # require "ruby_bots/bots/openai_bot.rb"
18
+ # require "ruby_bots/bots/pipeline_bot.rb"
19
+ # require "ruby_bots/bots/router_bot.rb"
20
+ # require "ruby_bots/tools/openai_tool.rb"
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_bots
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Paulson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: google_search_results
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: ruby-openai
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Bots can use different tools to solve any number of tasks. Bots can be
84
+ powered by OpenAI.
85
+ email:
86
+ - jpaulson@aha.io
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - lib/ruby_bots.rb
92
+ - lib/ruby_bots/bot.rb
93
+ - lib/ruby_bots/bots/openai_bot.rb
94
+ - lib/ruby_bots/bots/pipeline_bot.rb
95
+ - lib/ruby_bots/bots/router_bot.rb
96
+ - lib/ruby_bots/tool.rb
97
+ - lib/ruby_bots/tools/openai_tool.rb
98
+ - lib/ruby_bots/version.rb
99
+ homepage: https://github.com/aha-app/ruby_bots
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ homepage_uri: https://github.com/aha-app/ruby_bots
104
+ source_code_uri: https://github.com/aha-app/ruby_bots
105
+ changelog_uri: https://github.com/aha-app/ruby_bots
106
+ rubygems_mfa_required: 'true'
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: 2.6.0
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.3.26
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Ruby Bots lets you create tools and bots to complete tasks. Inspired by python
126
+ langchain.
127
+ test_files: []