ruby_bots 0.0.1 → 0.0.2

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: 31af013343283ed662eea6678279251ccbd7bda130b8633f05c173cb6186fa62
4
- data.tar.gz: b273bf6290b5c5b2cc00b2abf139b70393f5ee804a9b1e8e161a6f302a8d5c52
3
+ metadata.gz: 97bf25557fb288a1416c47c9e3e566e437c04c5d2c19fedab06ae83837e24408
4
+ data.tar.gz: 26bb0781e3d5c2580b385539ae041eda38fb6ce2d323df20e80260780df78b88
5
5
  SHA512:
6
- metadata.gz: cecf81c9e2d26a1f07fca2188c5f30230fd75b0040f5632b0f63416d4d177db97694ad0a66a11e084f3306772987ffa14785025ec6761503a7bfbd62413294b6
7
- data.tar.gz: f2007a6dfbace71b3747cbe503c36fc45337806e71aa213a2fd00595f494bb431da266aa6320356801f8bc475fe13291cfb7936fc4fdb7b51946c8ab9394a7f8
6
+ metadata.gz: 7cefa94ef3b53ea79d46d39fb8256a3d96e96db852f45ae51feed2c58e0826fd2ba536acb43a1c801fdae83de8694be7f30e9e6541c344228d4bda1cac4dcbf7
7
+ data.tar.gz: 2b2afd2c55c6878d52a5d9675bbcfc39b90a6df8374482fc06e762c68dec48afd88bf5282a36aa48859e77ec5697b7911e8a755fe5367d29734424225da701b7
@@ -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.2".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.2
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