Skip to content

Add /completions endpoint to proxy to model gateway

Max Woolf requested to merge mw/ai/proxy-code-suggestions into master

What does this MR do and why?

  • Adds a new endpoint /code_suggestions/completions to the API.
  • Adds documentation.

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

  1. Enable the required feature flags. (:code_suggestions_tokens_api)
  2. Get a PAT for a user that is able to use code suggestions. (Should be enabled for the user's groups and for the user themselves.)
  3. Get a production JWT token by calling the /code_suggestions/tokens endpoint on SaaS.
  4. In your GDK, make a call to the new endpoint:
POST /api/v4/code_suggestions/completions
Authorization: Bearer <PAT>
X-Gitlab-Authentication-Type: oidc
X-Gitlab-Oidc-Token: <JWT TOKEN>

{"prompt_version":"1","current_file":{"file_name":"dog.js","content_above_cursor":"class Car:\n    def __init__(self, make, model, year, color):\n        self.make = make\n        self.model = model\n        self.year = year\n        self.color = color\n        self.is_running = False\n        self.speed = 0\n    \n    def start(self):\n        if not self.is_running:\n            self.is_running = True\n            print(\"The car is now running.\")\n        else:\n            print(\"The car is already running.\")\n    \n    def stop(self):\n        if self.is_running:\n            self.is_running = False\n            self.speed = 0\n            print(\"The car has stopped.\")\n        else:\n            print(\"The car is already stopped.\")\n    \n    def accelerate(self, increment):","content_below_cursor":""},"project_id":"23"}

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to: #416391 (closed)

Edited by Bojan Marjanovic

Merge request reports