Add CodeGeeX4 code completion support (#1815)
Includes support for context through code snippets and relative filename resolution.
This commit is contained in:
parent
58a7ee8369
commit
d6c2e36814
1 changed files with 34 additions and 0 deletions
|
|
@ -155,6 +155,36 @@ const deepseekFimTemplate: AutocompleteTemplate = {
|
|||
},
|
||||
};
|
||||
|
||||
// https://github.com/THUDM/CodeGeeX4/blob/main/guides/Infilling_guideline.md
|
||||
const codegeexFimTemplate: AutocompleteTemplate = {
|
||||
template: (
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
filepath: string,
|
||||
reponame: string,
|
||||
snippets: AutocompleteSnippet[],
|
||||
): string => {
|
||||
const relativePaths = shortestRelativePaths([
|
||||
...snippets.map((snippet) => snippet.filepath),
|
||||
filepath,
|
||||
]);
|
||||
const baseTemplate = `###PATH:${relativePaths[relativePaths.length - 1]}\n###LANGUAGE:\n###MODE:\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`;
|
||||
if (snippets.length == 0)
|
||||
{
|
||||
return baseTemplate;
|
||||
}
|
||||
const references =
|
||||
`###REFERENCE:\n${snippets
|
||||
.map((snippet, i) => `###PATH:${relativePaths[i]}\n${snippet.contents}\n`)
|
||||
.join("###REFERENCE:\n")}`;
|
||||
const prompt = `${references}\n${baseTemplate}`;
|
||||
return prompt;
|
||||
},
|
||||
completionOptions: {
|
||||
stop: ["<|code_suffix|>", "<|code_prefix|>", "<|code_middle|>"],
|
||||
},
|
||||
};
|
||||
|
||||
const gptAutocompleteTemplate: AutocompleteTemplate = {
|
||||
template: `\`\`\`
|
||||
{{{prefix}}}[BLANK]{{{suffix}}}
|
||||
|
|
@ -302,6 +332,10 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
|
|||
return deepseekFimTemplate;
|
||||
}
|
||||
|
||||
if (lowerCaseModel.includes("codegeex")) {
|
||||
return codegeexFimTemplate;
|
||||
}
|
||||
|
||||
if (
|
||||
lowerCaseModel.includes("gpt") ||
|
||||
lowerCaseModel.includes("davinci-002") ||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue