Code Suggestions development guidelines

Code Suggestions development setup

The recommended setup for locally developing and debugging Code Suggestions is to have all 3 different components running:

  • IDE Extension (e.g. VS Code Extension).
  • Main application configured correctly (e.g. GDK).
  • AI Gateway.

This should enable everyone to see locally any change in an IDE being sent to the main application transformed to a prompt which is then sent to the respective model.

Setup instructions

  1. Install and run locally the VS Code Extension:
    1. Add the "gitlab.debug": true info to the Code Suggestions development config:
      1. In VS Code, go to the Extensions page and find “GitLab Workflow” in the list.
      2. Open the extension settings by clicking a small cog icon and select “Extension Settings” option.
      3. Check a “GitLab: Debug” checkbox.
    2. If you’d like to test code suggestions are working from inside the VS Code Extension, then follow the steps to set up a personal access token with your GDK inside the new window of VS Code that pops up when you run the “Run and Debug” command.
      • Once you complete the steps below, to test you are hitting your local /code_suggestions/completions endpoint and not production, follow these steps:
        1. Inside the new window, in the built in terminal select the “Output” tab then “GitLab Language Server” from the drop down menu on the right.
        2. Open a new file inside of this VS Code window and begin typing to see code suggestions in action.
        3. You will see completion request URLs being fetched that match the Git remote URL for your GDK.
  2. Main Application (GDK):
    1. Install the GitLab Development Kit.
    2. Enable Feature Flag ai_duo_code_suggestions_switch:
      1. In your terminal, go to your gitlab-development-kit > gitlab directory.
      2. Run gdk rails console or bundle exec rails c to start a Rails console.
      3. Enable the Feature Flag for the code suggestions tokens API by calling Feature.enable(:ai_duo_code_suggestions_switch) from the console.
    3. Set the AI Gateway URL environmental variable by running export AI_GATEWAY_URL=http://localhost:5052.
    4. Run your GDK server with gdk start if it’s not already running.
  3. Setup AI Gateway:
    1. Run the AI Gateway as part of your GDK
      1. Follow the “How to set up and validate locally” steps in this MR
      2. Be sure to add your ANTHROPIC_API_KEY to your GDK’s gitlab-ai-gateway/.env file
    2. Run the AI Gateway externally
      1. Complete the steps to run the server locally.
      2. Uncomment or add the following variables in the .env file for all debugging insights. You may need to adjust the filepath (remove ..) for this log to show in the ai-assist root directory.

        AIGW_LOGGING__LEVEL=debug
        AIGW_LOGGING__FORMAT_JSON=false
        AIGW_LOGGING__TO_FILE=../modelgateway_debug.log
        
      3. Watch the new log file modelgateway_debug.log.

        tail -f modelgateway_debug.log | fblog -a prefix -a suffix -a current_file_name -a suggestion -a language -a input -a parameters -a score -a exception
        

Setup instructions to use staging AI Gateway

When testing interactions with the AI Gateway, you might want to integrate your local GDK with the deployed staging AI Gateway. To do this:

  1. You need a cloud staging license that has the Code Suggestions add-on, because add-ons are enabled on staging. Drop a note in the #s_fulfillment or s_fulfillment_engineering internal Slack channel to request an add-on to your license. See this handbook page for how to request a license for local development.
  2. Set environment variables to point customers-dot to staging, and the AI Gateway to staging:

    export GITLAB_LICENSE_MODE=test
    export CUSTOMER_PORTAL_URL=https://customers.staging.gitlab.com
    export AI_GATEWAY_URL=https://cloud.staging.gitlab.com/ai
    
  3. Restart the GDK.
  4. Ensure you followed the necessary steps to enable the Code Suggestions feature.
  5. Test out the Code Suggestions feature by opening the Web IDE for a project.

Setup instructions to use GDK with the Code Suggestions Add-on

On February 15, 2023 we will require the code suggestions add-on subscription to be able to use code suggestions. To set up your GDK for local development using the add-on, please follow these steps:

  1. Drop a note in the #s_fulfillment or s_fulfillment_engineering internal Slack channel to request an activation code with the Code Suggestions add-on.
  2. Someone will reach out to you with a code.
  3. Follow the activation instructions:
    1. Set environment variables.
    export GITLAB_LICENSE_MODE=test
    export CUSTOMER_PORTAL_URL=https://customers.staging.gitlab.com
    export GITLAB_SIMULATE_SAAS=0
    
    1. Restart your GDK.
    2. Go to /admin/subscription.
    3. Remove any active license.
    4. Add the new activation code.
  4. Inside your GDK, navigate to Admin Area > GitLab Duo Pro, go to /admin/code_suggestions
  5. Filter users to find root and click the toggle to assign a GitLab Duo Pro add-on seat to the root user