Class: CommandGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/command_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, openai_client) ⇒ CommandGenerator

Returns a new instance of CommandGenerator.



7
8
9
10
11
# File 'lib/command_generator.rb', line 7

def initialize(config, openai_client)
  @config = config
  @openai_client = openai_client
  @prompts = YAML.load_file(File.join(__dir__, '..', 'config', 'prompts.yml'))
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/command_generator.rb', line 5

def config
  @config
end

#openai_clientObject (readonly)

Returns the value of attribute openai_client.



4
5
6
# File 'lib/command_generator.rb', line 4

def openai_client
  @openai_client
end

Instance Method Details

#final_prompt(prompt) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/command_generator.rb', line 63

def final_prompt(prompt)
  goal_commands_prompt = "    This is the output of the command you provided to the user in the previous step.\n\n    \#{prompt}\n\n  PROMPT\n\n  goal_commands_prompt += @prompts[\"goal_commands\"]\n\n  continue_conversation(goal_commands_prompt)\nend\n"

#first_prompt(user_goal_prompt) ⇒ Object



13
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
# File 'lib/command_generator.rb', line 13

def first_prompt(user_goal_prompt)
  system_prompt = @prompts["system"]

  if @config["send_path"]
    system_prompt += "      # ADDITIONAL CONTEXT:\n\n      The user's PATH environment variable is:\n      \#{ENV[\"PATH\"]}\n    PROMPT\n  end\n\n  user_prompt = @prompts[\"info_gathering\"]\n  user_prompt += <<~PROMPT\n    The user's GOAL PROMPT is:\n\n    \"\#{user_goal_prompt}\"\n\n    Please respond with one or more commands to execute to gather more information about the user's system before providing the response which will accomplish the user's goal.\n\n    COMMANDS:\n  PROMPT\n\n  @messages = [\n    { role: \"system\", content: system_prompt }\n  ]\n\n  continue_conversation(user_prompt)\nend\n"

#offer_information_prompt(previous_output, previous_output_type = :question_response) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/command_generator.rb', line 43

def offer_information_prompt(previous_output, previous_output_type = :question_response)
  question_prompt = if previous_output_type == :question_response
    "      This is the output of the question you asked the user in the previous step.\n\n      \#{previous_output}\n    PROMPT\n  else\n    <<~PROMPT\n      This is the output of the command you provided to the user in the previous step.\n\n      \#{previous_output}\n    PROMPT\n  end\n\n  question_prompt += @prompts[\"user_question\"]\n\n  continue_conversation(question_prompt)\nend\n"

#refine_last_response(prompt) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/command_generator.rb', line 76

def refine_last_response(prompt)
  refinement_prompt = @prompts["refine_commands"]

  refinement_prompt += "\n    \#{prompt}\n\n    COMMANDS:\n  PROMPT\n\n  continue_conversation(refinement_prompt)\nend\n"