Skip to content

feat: add code context to v2 completions API

Allen Cook requested to merge acook/v2_code_context into main

What does this merge request do and why?

Added code_context parameter to v2 completions API to match the one added to v3

{
  "current_file": {
    "file_name": "main.go",
    "language_identifier": "go",
    "content_above_cursor": "func parseEnvFile(filename string) (map[string]string, error) {",
    "content_below_cursor": "}"
  },
  "model_provider": "vertex-ai",
  "model_name": "code-gecko@002",
  "telemetry": [],
  "stream": true,
  "prompt_version": 2,
  "prompt": "func parseEnvFile(filename string)",
  "context": [
    {
      "content": "import os\\n\\tf, err := os.Open(filename)\\n",
      "name": "test",
      "type": "function"
    }
  ]
}

How to set up and validate locally

  1. submit code context parameter to v2 code completions
  2. Note how context is prepended to the prefix

Merge request checklist

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

Merge request reports