Skip to content
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

feat: add infill mode to anthropic claude instant #974

Merged
merged 1 commit into from
Sep 7, 2023
Merged

Conversation

abeatrix
Copy link
Contributor

@abeatrix abeatrix commented Sep 7, 2023

Close #811 #944 #1026

This PR contains changes related to adding "infill" mode to the Anthropic autocomplete provider for the Claude instant model:

  • A new CodyAutocompleteClaudeInstantInfill feature flag was added to the FeatureFlagProvider.
  • The vscode/package.json file was updated to include "claude-instant-infill" as a new advanced autocomplete model.
    • "cody.autocomplete.advanced.model": "claude-instant-infill"
  • createProvider.ts was updated to use the "infill" mode when "claude-instant-infill" is configured instead of the default mode for Anthropic claude-instant-1
  • AnthropicOptions now accepts a mode parameter to specify either 'default' (claude-instant-1) or 'infill' (claude-instant-infill).
  • AnthropicProvider has a new useInfillPrefix property to track whether infill mode is enabled.
  • When useInfillPrefix is true, getPromptPrefix will return different prompt context messages to guide the model to generate autocompletion with context awareness (infill).

Quick Demo

See improved suggestions on the right, vs suggestions provided by the latest release build on the left:
Screenshot 2023-09-06 at 1 20 52 PM

autocompletion_.compare.suggestions.before.after.mp4

Summary

This PR adds an "infill" mode to the Anthropic autocomplete provider Claude Instant model to generate more seamless completions based on surrounding code, which fixes issues where:

  • The current version of completion does not support including context after the cursor which leads to generating a lot of irrelevant suggestions that could be more helpful.
  • Issue where Cody suggests code that exists in the shared context

Before

Before.mp4

After

After.mp4

Resolve the issue where Cody suggests code that already exists

RE: #811 #944

As Claude instant was not intended to be used as a code completions model, additional prompt engineering is required to guide Claude to do the "right" thing, which includes asking Cluade not to complete the code with code already implemented.

update_.don.t.suggest.existing.code.mp4

Test plan

  1. Start Cody from this branch
  2. In your user config file, add: "cody.autocomplete.advanced.model": "claude-instant-infill"
  3. Try adding docstring above existing functions.
  • At first, you might need to type more to guide Cody to generating helpful suggestions, but it should work well in more structured files.

Compare the quality of suggestions you get from using this build with the ones from the stable release build that uses the claude instant model with the current prompt.

More examples

claude instant with infill vs starcoder:

starcoder.vs.claude.instant.-.code.comparison.mp4
starcoder.vs.claude.instant.-.code.comparison.mp4
starcoder.vs.claude.instant.-.suffix.mock.mp4

@abeatrix abeatrix requested a review from a team September 7, 2023 14:12
Copy link
Contributor

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so cool! Pinging @valerybugakov too but this looks safe enough to merge and try out.

There are some interesting diffs in the autocomplete test suite that I linked in the Slack thread but without actually improving the test suite OR running an A/B experiment, it’s so so hard to judge these nuances.

StarCoder vs Claude with Infill will be the battle of the giants. I've updated the temperature like we discussed last night for StarCoder too so it has gotten a bit more predictable.

Huge thank you for this awesome collaboration. You definitely managed to do what I couldn't.

Comment on lines +102 to +104
if (claudeInstantInfill === true) {
return { provider: 'anthropic', model: 'claude-instant-infill' }
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like if we set any starcoder FF to 50% and claude-instant-infill to 100% we can make a 50-50 test here 👍

@abeatrix
Copy link
Contributor Author

abeatrix commented Sep 7, 2023

ref

Here are the failed tests philipp mentioned above:
image

However, all the tests passed with the expected results when running them manually in the editor:
image
image
image
image

Will look into the test suite next.

See slack discussion for details: https://sourcegraph.slack.com/archives/C05AGQYD528/p1694095905077429

@abeatrix abeatrix merged commit 9edd9d8 into main Sep 7, 2023
12 checks passed
@abeatrix abeatrix deleted the bee/instant-mode branch September 7, 2023 15:44
abeatrix added a commit that referenced this pull request Sep 7, 2023
Forgot to add a changelog entry for
#974 😅

## Test plan

<!-- Required. See
https://docs.sourcegraph.com/dev/background-information/testing_principles.
-->

changelog update
},
{
speaker: 'human',
text: `Below is the code from file path ${this.options.fileName}. First, review the code outside of the ${OPENING_CODE_TAG} XML tags. Then complete the code inside the tags using the same style, patterns and logics of the surrounding code precisely without duplicating existing implementations:
Copy link
Member

@valerybugakov valerybugakov Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noice! This is a logical enhancement. We overlooked these low-hanging fruits because we hadn't been investing time into improving our prompt. It's great that we're addressing them now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocomplete: Cody suggests code that is already present
3 participants