Class: Llm::Agents::Reviewer

Inherits:
Base
  • Object
show all
Defined in:
lib/llm/agents/reviewer.rb

Instance Attribute Summary

Attributes inherited from Base

#agent_config, #config, #name

Instance Method Summary collapse

Methods inherited from Base

#name_with_type, #say

Constructor Details

#initialize(name, config, logger) ⇒ Reviewer

Returns a new instance of Reviewer.



4
5
6
7
# File 'lib/llm/agents/reviewer.rb', line 4

def initialize(name, config, logger)
  super(name, config, logger)
  @record_lgtm_function = Llm::Functions::RecordLgtm.new
end

Instance Method Details

#lgtm?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/llm/agents/reviewer.rb', line 9

def lgtm?
  @record_lgtm_function.lgtm?
end

#work(source_path: raise("source_path is required"), test_path: nil, switch_assignee_function: raise("switch_assignee_function is required")) ⇒ Object

skip test for this method



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/llm/agents/reviewer.rb', line 14

def work(
  source_path: raise("source_path is required"),
  test_path: nil,
  switch_assignee_function: raise("switch_assignee_function is required"))
  say("start to work for #{source_path}")

  message_container = Llm::MessageContainer.new
  test_path ||= self.config.language_klass.convert_source_path_to_test_path(source_path)
  message_container.add_system_message(self.agent_config.system_prompt.gsub("%{source_path}", source_path).gsub("%{test_path}", test_path))

  if switch_assignee_function.messages.size > 0
    message_container.add_system_message(I18n.t('ghostest.agents.reviewer.last_assignee_comment',
                                                last_assignee: switch_assignee_function.last_assignee,
                                                comment: switch_assignee_function.last_message))
  end

  azure_open_ai = Llm::Clients::AzureOpenAi.new
  io = azure_open_ai.chat_with_function_calling_loop(
    messages: message_container,
    functions: [
      @record_lgtm_function,
      Llm::Functions::GetFilesList.new,
      Llm::Functions::ReadFile.new,
      Llm::Functions::AddToMemory.new(message_container),
      switch_assignee_function,

    ] + self.config.language_klass.create_functions,
    agent: self,
  )

  comment = io.rewind && io.read
  say(comment)
  comment
end