diff --git a/Gemfile.lock b/Gemfile.lock index cec377c..f15a4a7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - omniai (1.8.0) + omniai (1.8.1) event_stream_parser http zeitwerk diff --git a/lib/omniai/tool.rb b/lib/omniai/tool.rb index aa48c34..6064931 100644 --- a/lib/omniai/tool.rb +++ b/lib/omniai/tool.rb @@ -53,7 +53,10 @@ def initialize(function, name:, description: nil, parameters: nil) # # parameters: { # # type: 'object', # # properties: { - # # n: OmniAI::Tool::Property.integer(description: 'The nth Fibonacci number to calculate') + # # n: { + # # description: 'The nth Fibonacci number to calculate') + # # type: 'integer' + # # } # # }, # # required: ['n'] # # } @@ -71,7 +74,7 @@ def serialize(context: nil) function: { name: @name, description: @description, - parameters: @parameters&.prepare, + parameters: @parameters.is_a?(Tool::Parameters) ? @parameters.serialize : @parameters, }.compact, } end @@ -83,7 +86,7 @@ def serialize(context: nil) # @param args [Hash] # @return [String] def call(args = {}) - @function.call(**(@parameters ? @parameters.parse(args) : args)) + @function.call(**(@parameters.is_a?(Tool::Parameters) ? @parameters.parse(args) : args)) end end end diff --git a/lib/omniai/tool/parameters.rb b/lib/omniai/tool/parameters.rb index b615ea9..65bbd28 100644 --- a/lib/omniai/tool/parameters.rb +++ b/lib/omniai/tool/parameters.rb @@ -24,10 +24,10 @@ def initialize(type: Type::OBJECT, properties: {}, required: []) end # @return [Hash] - def prepare + def serialize { type: @type, - properties: @properties.transform_values(&:prepare), + properties: @properties.transform_values(&:serialize), required: @required, }.compact end diff --git a/lib/omniai/tool/property.rb b/lib/omniai/tool/property.rb index 598af8f..70a5555 100644 --- a/lib/omniai/tool/property.rb +++ b/lib/omniai/tool/property.rb @@ -60,7 +60,7 @@ def initialize(type:, description: nil, enum: nil) end # @example - # property.prepare + # property.serialize # # { # # type: 'string', # # description: 'The unit (e.g. "fahrenheit" or "celsius").' @@ -68,7 +68,7 @@ def initialize(type:, description: nil, enum: nil) # # } # # @return [Hash] - def prepare + def serialize { type: @type, description: @description, diff --git a/lib/omniai/version.rb b/lib/omniai/version.rb index 504d78d..aa85da8 100644 --- a/lib/omniai/version.rb +++ b/lib/omniai/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module OmniAI - VERSION = '1.8.0' + VERSION = '1.8.1' end diff --git a/spec/omniai/tool/parameters_spec.rb b/spec/omniai/tool/parameters_spec.rb index 2ce97da..12f76f5 100644 --- a/spec/omniai/tool/parameters_spec.rb +++ b/spec/omniai/tool/parameters_spec.rb @@ -11,9 +11,9 @@ let(:required) { %i[n] } - describe '#prepare' do + describe '#serialize' do it 'converts the parameters to a hash' do - expect(parameters.prepare).to eq({ + expect(parameters.serialize).to eq({ type: 'object', properties: { n: { type: 'integer', description: 'The nth number to calculate.' }, diff --git a/spec/omniai/tool/property_spec.rb b/spec/omniai/tool/property_spec.rb index b640821..617f171 100644 --- a/spec/omniai/tool/property_spec.rb +++ b/spec/omniai/tool/property_spec.rb @@ -31,9 +31,9 @@ it { expect(property.type).to eq('number') } end - describe '#prepare' do + describe '#serialize' do it 'converts the property to a hash' do - expect(property.prepare).to eq({ + expect(property.serialize).to eq({ type: 'string', description: 'The unit (e.g. "fahrenheit" or "celsius")', enum: %w[fahrenheit celsius],