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

refactor: update preamble rules and mixin #1442

Merged
merged 1 commit into from
Oct 23, 2023
Merged

refactor: update preamble rules and mixin #1442

merged 1 commit into from
Oct 23, 2023

Conversation

abeatrix
Copy link
Contributor

Updating current preamble, rules, and prompt mixin with new findings from #907.

Issue 1: Cody hallucinates about file path and code

One of the main issues we saw in Chat is Cody hallucinating about files and code that do not exist in the shared context.

I noticed this is mainly because of how we phrased our context, as Cody do not understand the relationship between each code snippet we share with them. For more information, see #907 (comment)

One of the many prompts I've tried to prevent hallucination is to add Do not make any assumptions about the code and file names or any misleading information to the question, which has been working well for me. This is also the prompt we added to all our commands. A customer has also confirmed that adding this to their questions stopped Cody from hallucinating and received better responses from Chat, this is why I propose adding it to PromptMixin, which will be added to the start of every question (instead of Preabmle, which is added to the start of the session and will get left out as the conversation gets longer.)

I don't think this will be 100% hallucination-proof, but it works a lot better than what we currently have.

Before

  • lib/share/ui/src/components/CodeBlock is not the correct path

Screenshot 2023-10-18 at 2 45 49 PM

After

  • make well-informed answers

Screenshot 2023-10-18 at 2 47 07 PM

Issue 2: The current preambles need to be updated, and not working as intended most of the times.

Addressed by this PR with the following changes:

  • Simplified the preamble actions and rules text to be more concise.
  • Removed redundant rules that will always be false, e.g. Cody never has direct access to your file or repository even when we tell them they do.
  • Removed detailed instructions about code formatting and limitations, leaving just the essential rules
  • Shortened the preamble answer to focus on the core assistant persona and capabilities

Issue 3: Cody will not answer in language that is not the default language of the editor

CLOSE https://github.com/sourcegraph/cody/discussions/1011 && #988

Many users have complained that they cannot get Cody to answer their questions because Cody refused to answer questions that is not the same as the default language of the editor.

Addressed by this PR with the following changes: Remove languagePromptMixin from the activate event for editors, which allows Cody to answer in the same language as the question

Before

Screenshot 2023-10-19 at 5 08 17 PM

After

Screenshot 2023-10-19 at 5 07 57 PM

Test plan

  1. Ask Cody a question in another language that is not the same as your editor. Cody should still be able to answer your question in the same language.
  2. Ask Cody a question in editor, and then ask the same question in Web to compare the quality. Questions where Cody hallucinates on Web should not happen in the editor when using the updated prompts.

Example question to ask in the cody repo: Do we format the completion item before we suggest them?

image

@abeatrix abeatrix requested a review from a team October 20, 2023 00:48
Copy link
Member

@valerybugakov valerybugakov left a comment

Choose a reason for hiding this comment

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

Love the idea of adding Never make any assumptions nor provide any misleading or hypothetical examples.' to the prompt!

Asked questions about other changes in the PR.

- If you do not have access to a repository, tell me to add additional repositories to the chat context using repositories selector below the input box to help you answer the question.
- Only reference file names, repository names or URLs if you are sure they exist.`
const multiRepoRules = `Important rules to follow in all your responses:
- All code snippets must be markdown-formatted, and enclosed in triple backticks.
Copy link
Member

Choose a reason for hiding this comment

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

What's the rationale for removing the triple backticks example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From my experience, It is harder to tell Claude not to return code with backticks than including them lol It was a big issue for fixup because it would includes the backticks in the edited code 😓
I don't think Claude has any problem connecting triple backticks with markdown, so the example IMO is unnecessary. Here is an example:

image

@@ -39,7 +39,7 @@ export interface PlatformContext {

export function activate(context: vscode.ExtensionContext, platformContext: PlatformContext): ExtensionApi {
const api = new ExtensionApi()
PromptMixin.add(languagePromptMixin(vscode.env.language))
PromptMixin.add(defaultPromptMixin())
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to A/B test prompt changes as we do with autocomplete improvements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we have one but not sure if it's active 😅

*/
export function defaultPromptMixin(): PromptMixin {
const identity = 'Reply as Cody, a coding assistant developed by Sourcegraph.'
const hallucinate = 'Never make any assumptions nor provide any misleading or hypothetical examples.'
Copy link
Member

Choose a reason for hiding this comment

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

It would be interesting to test how this sentence affects CAR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha we can put it behind a feature flag.

Can't wait to move to Starcoder so we don't have to worry about this 😏

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Can't wait to move to Starcoder so we don't have to worry about this 😏

May I remind you of https://huggingface.co/bigcode/starcoder/discussions/50#647f8078222b8c6a6f3e1c27 😆

const answer = `Understood. I am Cody, an AI assistant made by Sourcegraph to help with programming tasks.
I work inside a text editor. I have access to your currently open files in the editor.
const answer = `Understood. I am Cody, an AI assistant developed by Sourcegraph to help with programming tasks.
I am working with you inside an editor, and I will answer your questions based on the context you provide from your current codebases.
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, did you find that the present continuous tense works better for the prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do. I actually learnt this from Claude's docs: https://docs.anthropic.com/claude/docs/advanced-text-analysis

They also mentioned somewhere in their docs that it is better to speak to Claude in first person instead of third :)

Copy link
Member

Choose a reason for hiding this comment

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

Nice, thanks for sharing the doc!

@jdorfman
Copy link
Member

This is a massive win for our users. Thanks, @abeatrix for digging in!

@abeatrix abeatrix merged commit c733de3 into main Oct 23, 2023
14 checks passed
@abeatrix abeatrix deleted the bee/new-rules branch October 23, 2023 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants