ruby_bots 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31af013343283ed662eea6678279251ccbd7bda130b8633f05c173cb6186fa62
4
- data.tar.gz: b273bf6290b5c5b2cc00b2abf139b70393f5ee804a9b1e8e161a6f302a8d5c52
3
+ metadata.gz: 656073bfe550e5be358a7189a137acd2fab90279f46a1d9c44899dddd022f844
4
+ data.tar.gz: 28bf1c1005c95aed8cb5f319c012a6ea4c54c8c1e2b5d9941af88bc6841eb9e3
5
5
  SHA512:
6
- metadata.gz: cecf81c9e2d26a1f07fca2188c5f30230fd75b0040f5632b0f63416d4d177db97694ad0a66a11e084f3306772987ffa14785025ec6761503a7bfbd62413294b6
7
- data.tar.gz: f2007a6dfbace71b3747cbe503c36fc45337806e71aa213a2fd00595f494bb431da266aa6320356801f8bc475fe13291cfb7936fc4fdb7b51946c8ab9394a7f8
6
+ metadata.gz: 3338bbd983626a62f6448ba4631a940932c2639abb00fb4e109ef47b2ad7b5f777371321f94b42f1ee6be510964a951f8ac8d181c6f953023ae2fb34c1ab334c
7
+ data.tar.gz: 1fb67357ceac7f6ceafeb0737a54e138e25350b79fc2aefc08278a9d1b83c4db391e4da669c53a390928cf56289c200ad943a86b8482a6362735857c8e04eb9b
@@ -2,24 +2,25 @@ module RubyBots
2
2
  class OpenAIBot < OpenAITool
3
3
  attr_accessor :tools
4
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)
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
20
 
21
- response = client.chat(parameters: params)
21
+ response = client.chat(parameters: params)
22
22
 
23
- response.dig("choices", 0, "message", "content")
23
+ response.dig("choices", 0, "message", "content")
24
+ end
24
25
  end
25
26
  end
@@ -1,23 +1,37 @@
1
1
  module RubyBots
2
2
  class Tool
3
- attr_accessor :name, :description
3
+ attr_accessor :name, :description, :errors
4
4
 
5
5
  def initialize(name:, description:)
6
6
  @name = name
7
7
  @description = description
8
+ @errors = []
9
+ @input_validators = []
10
+ @output_validators = []
8
11
  end
9
12
 
10
- def validate_inputs(inputs)
11
- raise NotImplementedError
13
+ def validate_inputs(method)
14
+ @input_validators << method
15
+ end
16
+
17
+ def validate_outputs(method)
18
+ @output_validators << method
12
19
  end
13
20
 
14
21
  def run(inputs)
15
22
  raise NotImplementedError
16
23
  end
17
24
 
18
- def response(inputs)
19
- validate_inputs(inputs)
20
- run(inputs)
25
+ def response(input)
26
+ @input_validators.each do |validator|
27
+ validator.call(input)
28
+ end
29
+
30
+ output = run(input)
31
+
32
+ @output_validators.each do |validator|
33
+ validator.call(output)
34
+ end
21
35
  end
22
36
  end
23
37
  end
@@ -2,7 +2,7 @@ require 'openai'
2
2
 
3
3
  module RubyBots
4
4
  class OpenAITool < Tool
5
- attr_accessor :name, :description
5
+ validate_inputs :input_is_json
6
6
 
7
7
  DEFAULT_DESCRIPTION = "This tool will use open ai to determine the output."
8
8
 
@@ -38,5 +38,11 @@ module RubyBots
38
38
 
39
39
  response.dig("choices", 0, "message", "content")
40
40
  end
41
+
42
+ def input_is_json(input)
43
+ JSON.parse(input)
44
+ rescue JSON::ParserError
45
+ errors.add(:input, "must be valid JSON")
46
+ end
41
47
  end
42
48
  end
@@ -1,3 +1,3 @@
1
1
  module RubyBots
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.3".freeze
3
3
  end
data/lib/ruby_bots.rb CHANGED
@@ -9,12 +9,15 @@ module RubyBots
9
9
  def self.tool
10
10
  RubyBots::Tool
11
11
  end
12
+
13
+ class Error < StandardError; end
14
+ class InvalidInputError < Error; end
15
+ class InvalidOutputError < Error; end
12
16
  end
13
17
 
14
18
  require "ruby_bots/tool"
15
19
  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"
20
+ require "ruby_bots/bots/openai_bot.rb"
21
+ require "ruby_bots/bots/pipeline_bot.rb"
22
+ require "ruby_bots/bots/router_bot.rb"
23
+ require "ruby_bots/tools/openai_tool.rb"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_bots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Paulson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-31 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debug