-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update post process logic for claude instant #1440
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we separate the bug fix from the prompt changes and put the prompt changes behind the feature flag so that we can test how they affect CAR in production before making it a default?
The prompt updates look logical, and I expect them to perform well, but with LLMs, we never know how newly added tokens will affect the output. We have quite a few changes here, from the sentence structure updates to changing the code block tags. Splitting this PR in two would make it easier to reason about CAR changes later:
- Minimal prompt change required to fix a bug + logic updates.
- Prompt updates behind the feature flag.
@valerybugakov that's fair, I can do that next! Have you tried the change in this PR yet? Is it working for you? |
}, | ||
{ | ||
speaker: 'human', | ||
text: `Below is the code from file path ${relativeFilePath}. Review the code outside the XML tags to detect the functionality, formats, style, patterns, and logics in use. Then, use what you detect and reuse methods/libraries to complete and enclose completed code only inside XML tags precisely without duplicating existing implementations. Here is the code: \n\`\`\`\n${infillPrefix}${OPENING_CODE_TAG}${infillBlock}${CLOSING_CODE_TAG}${infillSuffix}\n\`\`\``, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't split the prompt anymore between "head" and "tail", should we remove the whole getHeadAndTail
function?
TBH I’m happy to move fast with this given how big our regression is right now. My only thinking is that:
once you're happy with the results we should push out a patch release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preemptive stamp but lets make sure the tests are good
@philipp-spiess @valerybugakov I tried to make minimal prompt change as possible but the one we had just doesn't work anymore because of the lines and whitespaces removed on claude side. I added <cursor> to the end of the infill block to make sure the spaces are not removed, and it seems to work fine on my side, but i wasn't able to get the eval tests to work to confirm if there is other regression, but definately better than what is in prod right now. If this is good for now, please feel free to merge and make a patch release on monday to make sure our users are not getting affected, and I can do any required follow up works |
@abeatrix I pushed a fix for the local completions test and there seem to be some issues with the newly used XML leaking into the completion: Also the test case with a comment followed by a |
@valerybugakov After taking a look at the issue with @philipp-spiess , it looks like the root cause of the issue was the new Updatelooks like the issue (at current main) is when the current line ends with non-bracket, we will display the suggestion after trimming start() It doesn't happen if prefix ends with bracket (or if we remove the postProcess logic) @valerybugakov the change in my latest commit where I remove the space after the |
@@ -67,7 +67,7 @@ export class AnthropicProvider extends Provider { | |||
const { head, tail, overlap } = getHeadAndTail(this.options.docContext.prefix) | |||
|
|||
// Infill block represents the code we want the model to complete | |||
const infillBlock = tail.trimmed | |||
const infillBlock = tail.trimmed.endsWith('{\n') ? tail.trimmed.trimEnd() : tail.trimmed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this allows claude to response with multi-line completion on new line after the {
bracket
@@ -216,6 +216,10 @@ export class AnthropicProvider extends Provider { | |||
// leading `\n` followed by whitespace that Claude might add. | |||
completion = completion.replace(/^\s*\n\s*/, '') | |||
} else { | |||
// prevent normalizeStartLine from removing the starting new line | |||
if (completion.startsWith('\n')) { | |||
completion = '\n' + completion.trimStart() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normalizeStartLine
in parseAndTruncateCompletion
would remove the \n
if it follows by indentation when prefix didn't end with closing bracket (Need Valery to confirm if this is intended ). This solves the aforementioned issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the logic to normalizeStartLine
only for multiline completions like before my changes in this PR. It fixes the issue without adding the additional logic. Thank you for narrowing down this regression!
@abeatrix, thank you for sharing the context! I'm debugging it locally and will merge this if I can confirm your findings 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After my change, I verified that the cases mentioned here still work locally as expected. Regenerated completions using the generate:completions
to ensure we do not have any leaking XML tags.
The PR is blocked by eslint errors on main. Fixing it here: #1471 |
Patch release for p1 bugs - #1477 - #1440 - Update default prompt mixin ## Test plan <!-- Required. See https://docs.sourcegraph.com/dev/background-information/testing_principles. --> version bump
fix: use full infill block and adjust prefix
Test plan
Fix: show multi-line completion after
{
:Fix: show multi-line completions the line after
{