Skip to content

Use selected text in base prompt if present

Jan Provaznik requested to merge jp-tasks-code into master

What does this MR do and why?

When user selects some code, it makes sense to include this in the prompt (and prefer over blob from referrer).

Related to #431359 (closed)

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. In rails console enable code_tasks
    Feature.enable(:code_tasks)
  2. Open gitlab duo chat UI
  3. In a separate browser tab open graphql-explorer and send message request below:
mutation {
  aiAction(input: {chat: {content: "Refactor selected code", currentFile: {
    fileName: "test.py",
    selectedText: "
def extract
  lines = content.to_s.lines
  comment_block = []
  trimmed_lines = 0
end
",
    contentAboveCursor: "
module CodeSuggestions
  class InstructionsExtractor
    EMPTY_LINES_LIMIT = 1
    MIN_LINES_OF_CODE = 5
",
  }}}) {
    clientMutationId
    errors
  }
}
  1. check in chat UI that an answer relevant to the selected text is returned

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 Jan Provaznik

Merge request reports