ruby_bots 0.0.1 → 0.0.3
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/lib/ruby_bots/bots/openai_bot.rb +18 -17
- data/lib/ruby_bots/tool.rb +20 -6
- data/lib/ruby_bots/tools/openai_tool.rb +7 -1
- data/lib/ruby_bots/version.rb +1 -1
- data/lib/ruby_bots.rb +8 -5
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 656073bfe550e5be358a7189a137acd2fab90279f46a1d9c44899dddd022f844
         | 
| 4 | 
            +
              data.tar.gz: 28bf1c1005c95aed8cb5f319c012a6ea4c54c8c1e2b5d9941af88bc6841eb9e3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
            -
             | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 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 | 
            -
             | 
| 21 | 
            +
                  response = client.chat(parameters: params)
         | 
| 22 22 |  | 
| 23 | 
            -
             | 
| 23 | 
            +
                  response.dig("choices", 0, "message", "content")
         | 
| 24 | 
            +
                end
         | 
| 24 25 | 
             
              end
         | 
| 25 26 | 
             
            end
         | 
    
        data/lib/ruby_bots/tool.rb
    CHANGED
    
    | @@ -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( | 
| 11 | 
            -
                   | 
| 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( | 
| 19 | 
            -
                   | 
| 20 | 
            -
             | 
| 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 | 
            -
                 | 
| 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
         | 
    
        data/lib/ruby_bots/version.rb
    CHANGED
    
    
    
        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 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 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. | 
| 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- | 
| 11 | 
            +
            date: 2023-04-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: debug
         |