Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Code completions #1476

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open

Conversation

mikeshi80
Copy link
Contributor

Added the support for code completions, support 3 kinds of completions:

  1. Common code completions, like generate model, it will continue to generate the code according inputted code above.
  2. Code infill completions, the more parameter "suffix" is provided, the model generates the content between prompt and suffix.
  3. Repository level code completions, just like common code completions, but the other files in the repository are provided too, to generate more precise content.

I added two RESTful APIs:

  1. /v1/code/prompt
  2. v1/code/completions

Users can get the generated prompt by call 1st API.

Common Code Completion

POST the JSON object

{
  "model": "code-completion-model-uid",
  "mode": "completion",
  "prompt": "#write a quick sort algorithm"
}

Repository Level Code Completion

Users can provide files parameter , which is the mapping, key is file name or file path (it is defined in code prompt style), value is the file content.

Some model need the repo_name, that presents repository name.

{
  "model": "code-completion-model-uid",
  "mode": "completion",
  "prompt": "#write a quick sort algorithm",
  "files": {
    "test.py": "test file content",
    "main.py": "main file content"
  },
  "repo_name": "my-test-repo"
}

Note: if the model does not support repository level completion, it works like common code completion, "files" and "repo_name" will be ignored.

Infill Code Completion

Users can use infill mode by set mode to "infill", and provide suffix parameter.

{
  "model": "code-completion-model-uid",
    "mode": "infill",
    "prompt": "def quick_sort(arr):\n    if len(arr) <= 1:\n        return arr\n    pivot = arr[0]\n    left = []\n    right = []\n",
    "suffix": "\n        if arr[i] < pivot:\n            left.append(arr[i])\n        else:\n            right.append(arr[i])\n    return quick_sort(left) + [pivot] + quick_sort(right)"
}

Note: if the model does not support infill mode, you will get the exception.

If /v1/code/prompt API works well, it will return the response like below:

{
  "prompt": "<|fim▁begin|>def quick_sort(arr):\n    if len(arr) <= 1:\n        return arr\n    pivot = arr[0]\n    left = []\n    right = []\n<|fim▁hole|>\n        if arr[i] < pivot:\n            left.append(arr[i])\n        else:\n            right.append(arr[i])\n    return quick_sort(left) + [pivot] + quick_sort(right)<|fim▁end|>"
}

When you get the generated prompt, you can pass it to /v1/completions to get the response.

If you want to combine 2 requests into 1, you can just use the 2nd RESTful API /v1/code/completions, it just combined generating prompt and completions requests.

@XprobeBot XprobeBot added this to the v0.11.1 milestone May 11, 2024
@qinxuye qinxuye changed the title Code completions FEAT: Code completions May 13, 2024
@XprobeBot XprobeBot modified the milestones: v0.11.1, v0.11.2 May 17, 2024
@XprobeBot XprobeBot modified the milestones: v0.11.2, v0.11.3 May 24, 2024
@XprobeBot XprobeBot modified the milestones: v0.11.3, v0.11.4, v0.12.0, v0.12.1 May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants