Merge pull request #3025 from fbricon/granite-tweaks

Tweak Granite template and postprocessing
This commit is contained in:
Nate Sesti 2024-11-21 21:03:51 -08:00 • committed by GitHub
commit 28c84c8211
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 6 deletions

View file

@ -83,6 +83,7 @@ export const LINES_TO_REMOVE_BEFORE_START = [
"<COMPLETION>",
"[CODE]",
"<START EDITING HERE>",
"{{FILL_HERE}}"
];
export const ENGLISH_START_PHRASES = [

View file

@ -83,6 +83,24 @@ export function postprocessCompletion({
}
}
if (llm.model.includes("granite")) {
// Granite tends to repeat the start of the line in the completion output
let prefixEnd = prefix.split("\n").pop();
if (prefixEnd) {
if (completion.startsWith(prefixEnd)) {
completion = completion.slice(prefixEnd.length);
} else {
const trimmedPrefix = prefixEnd.trim();
const lastWord = trimmedPrefix.split(/\s+/).pop();
if (lastWord && completion.startsWith(lastWord)) {
completion = completion.slice(lastWord.length);
} else if (completion.startsWith(trimmedPrefix)) {
completion = completion.slice(trimmedPrefix.length);
}
}
}
}
// // If completion starts with multiple whitespaces, but the cursor is at the end of the line
// // then it should probably be on a new line
// if (
@ -99,7 +117,6 @@ export function postprocessCompletion({
prefix.endsWith(" ") &&
completion.startsWith(" ")
) {
const test = prefix.split("\n").pop()?.trim() !== "";
completion = completion.slice(1);
}

View file

@ -376,7 +376,8 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
if (
lowerCaseModel.includes("gpt") ||
lowerCaseModel.includes("davinci-002") ||
lowerCaseModel.includes("claude")
lowerCaseModel.includes("claude") ||
lowerCaseModel.includes("granite3")
) {
return holeFillerTemplate;
}

View file

@ -469,7 +469,7 @@ export abstract class BaseLLM implements ILLM {
);
if (log && this.writeLog) {
await this.writeLog(`Completion:\n\n${completion}\n\n`);
await this.writeLog(`Completion:\n${completion}\n\n`);
}
return {
@ -521,7 +521,7 @@ export abstract class BaseLLM implements ILLM {
this._logTokensGenerated(completionOptions.model, prompt, completion);
if (log && this.writeLog) {
await this.writeLog(`Completion:\n\n${completion}\n\n`);
await this.writeLog(`Completion:\n${completion}\n\n`);
}
}
@ -562,7 +562,7 @@ export abstract class BaseLLM implements ILLM {
this._logTokensGenerated(completionOptions.model, prompt, completion);
if (log && this.writeLog) {
await this.writeLog(`Completion:\n\n${completion}\n\n`);
await this.writeLog(`Completion:\n${completion}\n\n`);
}
return completion;
@ -628,7 +628,7 @@ export abstract class BaseLLM implements ILLM {
this._logTokensGenerated(completionOptions.model, prompt, completion);
if (log && this.writeLog) {
await this.writeLog(`Completion:\n\n${completion}\n\n`);
await this.writeLog(`Completion:\n${completion}\n\n`);
}
return {