Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.

Commit 6975b39

Browse files
committed
Tweak prompt and patch preprocessing
1 parent 3eaca7b commit 6975b39

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

server/bleep/src/webserver/answer/prompts.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,27 +160,21 @@ pub fn final_explanation_prompt(context: &str, query: &str, query_history: &str)
160160
example: Some(r#"The path is a relative path, with no leading slash. You must generate a trailing slash, for example: server/bleep/src/webserver/. On Windows, generate backslash separated components, for example: server\bleep\src\webserver\"#),
161161
},
162162
Rule {
163-
title: "Write a new code file",
164-
description: "Write a new code file that satisfies the query. Do not use this to demonstrate updating an existing file.",
165-
schema: "[\"new\",LANGUAGE:STRING,CODE:STRING]",
166-
note: "This object can occur multiple times",
167-
example: None,
168-
},
169-
Rule {
170-
title: "Update the code in an existing file",
171-
description: "Edit an existing code file by generating the diff between old and new versions. Changes should be as small as possible.",
172-
schema: "[\"mod\",PATH ALIAS:INT,LANGUAGE:STRING,DESCRIPTION:STRING,GIT DIFF WITHOUT LINE NUMBERS:STRING]",
163+
title: "Write a new code file in a unified diff format",
164+
description: "Write a new code file that satisfies the query.",
165+
schema: "[\"mod\",null,LANGUAGE:STRING,DESCRIPTION:STRING,GIT DIFF WITHOUT LINE NUMBERS:STRING,NEW PATH:STRING]",
173166
note: "This object can occur multiple times",
174167
example: Some(r#"DESCRIPTION is a natural language description of the changes
168+
NEW PATH: path for the newly created file.
175169
GIT DIFF WITHOUT LINE NUMBERS describes the unified diff for the file, including the git diff header. Do not include any line numbers
176170
For example:
177171
```
178172
@@ -1,7 +1,6 @@
179-
-The Way that can be told of is not the eternal Way;
180-
-The name that can be named is not the eternal name.
173+
- The Way that can be told of is not the eternal Way;
174+
- The name that can be named is not the eternal name.
181175
The Nameless is the origin of Heaven and Earth;
182-
-The Named is the mother of all things.
183-
+The named is the mother of all things.
176+
- The Named is the mother of all things.
177+
+ The named is the mother of all things.
184178
+
185179
Therefore let there always be non-being,
186180
so we may see their subtlety,
@@ -189,11 +183,19 @@ pub fn final_explanation_prompt(context: &str, query: &str, query_history: &str)
189183
The two are the same,
190184
But after they are produced,
191185
they have different names.
192-
+They both may be called deep and profound.
193-
+Deeper and more profound,
194-
+The door of all subtleties!
186+
+ They both may be called deep and profound.
187+
+ Deeper and more profound,
188+
+ The door of all subtleties!
195189
```"#),
196190
},
191+
Rule {
192+
title: "Update the code in an existing file",
193+
description: "Edit an existing code file by generating the diff between old and new versions. Changes should be as small as possible.",
194+
schema: "[\"mod\",PATH ALIAS:INT,LANGUAGE:STRING,DESCRIPTION:STRING,GIT DIFF WITHOUT LINE NUMBERS:STRING]",
195+
note: "This object can occur multiple times",
196+
example: Some(r#"DESCRIPTION is a natural language description of the changes
197+
GIT DIFF WITHOUT LINE NUMBERS describes the unified diff for the file, including the git diff header. Do not include any line numbers."#),
198+
},
197199
Rule {
198200
title: "Cite line ranges from the file",
199201
description: "START LINE and END LINE should focus on the code mentioned in the COMMENT. COMMENT should be a detailed explanation.",

server/bleep/src/webserver/answer/response.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub struct ModifyResult {
172172
description: Option<String>,
173173
diff: Option<ModifyResultHunk>,
174174
raw: Option<String>,
175+
new_file: Option<String>,
175176
}
176177

177178
#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
@@ -285,31 +286,38 @@ impl ModifyResult {
285286
.and_then(serde_json::Value::as_str)
286287
.map(str::to_string);
287288

289+
let new_file = v
290+
.get(4)
291+
.and_then(serde_json::Value::as_str)
292+
.map(str::to_string);
293+
288294
Some(Self {
289295
path_alias,
290296
language,
291297
diff,
292298
raw,
299+
new_file,
293300
..Default::default()
294301
})
295302
}
296303

297304
fn substitute_path_alias(mut self, path_aliases: &[String]) -> Self {
298-
self.path = self
299-
.path_alias
300-
.as_ref()
301-
.and_then(|alias| {
302-
if let Some(p) = path_aliases.get(*alias as usize) {
303-
Some(p)
304-
} else {
305-
tracing::warn!("no path found for alias `{alias}`");
306-
for (idx, p) in path_aliases.iter().enumerate() {
307-
tracing::warn!("we have {idx}. {p}");
305+
self.path = self.new_file.clone().or_else(|| {
306+
self.path_alias
307+
.as_ref()
308+
.and_then(|alias| {
309+
if let Some(p) = path_aliases.get(*alias as usize) {
310+
Some(p)
311+
} else {
312+
tracing::warn!("no path found for alias `{alias}`");
313+
for (idx, p) in path_aliases.iter().enumerate() {
314+
tracing::warn!("we have {idx}. {p}");
315+
}
316+
None
308317
}
309-
None
310-
}
311-
})
312-
.map(ToOwned::to_owned);
318+
})
319+
.map(ToOwned::to_owned)
320+
});
313321
self
314322
}
315323
}

server/bleep/src/webserver/git.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ impl<'a> Visit for CreateNewCommit<'a> {
296296
let processed = process_patch(patch);
297297
let base = String::from_utf8_lossy(&base);
298298
println!("{base}");
299+
println!("{processed}");
299300

300301
diffy::apply(base.as_ref(), &diffy::Patch::from_str(&processed).unwrap())
301302
.unwrap()
@@ -331,9 +332,7 @@ fn process_patch(patch: &str) -> String {
331332
.skip_while(|line| empty_line.is_match(line))
332333
.collect::<Vec<_>>();
333334

334-
rev.into_iter()
335-
.rev()
336-
.skip_while(|line| empty_line.is_match(line))
335+
rev.into_iter().rev()
337336
};
338337

339338
let mut collected = vec![];

0 commit comments

Comments
 (0)