Class: Llm::Functions::GetGemFilesList

Inherits:
Base
  • Object
show all
Defined in:
lib/llm/functions/get_gem_files_list.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#stop_llm_call?

Class Method Details

.gem_name_enumsObject



8
9
10
# File 'lib/llm/functions/get_gem_files_list.rb', line 8

def self.gem_name_enums
  @gem_name_enums ||= ::Bundler.locked_gems.specs.map(&:full_name)
end

Instance Method Details

#definitionObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/llm/functions/get_gem_files_list.rb', line 12

def definition
  return @definition unless @definition.nil?

  @definition = {
    name: self.function_name,
    description: I18n.t("ghostest.functions.#{self.function_name}.description"),
    parameters: {
      type: :object,
      properties: {
        gem_name: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.gem_name"),
          enum: self.class.gem_name_enums,
        },
      },
      required: [:gem_name],
    },
  }
  @definition
end

#execute_and_generate_message(args) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/llm/functions/get_gem_files_list.rb', line 33

def execute_and_generate_message(args)
  unless self.class.gem_name_enums.include?(args['gem_name'])
    return { message: 'invalid gem_name. gem_name is below' + self.class.gem_name_enums.join("\n") }
  end
  files_list = Dir.glob("#{Gem.paths.home}/gems/#{args['gem_name']}/**/*.{rb,yml}")

  { files_list: }
end

#function_nameObject



4
5
6
# File 'lib/llm/functions/get_gem_files_list.rb', line 4

def function_name
  :get_gem_files_list
end