got it to at least work mostly

This commit is contained in:
Nathan Hedge 2023-12-20 13:43:44 -06:00
parent b8e3d0b97b
commit 27613e21c1
No known key found for this signature in database
GPG Key ID: 1ADBA36D6E304C5C
2 changed files with 14 additions and 8 deletions

View File

@ -33,9 +33,14 @@
"description": "The model to use for generating completions"
},
"ollama-coder.system-message": {
"type": "string | undefined",
"default": null,
"description": "The system message to use for code completions"
"type": "string",
"default": "You are a code autocompletion engine. Respond with a continuation of the code provided and nothing else. Code should not be in a code block. Anything that is not code should be written as a code comment.",
"description": "The system message to use for code completions. Type DEFAULT for Makefile."
},
"ollama-coder.max-tokens-predicted": {
"type": "integer",
"default": 500,
"description": "The system message to use for code completions. Type DEFAULT for Makefile."
}
}
}

View File

@ -5,8 +5,9 @@ import axios from "axios";
const apiEndpoint: string = vscode.workspace.getConfiguration("ollama-coder").get("apiEndpoint") || "http://localhost:11434/api/generate";
const apiModel: string = vscode.workspace.getConfiguration("ollama-coder").get("model") || "deepseek-coder";
const apiSystemMessage: string | undefined = vscode.workspace.getConfiguration("ollama-coder").get("system-message");
const documentRange = 2000;
let apiSystemMessage: string | undefined = vscode.workspace.getConfiguration("ollama-coder").get("system-message");
if (apiSystemMessage == "DEFAULT") apiSystemMessage = undefined;
const numPredict: number = vscode.workspace.getConfiguration("ollama-coder").get("max-tokens-predicted") || 500;
// This method is called when your extension is activated
function activate(context: vscode.ExtensionContext) {
@ -15,7 +16,7 @@ function activate(context: vscode.ExtensionContext) {
const provider = vscode.languages.registerCompletionItemProvider("javascript", {
async provideCompletionItems(document, position) {
// Get the current prompt
const prompt = document.lineAt(position.line).text.substring(0, position.character);
const prompt = document.getText(new vscode.Range(document.lineAt(0).range.start, position));
// Check if the prompt is not empty and ends with a dot
if (prompt) {
// Create a completion item
@ -35,7 +36,7 @@ function activate(context: vscode.ExtensionContext) {
}
},
},
"."
"\n", " "
);
// Add the completion provider to the context
@ -60,7 +61,7 @@ function activate(context: vscode.ExtensionContext) {
stream: false,
system: apiSystemMessage,
options: {
num_predict: 100
num_predict: numPredict
}
}
);