Add more context to the terminal assistant (#15492)

Release Notes:

- N/A
This commit is contained in:
Kirill Bulatov 2024-07-30 20:21:45 +03:00 committed by GitHub
parent 73e3dfc0c3
commit eedef487ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 8 deletions

View file

@ -115,11 +115,19 @@ pub fn generate_terminal_assistant_prompt(
user_prompt: &str,
shell: Option<&str>,
working_directory: Option<&str>,
latest_output: &[String],
) -> String {
let mut prompt = String::new();
writeln!(&mut prompt, "You are an expert terminal user.").unwrap();
writeln!(&mut prompt, "You will be given a description of a command and you need to respond with a command that matches the description.").unwrap();
writeln!(&mut prompt, "Do not include markdown blocks or any other text formatting in your response, always respond with a single command that can be executed in the given shell.").unwrap();
writeln!(
&mut prompt,
"Current OS name is '{}', architecture is '{}'.",
std::env::consts::OS,
std::env::consts::ARCH,
)
.unwrap();
if let Some(shell) = shell {
writeln!(&mut prompt, "Current shell is '{shell}'.").unwrap();
}
@ -130,6 +138,15 @@ pub fn generate_terminal_assistant_prompt(
)
.unwrap();
}
if !latest_output.is_empty() {
writeln!(
&mut prompt,
"Latest non-empty {} lines of the terminal output: {:?}",
latest_output.len(),
latest_output
)
.unwrap();
}
writeln!(&mut prompt, "Here is the description of the command:").unwrap();
prompt.push_str(user_prompt);
prompt