Skip to content

feat: add xray data to /refactor, /fix, and /tests prompts

What does this merge request do and why?

For gitlab-org/gitlab#450753 (closed)

The Repository X-Ray is a tool that searches for dependency manager configuration/lock files and then extracts a list of libraries from the content.

gitlab-org/gitlab!173750 (merged) fetches the latest xray report (if available) for a project and includes this xray_data in the prompt_options that are passed to the aigw for /refactor, /fix, and /tests. This MR then adds the xray_data to the corresponding prompts in the aigw. Given this context the code refactored/fixed/with tests should be more relevant and higher quality.

How to set up and validate locally

  1. Set up LangSmith tracing for Duo Chat: https://docs.gitlab.com/ee/development/ai_features/duo_chat.html#use-tracing-with-langsmith
  2. Follow the validation steps in this related MR to trigger creating an xray report for a project in gdk. Make a note of the project id where the xray report was generated: gitlab-org/gitlab!165391 (merged)
  3. Run gdk locally but gdk stop gitlab-ai-gateway, we're going to run this separately
  4. Open a second terminal and cd gitlab-ai-gateway then poetry shell and poetry run ai_gateway
  5. Go to the graphql explorer: http://gdk.test:3000/-/graphql-explorer
  6. Run a mutation to trigger /refactor, /fix, or /tests, be sure to pass in the correct id for the project where you created an xray report
    mutation {
      aiAction(
        input: {
          chat: {
            content: "/refactor", 
            currentFile: {
              selectedText: "\n@sold_items = %w( onions garlic potatoes ) \ndef print_report\nputs '*** Sales Report for #{Time.new.strftime('%d/%m/%Y')} ***'\n@sold_items.each { |i| puts i }\nputs '*** End of Sales Report ***'\nend",
              fileName: "hello.rb"
            },
            resourceId: "gid://gitlab/Project/25"
          },
        }
      ) {
        clientMutationId
        errors
      }
    }
  7. Open LangSmith and go to the project you set up for tracing. You should see a new run for the /refactor call you just made
  8. The ChatAnthropic section shows the compiled System prompt. Verify that the prompt includes the injected xray libraries!

Here are some examples:

Screenshots or screen recordings

See 👉 gitlab-org/gitlab!173750 (merged)

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Missy Davies

Merge request reports

Loading