diff options
Diffstat (limited to 'logic/providers/openai/tools.rb')
-rw-r--r-- | logic/providers/openai/tools.rb | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/logic/providers/openai/tools.rb b/logic/providers/openai/tools.rb index 1aa9029..68f2209 100644 --- a/logic/providers/openai/tools.rb +++ b/logic/providers/openai/tools.rb @@ -17,10 +17,7 @@ module NanoBot tool = Helpers::Hash.symbolize_keys(tool) cartridge.each do |candidate| - next unless ( - candidate[:type].nil? || - (candidate[:type] == 'function' && tool[:type] == candidate[:type]) - ) && tool[:function][:name] == candidate[:name] + next unless tool[:function][:name] == candidate[:name] source = {} @@ -31,40 +28,26 @@ module NanoBot applies << { id: tool[:id], name: tool[:function][:name], - type: candidate[:type] || 'function', + type: 'function', parameters: JSON.parse(tool[:function][:arguments]), source: } end end + raise 'missing tool' if applies.size != tools.size + applies end def self.adapt(cartridge) - raise 'unsupported tool' if cartridge[:type] != 'function' && !cartridge[:type].nil? - - adapted = { - type: cartridge[:type] || 'function', + { + type: 'function', function: { name: cartridge[:name], description: cartridge[:description], - parameters: { type: 'object', properties: {} } + parameters: cartridge[:parameters] } } - - properties = adapted[:function][:parameters][:properties] - - adapted[:function][:parameters][:required] = cartridge[:required] if cartridge[:required] - - cartridge[:parameters]&.each do |parameter| - key = parameter[:name].to_sym - properties[key] = {} - properties[key][:type] = parameter[:type] || 'string' - properties[key][:description] = parameter[:description] if parameter[:description] - properties[key][:items] = parameter[:items].slice(:type) if parameter[:items] - end - - adapted end end end |