Sha256: 77e909cbbe3af578be94a7d435ead7e16d8365fec2948424f1693be813d35649
Contents?: true
Size: 1.62 KB
Versions: 14
Compression:
Stored size: 1.62 KB
Contents
# frozen_string_literal: true require 'json' require 'babosa' require_relative '../../helpers/hash' module NanoBot module Logic module OpenAI module Tools def self.prepare(cartridge, tools) applies = [] tools = Marshal.load(Marshal.dump(tools)) tools.each do |tool| tool = Helpers::Hash.symbolize_keys(tool) cartridge.each do |candidate| candidate_key = candidate[:name].to_slug.normalize.gsub('-', '_') tool_key = tool[:function][:name].to_slug.normalize.gsub('-', '_') next unless candidate_key == tool_key source = {} source[:clojure] = candidate[:clojure] if candidate[:clojure] source[:fennel] = candidate[:fennel] if candidate[:fennel] source[:lua] = candidate[:lua] if candidate[:lua] applies << { id: tool[:id], label: candidate[:name], name: tool[:function][:name], 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) output = { type: 'function', function: { name: cartridge[:name], description: cartridge[:description] } } output[:function][:parameters] = (cartridge[:parameters] || { type: 'object', properties: {} }) output end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems