Compare commits

...

8 Commits

Author SHA1 Message Date
Jason Mancuso
e8e4e87b92 hacking on inline assist prompt to avoid overgeneration for empty-line inserts that fall before a non-empty line
Co-Authored-By: Nathan <nathan@zed.dev>
2024-08-15 19:38:27 -04:00
Jason Mancuso
e23e10da0f Revert "Expand the closing rewrite_this tag range up to the first non-whitespace char."
This reverts commit f9167dd4ee77168955f33a9e90b4abdc3d6adb82.
2024-08-15 19:38:27 -04:00
Jason Mancuso
39e1357d68 stash work: trying to include immediate next line in rewrite_section if it's non-empty 2024-08-15 19:38:27 -04:00
Jason Mancuso
7e0b837936 Expand the closing rewrite_this tag range up to the first non-whitespace char.
Co-Authored-By: Richard <richard@zed.dev>
2024-08-15 19:38:16 -04:00
Jason Mancuso
68b4bf067b content prompt copy changes 2024-08-15 14:57:39 -04:00
Jason Mancuso
21202be487 prime the model to seek rewrite_this section of <document> 2024-08-15 11:05:15 -04:00
Jason Mancuso
02ab37f2c3 escape rewritten_{content_type} in output format 2024-08-14 14:22:30 -04:00
Jason Mancuso
88ebdb6390 rewrite content prompt to avoid chatter and xml tags in output 2024-08-14 13:14:01 -04:00
4 changed files with 1643 additions and 33 deletions

View File

