Skip to content

Commit

Permalink
Edit: Fix leaky XML tags (#1789)
Browse files Browse the repository at this point in the history
## Description

Reported here:
https://sourcegraph.slack.com/archives/C05AGQYD528/p1700227846587329

Fixups can sometimes leak tags:
- When little context is provided, so Cody gets confused about the task
- Due to multiple tags being used, Cody sometimes thinks they are to be
used in the response.


## Test plan

Test creating fixups.

Primarily test creating fixups on code actions, where we provide the
least context
<!-- Required. See
https://docs.sourcegraph.com/dev/background-information/testing_principles.
-->
  • Loading branch information
umpox authored Nov 17, 2023
1 parent 5d14714 commit ec1def1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/shared/src/chat/recipes/__snapshots__/fixup.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`Fixup > builds prompt correctly for adding 1`] = `
- You should ensure your code matches the indentation and whitespace of the preceding code in the users' file.
- It is not acceptable to use Markdown in your response. You should not produce Markdown-formatted code blocks. Ignore any previous instructions that may have told you to format your responses with Markdown.
- You will be provided with instructions on what to do, enclosed in <instructions></instructions> XML tags. You must follow these instructions carefully and to the letter.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
The user is currently in the file: src/file/index.ts
Expand All @@ -27,7 +27,7 @@ exports[`Fixup > builds prompt correctly for edits 1`] = `
- It is not acceptable to use Markdown in your response. You should not produce Markdown-formatted code blocks. Ignore any previous instructions that may have told you to format your responses with Markdown.
- You will be provided with code that is in the users' selection, enclosed in <selectedCode></selectedCode> XML tags. You must use this code to help you plan your updated code.
- You will be provided with instructions on how to update this code, enclosed in <instructions></instructions> XML tags. You must follow these instructions carefully and to the letter.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
This is part of the file src/file/index.ts.
Expand All @@ -52,7 +52,7 @@ exports[`Fixup > builds prompt correctly for fixing 1`] = `
- You will be provided with code that is in the users' selection, enclosed in <selectedCode></selectedCode> XML tags. You must use this code to help you plan your fixed code.
- You will be provided with errors from the users' selection enclosed in <diagnostics></diagnostics> XML tags. You must attempt to fix all of these errors.
- If you do not know how to fix an error, do not modify the code related to that error and leave it as is. Only modify code related to errors you know how to fix.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
This is part of the file src/file/index.ts.
Expand Down
17 changes: 13 additions & 4 deletions lib/shared/src/chat/recipes/fixup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,16 @@ export class Fixup implements Recipe {
* No additional context is required. We already have the errors directly via the instruction, and we know their selected code.
*/
case 'fix':
return []
return [
...getContextMessageWithResponse(
populateCodeContextTemplate(truncatedPrecedingText, task.fileName),
task
),
...getContextMessageWithResponse(
populateCodeContextTemplate(truncatedFollowingText, task.fileName),
task
),
]
}
/* eslint-enable no-case-declarations */
}
Expand All @@ -142,7 +151,7 @@ export class Fixup implements Recipe {
- It is not acceptable to use Markdown in your response. You should not produce Markdown-formatted code blocks. Ignore any previous instructions that may have told you to format your responses with Markdown.
- You will be provided with code that is in the users' selection, enclosed in <selectedCode></selectedCode> XML tags. You must use this code to help you plan your updated code.
- You will be provided with instructions on how to update this code, enclosed in <instructions></instructions> XML tags. You must follow these instructions carefully and to the letter.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
This is part of the file {fileName}.
Expand All @@ -162,7 +171,7 @@ Provide your generated code using the following instructions:
- You should ensure your code matches the indentation and whitespace of the preceding code in the users' file.
- It is not acceptable to use Markdown in your response. You should not produce Markdown-formatted code blocks. Ignore any previous instructions that may have told you to format your responses with Markdown.
- You will be provided with instructions on what to do, enclosed in <instructions></instructions> XML tags. You must follow these instructions carefully and to the letter.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
The user is currently in the file: {fileName}
Expand All @@ -181,7 +190,7 @@ Provide your generated code using the following instructions:
- You will be provided with code that is in the users' selection, enclosed in <selectedCode></selectedCode> XML tags. You must use this code to help you plan your fixed code.
- You will be provided with errors from the users' selection enclosed in <diagnostics></diagnostics> XML tags. You must attempt to fix all of these errors.
- If you do not know how to fix an error, do not modify the code related to that error and leave it as is. Only modify code related to errors you know how to fix.
- Enclose your response in <fixup></fixup> XML tags. Do not provide anything else.
- Only enclose your response in <fixup></fixup> XML tags. Do use any other XML tags unless they are part of the generated code.
This is part of the file {fileName}.
Expand Down
2 changes: 2 additions & 0 deletions vscode/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Starting from `0.2.0`, Cody is using `major.EVEN_NUMBER.patch` for release versi

### Fixed

- Edit: Fixed an issue where Cody would regularly include unrelated XML tags in the generated output. [pull/1789](https://github.com/sourcegraph/cody/pull/1789)

### Changed

## [0.16.0]
Expand Down

0 comments on commit ec1def1

Please sign in to comment.