Sha256: 52ecc9b362bcbba609058b952ed02d75a5af98d21f380a50122a6a103e7ef07e
Contents?: true
Size: 1.27 KB
Versions: 5
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true module EasyTalk module Tools # FunctionBuilder is a module that builds a hash with the function type and function details. # The return value is typically passed as argument to LLM function calling APIs. module FunctionBuilder class << self # Creates a new function object based on the given model. # # @param [Model] model The EasyTalk model containing the function details. # @return [Hash] The function object. def new(model) { type: 'function', function: { name: generate_function_name(model), description: generate_function_description(model), parameters: model.json_schema } } end def generate_function_name(model) model.schema.fetch(:title, model.name) end def generate_function_description(model) if model.respond_to?(:instructions) raise Instructor::Error, 'The instructions must be a string' unless model.instructions.is_a?(String) model.instructions else "Correctly extracted `#{model.name}` with all the required parameters and correct types." end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems