Class: CommandGenerator
- Inherits:
-
Object
- Object
- CommandGenerator
- Defined in:
- lib/command_generator.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#openai_client ⇒ Object
readonly
Returns the value of attribute openai_client.
Instance Method Summary collapse
- #final_prompt(prompt) ⇒ Object
- #first_prompt(user_goal_prompt) ⇒ Object
-
#initialize(config, openai_client) ⇒ CommandGenerator
constructor
A new instance of CommandGenerator.
- #offer_information_prompt(previous_output, previous_output_type = :question_response) ⇒ Object
- #refine_last_response(prompt) ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/command_generator.rb', line 5 def config @config end |
#openai_client ⇒ Object (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 = <<~PROMPT This is the output of the command you provided to the user in the previous step. #{prompt} PROMPT goal_commands_prompt += @prompts["goal_commands"] continue_conversation(goal_commands_prompt) end |
#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 += <<~PROMPT # ADDITIONAL CONTEXT: The user's PATH environment variable is: #{ENV["PATH"]} PROMPT end user_prompt = @prompts["info_gathering"] user_prompt += <<~PROMPT The user's GOAL PROMPT is: "#{user_goal_prompt}" 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. COMMANDS: PROMPT @messages = [ { role: "system", content: system_prompt } ] continue_conversation(user_prompt) end |
#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 <<~PROMPT This is the output of the question you asked the user in the previous step. #{previous_output} PROMPT else <<~PROMPT This is the output of the command you provided to the user in the previous step. #{previous_output} PROMPT end question_prompt += @prompts["user_question"] continue_conversation(question_prompt) end |
#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 += <<~PROMPT #{prompt} COMMANDS: PROMPT continue_conversation(refinement_prompt) end |