Smart Competition: Prompt Formatting in IDE for Code Creation
Goal
As part of our Competitive Intelligence efforts we need to capture all relevant recourses for code-completion
Findings
This is a POST request with two headers, and several body parameters.
The headers are described below:
-
authorization
header that should allow us authorization to this feature -
Content-Type
header that of course we as kind developers will include because it is the polite thing to do, and also it tells GitLab that we will be.
The body parameters:
-
prompt_version
is as far as I can tell a broadly useless parameters but I am waiting for for confirmation from @mikolaj_wawrzyniak -
project_path
is the project namespace with path -
project_id
the id of the project -
current_file
an object containing several parameters related to the file -
current_file.file_name
is the filename "filename.ext" -
current_file.content_above_cursor
is the code before where the cursor with no modification -
current_file.content_below_cursor
is the code that is after the cursor with no modification -
intent
is the intention when calling the endpoint, there are only two options "generation" or "completion" (the default is "completion") -
stream
is a boolean that describes if the results should be streamed (the default is false)
As far as I can tell there is no modification of the input test as it passes from IDE to the backend, with the only exception being that it won't send the data if the combined length is less than 10 characters long.
// Pulled from VS Code Extension Repository
static #getPrompt(
document: vscode.TextDocument,
position: vscode.Position,
project: GitLabProject | undefined,
): CodeSuggestionPrompt | undefined {
const contentBeforeCursor = document.getText(
new vscode.Range(0, 0, position.line, position.character),
);
const contentAfterCursor = document.getText(
new vscode.Range(position.line, position.character, document.lineCount, 0),
);
const contentLength = contentBeforeCursor.length + contentAfterCursor.length;
if (contentLength < CODE_SUGGESTIONS_MIN_LENGTH) {
log.debug(
`Code suggestion: Cancelling Prompt building as content length (${contentLength}) is less than ${CODE_SUGGESTIONS_MIN_LENGTH}`,
);
return undefined;
}
Take Aways
Once we have the ability to call the endpoint as we do with any of our other models we should be ready to go!
Links / references
Edited by Stephan Rayner