Skip to content

Add repository_id to v2 suggestions request

Tan Le requested to merge add-repository-id-v2 into main

What does this MR do and why?

This MR adds a new field named repository_id to the v2/completions request.

Relates to gitlab-org/gitlab-vscode-extension#638 (closed).

POST /v2/completions
Attribute Type Required Description Example
prompt_version int yes The version of the prompt 1
repository_name string yes The name of the repository (max_len: 255) gitlab-shell
repository_id (NEW) int yes The id of the repository 14022
current_file.file_name string yes The name of the current file (max_len: 255) README.md
current_file.content_above_cursor string yes The content above cursor (max_len: 100,000) import numpy as np
current_file.content_below_cursor string yes The project below cursor (max_len: 100,000) def __main__:\n

Example request:

curl --silent \
     --request POST \
     --url http://codesuggestions.gitlab.com/v2/completions \
     --header 'authorization: Bearer glpat-.....' \
     --header 'Content-Type: application/json' \
     --data '{
       "prompt_version": 1,
       "repository_name": "awesome_project",
       "repository_id": 8888,
       "current_file": {
         "file_name": "main.py",
         "content_above_cursor": "\"\"\"\nImplement fastapi middleware to log all incoming requests\"\"\"\n",
         "content_below_cursor": "robin"
       }
     }'

Example response:

{
  "id": "id",
  "model": "codegen",
  "object": "text_completion",
  "created": 1678282416,
  "choices": [
    {
      "text": "\nimport logging\n\nfrom fastapi import FastAPI\nfrom fastapi.",
      "index": 0,
      "finish_reason": "length"
    }
  ]
}

How to set up and validate locally

  1. Check out this branch
  2. Build a local Docker image
    docker buildx build -t code-suggestions-api:dev .
  3. Run the recently build docker image, map to port 5999 on localhost
    docker run --rm -p 5999:5000 -e AUTH_BYPASS_EXTERNAL=true -it code-suggestions-api:dev
  4. Use your favourite REST client or curl to hit the endpoint (hint: use jq to parse JSON response)
    curl --silent \
      --request POST \
      --url http://localhost:5999/v2/completions \
      --header 'Content-Type: application/json' \
      --data '{
        "prompt_version": 1,
        "repository_name": "awesome_project",
        "repository_id": 8888,
        "current_file": {
          "file_name": "main.py",
          "content_above_cursor": "\"\"\"\nImplement fastapi middleware to log all incoming requests\"\"\"\n",
          "content_below_cursor": "robin"
        }
      }' | jq .
    
    {
      "id": "id",
      "model": "codegen",
      "object": "text_completion",
      "created": 1678282416,
      "choices": [
        {
          "text": "\nimport logging\n\nfrom fastapi import FastAPI\nfrom fastapi.",
          "index": 0,
          "finish_reason": "length"
        }
      ]
    }
Edited by Tan Le

Merge request reports

Loading