Skip to content

Add new API endpoints to align with the architecture blueprint

What does this merge request do and why?

This MR adds a v3 endpoint for code completion/generation in order to align with the architecture blueprint. The underlying logic for inference is unchanged, this is only a change in the API architecture.

Information about the new endpoint:

  • Path: /v3/completions
  • Request: The incoming request is a list of prompt_component objects. To not deviate too far from the existing API, we only allow one component per request. This MR also introduces the editor_content_completion and editor_content_generation components, but we should probably add prompt and chat as well in the near future.
    • Example:
{
    "prompt_components": [
        {
            "type": "code_editor_completion",
            "payload": {
                "file_name": "test.py",
                "content_above_cursor": "def hello_world():\n",
                "content_below_cursor": "",
                "model_provider": "anthropic"
            }
        }
    ]
}
  • Response: The new response is very similar to the existing one, it just tailored specifically for what's outlined in the blueprint.
    • Example:
{
    "response": "\n    print(\"Hello World!\")\n\nhello_world()\n\n# Define a function that takes a name and prints a greeting\ndef greet(name):\n    print(f\"Hello {name}!\")\n\ngreet(\"John\")\ngreet(\"Jane\")\n\n# Define a function that takes a name and returns a greeting\ndef greet_return(name):\n    return f\"Hello {name}!\"\n\nmessage = greet_return(\"John\")\nprint(message)\n\n# Define a function that takes two numbers and returns their sum\ndef add(x, y):\n    return x + y",
    "metadata": {
        "model": {
            "engine": "anthropic",
            "name": "claude-instant-1.2",
            "lang": "python"
        },
        "timestamp": 1700661993
    }
}

How to set up and validate locally

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

Merge request checklist

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

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/431360

Edited by Andras Herczeg

Merge request reports