ruby-openai-swarm 0.2.4 → 0.2.6
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/Gemfile.lock +1 -1
- data/lib/ruby-openai-swarm/core.rb +10 -2
- data/lib/ruby-openai-swarm/function_descriptor.rb +5 -2
- data/lib/ruby-openai-swarm/util.rb +8 -5
- data/lib/ruby-openai-swarm/version.rb +1 -1
- data/lib/ruby-openai-swarm.rb +7 -1
- 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: 143ab1b153e54393e27a5a2f02d77c94ecaa8ed477d6ecdc2f072730b63ffd1f
         | 
| 4 | 
            +
              data.tar.gz: fa72888457647eefc2fedc5c5d97dcd1ccf7b2e35f1395eebf0500dc4a14fb22
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6b6830bb7dc3cb4e0512e0c5e0967ba7160b1967b5a44136923108df60cbb76450da27df55cadc9357a8a6c86d093db27dfbfdcf0f839e8db1e12114606055d7
         | 
| 7 | 
            +
              data.tar.gz: f8f67a146f3e089973e333a9ae39d2310779fa89648b91459ebcfe83029b4b6328852085cfb4179ae6627e60d802ff974ddaa8bebeee2f638fedcd89f1020e2a
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -212,8 +212,16 @@ module OpenAISwarm | |
| 212 212 |  | 
| 213 213 | 
             
                    yield({ delim: "start" }) if block_given?
         | 
| 214 214 | 
             
                    completion.each do |chunk|
         | 
| 215 | 
            -
             | 
| 216 | 
            -
             | 
| 215 | 
            +
                      if chunk['error']
         | 
| 216 | 
            +
                        details = {
         | 
| 217 | 
            +
                          'response' =>
         | 
| 218 | 
            +
                             Response.new(
         | 
| 219 | 
            +
                               messages: messages,
         | 
| 220 | 
            +
                               agent: active_agent,
         | 
| 221 | 
            +
                               context_variables: context_variables)
         | 
| 222 | 
            +
                        }
         | 
| 223 | 
            +
                        raise OpenAISwarm::Error.new(chunk['error'], details)
         | 
| 224 | 
            +
                      end
         | 
| 217 225 |  | 
| 218 226 | 
             
                      delta = chunk.dig('choices', 0, 'delta')
         | 
| 219 227 | 
             
                      if delta['role'] == "assistant"
         | 
| @@ -1,10 +1,13 @@ | |
| 1 1 | 
             
            module OpenAISwarm
         | 
| 2 2 | 
             
              class FunctionDescriptor
         | 
| 3 | 
            -
                attr_reader :target_method, | 
| 3 | 
            +
                attr_reader :target_method,
         | 
| 4 | 
            +
                            :description,
         | 
| 5 | 
            +
                            :parameters
         | 
| 4 6 |  | 
| 5 | 
            -
                def initialize(target_method:, description: '')
         | 
| 7 | 
            +
                def initialize(target_method:, description: '', parameters: nil)
         | 
| 6 8 | 
             
                  @target_method = target_method.is_a?(Method) ? target_method : method(target_method)
         | 
| 7 9 | 
             
                  @description = description
         | 
| 10 | 
            +
                  @parameters = parameters
         | 
| 8 11 | 
             
                end
         | 
| 9 12 | 
             
              end
         | 
| 10 13 | 
             
            end
         | 
| @@ -52,6 +52,7 @@ module OpenAISwarm | |
| 52 52 | 
             
                def self.function_to_json(func_instance)
         | 
| 53 53 | 
             
                  is_target_method = func_instance.respond_to?(:target_method) || func_instance.is_a?(OpenAISwarm::FunctionDescriptor)
         | 
| 54 54 | 
             
                  func = is_target_method ? func_instance.target_method : func_instance
         | 
| 55 | 
            +
                  custom_parameters = is_target_method ? func_instance.parameters : nil
         | 
| 55 56 |  | 
| 56 57 | 
             
                  function_name = func.name
         | 
| 57 58 | 
             
                  function_parameters = func.parameters
         | 
| @@ -82,16 +83,18 @@ module OpenAISwarm | |
| 82 83 |  | 
| 83 84 | 
             
                  description = func_instance.respond_to?(:description) ? func_instance&.description : nil
         | 
| 84 85 |  | 
| 86 | 
            +
                  json_parameters = {
         | 
| 87 | 
            +
                    type: "object",
         | 
| 88 | 
            +
                    properties: parameters,
         | 
| 89 | 
            +
                    required: required
         | 
| 90 | 
            +
                  }
         | 
| 91 | 
            +
             | 
| 85 92 | 
             
                  {
         | 
| 86 93 | 
             
                    type: "function",
         | 
| 87 94 | 
             
                    function: {
         | 
| 88 95 | 
             
                      name: function_name,
         | 
| 89 96 | 
             
                      description: description || '',
         | 
| 90 | 
            -
                      parameters:  | 
| 91 | 
            -
                        type: "object",
         | 
| 92 | 
            -
                        properties: parameters,
         | 
| 93 | 
            -
                        required: required
         | 
| 94 | 
            -
                      }
         | 
| 97 | 
            +
                      parameters: custom_parameters || json_parameters
         | 
| 95 98 | 
             
                    }
         | 
| 96 99 | 
             
                  }
         | 
| 97 100 | 
             
                end
         | 
    
        data/lib/ruby-openai-swarm.rb
    CHANGED
    
    | @@ -8,7 +8,13 @@ require 'ruby-openai-swarm/function_descriptor' | |
| 8 8 | 
             
            require 'ruby-openai-swarm/repl'
         | 
| 9 9 |  | 
| 10 10 | 
             
            module OpenAISwarm
         | 
| 11 | 
            -
              class Error < StandardError; | 
| 11 | 
            +
              class Error < StandardError;
         | 
| 12 | 
            +
                attr_reader :details
         | 
| 13 | 
            +
                def initialize(message, details = {})
         | 
| 14 | 
            +
                  @details = details
         | 
| 15 | 
            +
                  super(message)
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 12 18 |  | 
| 13 19 | 
             
              class << self
         | 
| 14 20 | 
             
                def new(client = nil)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ruby-openai-swarm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Grayson
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-12-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: ruby-openai
         |