Module: EasyTalk::Tools::FunctionBuilder

Defined in:
lib/easy_talk/tools/function_builder.rb

Overview

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.

Class Method Summary collapse

Class Method Details

.generate_function_description(model) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/easy_talk/tools/function_builder.rb', line 28

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

.generate_function_name(model) ⇒ Object



24
25
26
# File 'lib/easy_talk/tools/function_builder.rb', line 24

def generate_function_name(model)
  model.schema.fetch(:title, model.name)
end

.new(model) ⇒ Hash

Creates a new function object based on the given model.

Parameters:

  • model (Model)

    The EasyTalk model containing the function details.

Returns:

  • (Hash)

    The function object.



13
14
15
16
17
18
19
20
21
22
# File 'lib/easy_talk/tools/function_builder.rb', line 13

def new(model)
  {
    type: 'function',
    function: {
      name: generate_function_name(model),
      description: generate_function_description(model),
      parameters: model.json_schema
    }
  }
end