Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutocompleteTemplate: Use modelfile template for granite3 #3314

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions core/autocomplete/templating/AutocompleteTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ Fill in the blank to complete the code block. Your response should include only
completionOptions: { stop: ["\n"] },
};

const holeFillerTemplate: AutocompleteTemplate = {
template: (prefix: string, suffix: string) => {
// From https://github.com/VictorTaelin/AI-scripts
const SYSTEM_MSG = `You are a HOLE FILLER. You are provided with a file containing holes, formatted as '{{HOLE_NAME}}'. Your TASK is to complete with a string to replace this hole with, inside a <COMPLETION/> XML tag, including context-aware indentation, if needed. All completions MUST be truthful, accurate, well-written and correct.
// From https://github.com/VictorTaelin/AI-scripts
const HOLE_FILLER_SYSTEM_MSG = `You are a HOLE FILLER. You are provided with a file containing holes, formatted as '{{HOLE_NAME}}'. Your TASK is to complete with a string to replace this hole with, inside a <COMPLETION/> XML tag, including context-aware indentation, if needed. All completions MUST be truthful, accurate, well-written and correct.

## EXAMPLE QUERY:

Expand Down Expand Up @@ -324,8 +322,10 @@ function hypothenuse(a, b) {

<COMPLETION>a ** 2 + </COMPLETION>`;

const holeFillerTemplate: AutocompleteTemplate = {
template: (prefix: string, suffix: string) => {
const fullPrompt =
SYSTEM_MSG +
HOLE_FILLER_SYSTEM_MSG +
`\n\n<QUERY>\n${prefix}{{FILL_HERE}}${suffix}\n</QUERY>\nTASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion, and NOTHING ELSE. Do it now.\n<COMPLETION>`;
return fullPrompt;
},
Expand All @@ -334,6 +334,17 @@ function hypothenuse(a, b) {
},
};

const graniteHoleFillerTemplate: AutocompleteTemplate = {
template: (prefix: string, suffix: string) => {
const request = `<QUERY>\n${prefix}{{FILL_HERE}}${suffix}\n</QUERY>\nTASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion, and NOTHING ELSE.`;

return `<|start_of_role|>system<|end_of_role|>${HOLE_FILLER_SYSTEM_MSG}<|end_of_text|>\n<|start_of_role|>user<|end_of_role|>${request}<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>`;
},
completionOptions: {
stop: ["<|end_of_text|>", "<|start_of_role|>", "</COMPLETION>"],
},
};

export function getTemplateForModel(model: string): AutocompleteTemplate {
const lowerCaseModel = model.toLowerCase();

Expand Down Expand Up @@ -380,11 +391,14 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
if (
lowerCaseModel.includes("gpt") ||
lowerCaseModel.includes("davinci-002") ||
lowerCaseModel.includes("claude") ||
lowerCaseModel.includes("granite3")
lowerCaseModel.includes("claude")
) {
return holeFillerTemplate;
}

if (lowerCaseModel.includes("granite3")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lowerCaseModel.includes("granite3") && !lowerCaseModel.includes("-code")

future proofing the next models that'll support FIM

return graniteHoleFillerTemplate;
}

return stableCodeFimTemplate;
}
Loading