Module: AICallable::ClassMethods

Defined in:
lib/glim_ai_callable.rb

Instance Method Summary collapse

Instance Method Details

#ai_callable_as(method_name, &block) ⇒ Object



11
12
13
14
15
# File 'lib/glim_ai_callable.rb', line 11

def ai_callable_as(method_name, &block)
  method_signature_builder = MethodSignatureBuilder.new
  method_signature_builder.instance_eval(&block)
  ai_method_signatures << method_signature_builder.signature.merge({ name: method_name.to_s })
end

#ai_method_signaturesObject



17
18
19
# File 'lib/glim_ai_callable.rb', line 17

def ai_method_signatures
  @ai_method_signatures ||= []
end

#ai_method_signatures_cleanObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/glim_ai_callable.rb', line 21

def ai_method_signatures_clean
  return @ai_method_signatures_clean if @ai_method_signatures_clean
  def remove_local_name(data)
    result = data.map do |item|
      { 
        'name' => item[:name],
        'description' => item[:description],
        'parameters' => {
          'type' => item[:parameters][:type],
          'properties' => item[:parameters][:properties].transform_values { |property| property.reject { |k, _| k == :local_name } },
          'required' => item[:parameters][:required]
        }
      }
    rescue => e
      putt :warning, "Issue with #{item}: #{e.message}"
      raise e
    end
    return result
  end
  sigs = ai_method_signatures # this is an array
  @ai_method_signatures_clean = remove_local_name(sigs)
end

#remove_local_name(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/glim_ai_callable.rb', line 23

def remove_local_name(data)
  result = data.map do |item|
    { 
      'name' => item[:name],
      'description' => item[:description],
      'parameters' => {
        'type' => item[:parameters][:type],
        'properties' => item[:parameters][:properties].transform_values { |property| property.reject { |k, _| k == :local_name } },
        'required' => item[:parameters][:required]
      }
    }
  rescue => e
    putt :warning, "Issue with #{item}: #{e.message}"
    raise e
  end
  return result
end