fix: type errors
This commit is contained in:
parent
e92a8cd1c0
commit
70ae58594c
3 changed files with 23 additions and 37 deletions
|
|
@ -162,10 +162,7 @@ export class CompletionProvider {
|
|||
token = controller.signal;
|
||||
}
|
||||
|
||||
const [
|
||||
{ snippets, diff, clipboardContent, payload: snippetPayload },
|
||||
workspaceDirs,
|
||||
] = await Promise.all([
|
||||
const [snippetPayload, workspaceDirs] = await Promise.all([
|
||||
getAllSnippets({
|
||||
helper,
|
||||
ide: this.ide,
|
||||
|
|
@ -176,10 +173,7 @@ export class CompletionProvider {
|
|||
]);
|
||||
|
||||
const { prompt, prefix, suffix, completionOptions } = renderPrompt({
|
||||
snippets,
|
||||
snippetPayload,
|
||||
diff,
|
||||
clipboardContent,
|
||||
workspaceDirs,
|
||||
helper,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
import { CompletionOptions } from "../../index.js";
|
||||
import { getLastNPathParts, shortestRelativePaths } from "../../util/index.js";
|
||||
import { AutocompleteCodeSnippet } from "../snippets/types.js";
|
||||
import { AutocompleteSnippetDeprecated } from "../types.js";
|
||||
import {
|
||||
AutocompleteCodeSnippet,
|
||||
AutocompleteSnippet,
|
||||
AutocompleteSnippetType,
|
||||
} from "../snippets/types.js";
|
||||
|
||||
export interface AutocompleteTemplate {
|
||||
compilePrefixSuffix?: (
|
||||
|
|
@ -11,7 +14,7 @@ export interface AutocompleteTemplate {
|
|||
suffix: string,
|
||||
filepath: string,
|
||||
reponame: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
snippets: AutocompleteSnippet[],
|
||||
) => [string, string];
|
||||
template:
|
||||
| string
|
||||
|
|
@ -21,7 +24,7 @@ export interface AutocompleteTemplate {
|
|||
filepath: string,
|
||||
reponame: string,
|
||||
language: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
snippets: AutocompleteSnippet[],
|
||||
) => string);
|
||||
completionOptions?: Partial<CompletionOptions>;
|
||||
}
|
||||
|
|
@ -74,8 +77,12 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
|
|||
suffix: string,
|
||||
filepath: string,
|
||||
reponame: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
allSnippets: AutocompleteSnippet[],
|
||||
): [string, string] => {
|
||||
const snippets = allSnippets.filter(
|
||||
(snippet) => snippet.type === AutocompleteSnippetType.Code,
|
||||
) as AutocompleteCodeSnippet[];
|
||||
|
||||
if (snippets.length === 0) {
|
||||
if (suffix.trim().length === 0 && prefix.trim().length === 0) {
|
||||
return [`+++++ ${getLastNPathParts(filepath, 2)}\n${prefix}`, suffix];
|
||||
|
|
@ -96,14 +103,7 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
|
|||
suffix,
|
||||
];
|
||||
},
|
||||
template: (
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
filepath: string,
|
||||
reponame: string,
|
||||
language: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
): string => {
|
||||
template: (prefix: string, suffix: string): string => {
|
||||
return `[SUFFIX]${suffix}[PREFIX]${prefix}`;
|
||||
},
|
||||
completionOptions: {
|
||||
|
|
@ -134,7 +134,7 @@ const starcoder2FimTemplate: AutocompleteTemplate = {
|
|||
filename: string,
|
||||
reponame: string,
|
||||
language: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
snippets: AutocompleteSnippet[],
|
||||
): string => {
|
||||
const otherFiles =
|
||||
snippets.length === 0
|
||||
|
|
@ -187,8 +187,12 @@ const codegeexFimTemplate: AutocompleteTemplate = {
|
|||
filepath: string,
|
||||
reponame: string,
|
||||
language: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
allSnippets: AutocompleteSnippet[],
|
||||
): string => {
|
||||
const snippets = allSnippets.filter(
|
||||
(snippet) => snippet.type === AutocompleteSnippetType.Code,
|
||||
) as AutocompleteCodeSnippet[];
|
||||
|
||||
const relativePaths = shortestRelativePaths([
|
||||
...snippets.map((snippet) => snippet.filepath),
|
||||
filepath,
|
||||
|
|
@ -227,14 +231,7 @@ Fill in the blank to complete the code block. Your response should include only
|
|||
};
|
||||
|
||||
const holeFillerTemplate: AutocompleteTemplate = {
|
||||
template: (
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
filename: string,
|
||||
reponame: string,
|
||||
language: string,
|
||||
snippets: AutocompleteCodeSnippet[],
|
||||
) => {
|
||||
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.
|
||||
|
||||
|
|
|
|||
|
|
@ -47,20 +47,13 @@ function renderStringTemplate(
|
|||
}
|
||||
|
||||
export function renderPrompt({
|
||||
snippets,
|
||||
snippetPayload,
|
||||
workspaceDirs,
|
||||
helper,
|
||||
}: {
|
||||
snippets: AutocompleteCodeSnippet[];
|
||||
snippetPayload: SnippetPayload;
|
||||
workspaceDirs: string[];
|
||||
helper: HelperVars;
|
||||
diff?: string;
|
||||
clipboardContent: {
|
||||
text: string;
|
||||
copiedAt: string;
|
||||
};
|
||||
}): {
|
||||
prompt: string;
|
||||
prefix: string;
|
||||
|
|
@ -76,6 +69,8 @@ export function renderPrompt({
|
|||
const { template, compilePrefixSuffix, completionOptions } =
|
||||
getTemplate(helper);
|
||||
|
||||
const snippets = getSnippets(helper, snippetPayload);
|
||||
|
||||
// Some models have prompts that need two passes. This lets us pass the compiled prefix/suffix
|
||||
// into either the 2nd template to generate a raw string, or to pass prefix, suffix to a FIM endpoint
|
||||
if (compilePrefixSuffix) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue