diff options
author | icebaker <icebaker@proton.me> | 2023-11-19 13:35:54 -0300 |
---|---|---|
committer | icebaker <icebaker@proton.me> | 2023-11-19 13:35:54 -0300 |
commit | e89a1d57c49c94c16c37a8ee3a69b52a9e2b341b (patch) | |
tree | e82a7579534003f02de32d058f4a60d1d076240c /logic/providers/openai | |
parent | c470d63b169058d81f44569a5f1c4c1fb222279f (diff) |
improving tool specifications
Diffstat (limited to 'logic/providers/openai')
-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 |