From 27613e21c152f011e470d6ccc277d99288e15049 Mon Sep 17 00:00:00 2001 From: Nathan Hedge <23344786+10Nates@users.noreply.github.com> Date: Wed, 20 Dec 2023 13:43:44 -0600 Subject: [PATCH] got it to at least work mostly --- package.json | 11 ++++++++--- src/extension.ts | 11 ++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a60dfb4..edd830f 100644 --- a/package.json +++ b/package.json @@ -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." } } } diff --git a/src/extension.ts b/src/extension.ts index ac2bbd5..ba75afc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 } } );