Compare commits

...

3 Commits

Author SHA1 Message Date
Richard Feldman
9404251dd0 Tweak workflow prompt to be more explicit about step boundaries 2024-08-16 16:41:15 -04:00
Richard Feldman
289ba8fb34 Make find_most_similar resilient to queries that contain types 2024-08-16 16:14:53 -04:00
Richard Feldman
ba7e894a6e Simplify workflow prompt 2024-08-16 15:41:47 -04:00
2 changed files with 8 additions and 4 deletions

View File

@@ -1,12 +1,11 @@
<workflow>
Guide the user through code changes in numbered steps that focus on individual functions, type definitions, etc.
Guide the user through code changes in numbered steps where each step focuses on a single individual function, type definition, etc.
Surround each distinct step in a <step></step> XML tag. The user will be performing these steps in a code editor
named Zed, which is where they will have entered this prompt and will be seeing the response.
<instructions>
- Use the language of the file for code fence blocks unless otherwise specified.
- Include a code or file action in each step.
- Only put code in separate steps if it should either go in separate files, or in different (non-contiguous) places in the same file.
- Provide error handling and input validation where appropriate.
- Adapt explanations based on the user's perceived level of expertise.
- Include comments in code examples to enhance understanding.

View File

@@ -88,7 +88,12 @@ impl<T> Outline<T> {
}
/// Find the most similar symbol to the provided query using normalized Levenshtein distance.
pub fn find_most_similar(&self, query: &str) -> Option<(SymbolPath, &OutlineItem<T>)> {
pub fn find_most_similar(&self, symbol: &str) -> Option<(SymbolPath, &OutlineItem<T>)> {
// Sometimes the model incorrectly includes a space or colon in the query,
// e.g. in Elm, Roc, etc. it might say `foo : ...` because it's trying to include the symbol's type,
// which isn't part of the symbol and won't be in the outline. Trim the first space and anything after it.
let symbol = &symbol[..symbol.find(' ').unwrap_or(symbol.len())];
const SIMILARITY_THRESHOLD: f64 = 0.6;
let (position, similarity) = self
@@ -96,7 +101,7 @@ impl<T> Outline<T> {
.iter()
.enumerate()
.map(|(index, candidate)| {
let similarity = strsim::normalized_levenshtein(&candidate.string, query);
let similarity = strsim::normalized_levenshtein(&candidate.string, symbol);
(index, similarity)
})
.max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())?;