diff options
Diffstat (limited to 'logic')
-rw-r--r-- | logic/cartridge/safety.rb | 4 | ||||
-rw-r--r-- | logic/providers/openai/tools.rb | 31 |
2 files changed, 9 insertions, 26 deletions
diff --git a/logic/cartridge/safety.rb b/logic/cartridge/safety.rb index 6414e51..39826a9 100644 --- a/logic/cartridge/safety.rb +++ b/logic/cartridge/safety.rb @@ -7,14 +7,14 @@ module NanoBot module Cartridge module Safety def self.default_answer(cartridge) - default = Fetch.cascate(cartridge, [%i[interfaces tools confirm default]]) + default = Fetch.cascate(cartridge, [%i[interfaces tools confirming default]]) return [] if default.nil? default end def self.yeses(cartridge) - yeses_values = Fetch.cascate(cartridge, [%i[interfaces tools confirm yeses]]) + yeses_values = Fetch.cascate(cartridge, [%i[interfaces tools confirming yeses]]) return [] if yeses_values.nil? yeses_values 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 |