코드 제안 API

코드 제안 API를 사용하여 코드 제안 기능에 액세스할 수 있습니다.

코드 완성 생성

Status: Experiment
History
자체 관리형 GitLab의 경우, 기본적으로 이 기능을 사용할 수 없습니다. 관리자가 code_suggestions_completion_api라는 기능 플래그를 활성화하여 사용할 수 있습니다. GitLab.com 및 전용 GitLab에서는 이 기능을 사용할 수 없습니다. 이 기능은 생산 환경에 사용하기에 적합하지 않습니다.
POST /code_suggestions/completions
note
이 엔드포인트는 각 사용자를 1분 윈도우당 60개의 요청으로 제한합니다.

AI 추상화 레이어를 사용하여 코드 완성을 생성합니다.

이 엔드포인트로의 요청은 AI Gateway로 프록시됩니다.

매개변수:

속성 유형 필수 여부 설명
current_file 해시 코드 제안이 생성되는 파일의 속성. 이 속성이 허용하는 문자열 목록에 대한 설명은 파일 속성을 참조하십시오.
intent 문자열 아니요 완성 요청의 의도. 옵션: 완성 또는 제너레이션.
stream 부울 아니요 (적용 가능한 경우) 작은 청크로 응답을 스트리밍할지 여부. 기본값: false.
project_path 문자열 아니요 프로젝트의 경로.

파일 속성

current_file 속성은 다음 문자열을 허용합니다:

  • file_name - 파일의 이름. 필수.
  • content_above_cursor - 현재 커서 위치 위의 파일 내용. 필수.
  • content_below_cursor - 현재 커서 위치 아래의 파일 내용. 선택적.

예시 요청:

curl --request POST \
  --header "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
  --data '{
      "current_file": {
        "file_name": "car.py",
        "content_above_cursor": "class Car:\n    def __init__(self):\n        self.is_running = False\n        self.speed = 0\n    def increase_speed(self, increment):",
        "content_below_cursor": ""
      },
      "intent": "completion"
    }' \
  --url "https://gitlab.example.com/api/v4/code_suggestions/completions"

예시 응답:

{
  "id": "id",
  "model": {
    "engine": "vertex-ai",
    "name": "code-gecko"
  },
  "object": "text_completion",
  "created": 1688557841,
  "choices": [
    {
      "text": "\n        if self.is_running:\n            self.speed += increment\n            print(\"The car's speed is now",
      "index": 0,
      "finish_reason": "length"
    }
  ]
}