Skip to content

Instruct the prompt to not repeat existing comments

Allen Cook requested to merge acook/repeat_comments_skip_generations_fix into master

What does this MR do and why?

When using the LLM for generation instruction extraction, the LLM more frequently wants to comment and explain the code. These additional instructions ensure it does not repeat existing comments

Resolves #431267 (closed)

Screenshots or screen recordings

POST /api/v4/code_suggestions/completions

{
  "current_file": {
    "file_name": "test.js",
    "content_above_cursor": "function validateAustrianPostalCode(postalCode) { \n// validate austrian postal code",
    "content_below_cursor": "\n}"
  },
  "repositories": []
}

Result

{
  "id": "id",
  "model": {
    "engine": "anthropic",
    "name": "claude-2",
    "lang": "js"
  },
...
  "choices": [
    {
      "text": "\nconst postalCodeRegex = /^[1-9][0-9]{3}$/;\n\nif (!postalCodeRegex.test(postalCode)) {\n  return false; \n}\n\nreturn true;\n",
      "index": 0,
      "finish_reason": "length"
    }
  ]
}

How to set up and validate locally

  1. Enable code completion for your local instance according to instructions
  2. Enable the code_generation_anthropic and skip_code_generation_instruction_extraction feature flags
  3. Send a code completion request with a comment just before the cursor
  4. The response should not have that comment in it's choices text

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Allen Cook

Merge request reports