Skip to content

Commit

Permalink
improve answer prompt and fix case where single-file context was omit…
Browse files Browse the repository at this point in the history
…ted because it did not fit within the token limit (#1031)
  • Loading branch information
ggordonhall committed Oct 9, 2023
1 parent b810d71 commit 01b09b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions server/bleep/src/agent/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ pub fn answer_article_prompt(context: &str) -> String {
format!(
r#"{context}####
Your job is to answer a query about a codebase using the information above.
You are an expert programmer called 'bloop' and you are helping a junior colleagure answer questions about a codebase using the information above. If their query refers to 'this' or 'it' and there is no other context, assume that it refers to the information above.
Provide only as much information and code as is necessary to answer the query, but be concise. Keep number of quoted lines to a minimum when possible. If you do not have enough information needed to answer the query, do not make up an answer.
Provide only as much information and code as is necessary to answer the query, but be concise. Keep number of quoted lines to a minimum when possible. If you do not have enough information needed to answer the query, do not make up an answer. Infer as much as possible from the information above.
When referring to code, you must provide an example in a code block.
Respect these rules at all times:
Expand Down
21 changes: 19 additions & 2 deletions server/bleep/src/agent/tools/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Agent {

debug!(?spans_by_path, "expanded spans");

spans_by_path
let code_chunks = spans_by_path
.into_iter()
.flat_map(|(path, spans)| spans.into_iter().map(move |s| (path.clone(), s)))
.map(|(path, span)| {
Expand All @@ -386,7 +386,24 @@ impl Agent {
end_line: span.end,
}
})
.collect()
.collect::<Vec<CodeChunk>>();

// Handle case where there is only one code chunk and it exceeds `max_tokens`.
// In this instance we trim the chunk to fit within the limit.
if code_chunks.len() == 1 {
let chunk = code_chunks.first().unwrap();
let trimmed_snippet = transcoder::limit_tokens(&chunk.snippet, bpe, max_tokens);
let num_trimmed_lines = trimmed_snippet.lines().count();
vec![CodeChunk {
alias: chunk.alias,
path: chunk.path.clone(),
snippet: trimmed_snippet.to_string(),
start_line: chunk.start_line,
end_line: (chunk.start_line + num_trimmed_lines).saturating_sub(1),
}]
} else {
code_chunks
}
}
}

Expand Down

0 comments on commit 01b09b1

Please sign in to comment.