@@ -1,52 +1,53 @@
Here's a text file that I'm going to ask you to make an edit to.
{{#if language_name}}
The file is in {{language_name}}.
File language: {{language_name}}
{{/if}}
You need to rewrite a portion of it.
The section you'll need to edit is marked with <rewrite_this></rewrite_this> tags.
Note the position of `<rewrite_this>...</rewrite_this>` tags in the document.
<document>
{{{document_content}}}
</document>
{{#if is_truncated}}
The context around the relevant section has been truncated (possibly in the middle of a line) for brevity.
Note: Context around the relevant section has been truncated for brevity.
{{/if}}
Rewrite the section of {{content_type}} in <rewrite_this></rewrite_this> tags based on the following prompt:
Editing instructions:
1. Modify the code tagged above with `<rewrite_this>...</rewrite_this>` based on this prompt:
<prompt>
{{{user_prompt}}}
</prompt>
Here's the section to edit based on that prompt again for reference:
2. Only perform these changes:
{{#if has_insertion}}
- Add content where you see <insert_here></insert_here>
{{/if}}
{{#if has_replacement}}
- Update content between <edit_here></edit_here> tags
{{/if}}
<rewrite_this>
{{{rewrite_section}}}
</rewrite_this>
3. Reminder: immediately surrounding code from the above `document`. Use this to silently recall the context, do not include surrounding code in your output!
<surrounding-context>
{{{rewrite_section_surrounding_with_selections}}}
</surrounding-context>
You'll rewrite this entire section, but you will only make changes within certain subsections.
4. Important guidelines:
- Make only the changes needed to address the prompt
- Match the original indentation
- Do NOT include any `<rewrite_this>` or {{#if has_insertion}}`<insert_here>`{{/if}}{{#if has_replacement}}`<edit_here>`{{/if}} tags in your response
- Only change {{content_type}} that goes between the `{{#if has_insertion}}<insert_here>...</insert_here>{{/if}}{{#if has_replacement}}<edit_here>...</edit_here>{{/if}}` tags
- Provide the entire `<rewrite_this>` section, even if parts remain unchanged
- Do NOT output any of the code outside of the `<rewrite_this>` section
{{#if has_insertion}}
Insert text anywhere you see it marked with with <insert_here></insert_here> tags. Do not include <insert_here> tags in your output.
{{/if}}
{{#if has_replacement}}
Edit edit text that you see surrounded with <edit_here></edit_here> tags. Do not include <edit_here> tags in your output.
{{/if}}
<rewrite_this>
{{{rewrite_section_with_selections}}}
</rewrite_this>
Only make changes that are necessary to fulfill the prompt, leave everything else as-is. All surrounding {{content_type}} will be preserved. Do not output the <rewrite_this></rewrite this> tags or anything outside of them.
Start at the indentation level in the original file in the rewritten {{content_type}}. Don't stop until you've rewritten the entire section, even if you have no more changes to make. Always write out the whole section with no unnecessary elisions.
Immediately start with the following format with no remarks:
Remember, this is the user's prompt:
<prompt>
{{{user_prompt}}}
</prompt>
Example of expected output format:
```
\{{REWRITTEN_CODE}}
\{{rewritten_{{content_type}}}}
```
Where \{{rewritten_{{content_type}}}} is replaced with your modified `<rewrite_this>' section.
Now, provide your modified `<rewrite_this>' section using the format shown above. Start immediately with the ``` delimiter, no commentary.

File diff suppressed because it is too large Load Diff

View File

@@ -2258,7 +2258,8 @@ impl Codegen {
cx: &AppContext,
) -> BoxFuture<'static, Result<TokenCounts>> {
if let Some(model) = LanguageModelRegistry::read_global(cx).active_model() {
let request = self.build_request(user_prompt, assistant_panel_context.clone(), cx);
let request =
self.build_request(user_prompt, assistant_panel_context.clone(), false, cx);
match request {
Ok(request) => {
let total_count = model.count_tokens(request.clone(), cx);
@@ -2304,7 +2305,7 @@ impl Codegen {
if user_prompt.trim().to_lowercase() == "delete" {
async { Ok(stream::empty().boxed()) }.boxed_local()
} else {
let request = self.build_request(user_prompt, assistant_panel_context, cx)?;
let request = self.build_request(user_prompt, assistant_panel_context, true, cx)?;
let chunks =
cx.spawn(|_, cx| async move { model.stream_completion(request, &cx).await });
@@ -2318,6 +2319,7 @@ impl Codegen {
&self,
user_prompt: String,
assistant_panel_context: Option<LanguageModelRequest>,
log_prompt: bool,
cx: &AppContext,
) -> Result<LanguageModelRequest> {
let buffer = self.buffer.read(cx).snapshot(cx);
@@ -2385,6 +2387,13 @@ impl Codegen {
)
.map_err(|e| anyhow::anyhow!("Failed to generate content prompt: {}", e))?;
if log_prompt {
println!(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n{}\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
prompt
);
}
let mut messages = Vec::new();
if let Some(context_request) = assistant_panel_context {
messages = context_request.messages;

View File

@@ -6,6 +6,7 @@ use language::BufferSnapshot;
use parking_lot::Mutex;
use serde::Serialize;
use std::{ops::Range, sync::Arc, time::Duration};
use text::OffsetRangeExt as _;
use util::ResultExt;
#[derive(Serialize)]
@@ -17,6 +18,7 @@ pub struct ContentPromptContext {
pub user_prompt: String,
pub rewrite_section: String,
pub rewrite_section_with_selections: String,
pub rewrite_section_surrounding_with_selections: String,
pub has_insertion: bool,
pub has_replacement: bool,
}
@@ -211,6 +213,7 @@ impl PromptBuilder {
let rewrite_section_with_selections = {
let mut section_with_selections = String::new();
let mut last_end = 0;
section_with_selections.push_str("<rewrite_this>\n");
for selected_range in &selected_ranges {
if selected_range.start > last_end {
section_with_selections.push_str(
@@ -232,9 +235,30 @@ impl PromptBuilder {
if last_end < rewrite_section.len() {
section_with_selections.push_str(&rewrite_section[last_end..]);
}
section_with_selections.push_str("\n</rewrite_this>");
section_with_selections
};
let rewrite_section_surrounding_with_selections = {
let mut context_range = transform_range.to_point(&buffer);
context_range.start.row = context_range.start.row.saturating_sub(8);
context_range.end = buffer
.max_point()
.min(context_range.end + rope::Point::new(8, 0));
context_range.end.column = buffer.line_len(context_range.end.row);
let context_range = context_range.to_offset(&buffer);
let mut surrounding = String::new();
for chunk in buffer.text_for_range(context_range.start..transform_range.start) {
surrounding.push_str(chunk);
}
surrounding.push_str(&rewrite_section_with_selections);
for chunk in buffer.text_for_range(transform_range.end..context_range.end) {
surrounding.push_str(chunk);
}
surrounding
};
let has_insertion = selected_ranges.iter().any(|range| range.start == range.end);
let has_replacement = selected_ranges.iter().any(|range| range.start != range.end);
@@ -246,6 +270,7 @@ impl PromptBuilder {
user_prompt,
rewrite_section,
rewrite_section_with_selections,
rewrite_section_surrounding_with_selections,
has_insertion,
has_replacement,
};