updated prompt formatting

This commit is contained in:
Leyla Becker 2025-07-19 15:25:16 -05:00
parent e83fe9b479
commit 6743ea6ece

View file

@ -5,11 +5,11 @@ import { Ollama } from 'ollama/browser';
const MODEL = 'deepseek-coder:6.7b';
const PREFIX_START = '<fileStart>';
const PREFIX_END = '</fileStart>';
const PREFIX_START = '<prefixStart>';
const PREFIX_END = '<prefixEnd>';
const SUFFIX_START = '<fileEnd>';
const SUFFIX_END = '</fileEnd>';
const SUFFIX_START = '<suffixStart>';
const SUFFIX_END = '<suffixEnd>';
const MAX_TOKENS = 50;
const GENERATION_TIMEOUT = 200;
@ -35,12 +35,15 @@ const getModelSupportsSuffix = async (model: string) => {
const getPrompt = (document: vscode.TextDocument, position: vscode.Position) => {
const prefix = document.getText(new vscode.Range(0, 0, position.line, position.character));
const messageHeader = `In an english code base with the file.\nfile:\nproject {PROJECT_NAME}\nfile {FILE_NAME}\nlanguage {LANG}\nFile:\n${PREFIX_START}\n`;
const prompt = messageHeader
const messageHeader = `In an english code base with the file.\nfile:\nproject {PROJECT_NAME}\nfile {FILE_NAME}\nlanguage {LANG}`
.replace("{PROJECT_NAME}", vscode.workspace.name || "Untitled")
.replace("{FILE_NAME}", document.fileName)
.replace("{LANG}", document.languageId) + prefix;
.replace("{LANG}", document.languageId);
const message = `File:\n${PREFIX_START}`;
const prompt = `${messageHeader}\n${message}\n${prefix}`;
return prompt;
};
@ -52,7 +55,7 @@ const getPromptWithSuffix = (document: vscode.TextDocument, position: vscode.Pos
const messageSuffix = `End of the file:\n${SUFFIX_START}\n${suffix}\n${SUFFIX_END}\n`;
const messagePrefix = `Start of the file:\n${PREFIX_START}`;
const messageHeader = `In an english code base with the file.\nfile:\nproject {PROJECT_NAME}\nfile {FILE_NAME}\nlanguage {LANG}\nThis is the end of and then the start of the file.`
const messageHeader = `In an english code base with the file.\nfile:\nproject {PROJECT_NAME}\nfile {FILE_NAME}\nlanguage {LANG}\n.`
.replace("{PROJECT_NAME}", vscode.workspace.name || "Untitled")
.replace("{FILE_NAME}", document.fileName)
.replace("{LANG}", document.languageId);
@ -97,9 +100,9 @@ export const activate = (context: vscode.ExtensionContext) => {
console.log('"ai-code" extensions loaded');
const provider: vscode.InlineCompletionItemProvider = {
async provideInlineCompletionItems(document, position, context, _token) {
async provideInlineCompletionItems(document, position, context, token) {
try {
const response = await tokenProvider(document, position, context, _token);
const response = await tokenProvider(document, position, context, token);
const resultBuffer: string[] = await new Promise(async (resolve, reject) => {
const buffer: string[] = [];