1- import { type AutoCompleteContext } from "./context" ;
1+ import { Prompt } from 'ai' ;
2+ import { ProviderOptions } from '@ai-sdk/provider-utils' ;
23
34export interface HoleFiller {
4- systemPrompt ( ) : string
5- userPrompt ( params : AutoCompleteContext ) : string
6- }
7-
8- // Source: continue/core/autocomplete/templating/AutocompleteTemplate.ts (holeFillerTemplate)
9- export class DefaultHoleFiller implements HoleFiller {
10- systemPrompt ( ) : string {
11- // From https://github.com/VictorTaelin/AI-scripts
12- return `You are a HOLE FILLER. You are provided with a file containing holes, formatted as '{{HOLE_NAME}}'.
13- Your TASK is to complete with a string to replace this hole with, inside a <COMPLETION/> XML tag, including context-aware indentation, if needed.
14- All completions MUST be truthful, accurate, well-written and correct.
15- ## EXAMPLE QUERY:
16-
17- <QUERY>
18- function sum_evens(lim) {
19- var sum = 0;
20- for (var i = 0; i < lim; ++i) {
21- {{FILL_HERE}}
22- }
23- return sum;
24- }
25- </QUERY>
26-
27- TASK: Fill the {{FILL_HERE}} hole.
28-
29- ## CORRECT COMPLETION
30-
31- <COMPLETION>if (i % 2 === 0) {
32- sum += i;
33- }</COMPLETION>
34-
35- ## EXAMPLE QUERY:
36-
37- <QUERY>
38- def sum_list(lst):
39- total = 0
40- for x in lst:
41- {{FILL_HERE}}
42- return total
43-
44- print sum_list([1, 2, 3])
45- </QUERY>
46-
47- ## CORRECT COMPLETION:
48-
49- <COMPLETION> total += x</COMPLETION>
50-
51- ## EXAMPLE QUERY:
52-
53- <QUERY>
54- // data Tree a = Node (Tree a) (Tree a) | Leaf a
55-
56- // sum :: Tree Int -> Int
57- // sum (Node lft rgt) = sum lft + sum rgt
58- // sum (Leaf val) = val
59-
60- // convert to TypeScript:
61- {{FILL_HERE}}
62- </QUERY>
63-
64- ## CORRECT COMPLETION:
65-
66- <COMPLETION>type Tree<T>
67- = {$:"Node", lft: Tree<T>, rgt: Tree<T>}
68- | {$:"Leaf", val: T};
69-
70- function sum(tree: Tree<number>): number {
71- switch (tree.$) {
72- case "Node":
73- return sum(tree.lft) + sum(tree.rgt);
74- case "Leaf":
75- return tree.val;
76- }
77- }</COMPLETION>
78-
79- ## EXAMPLE QUERY:
80-
81- The 5th {{FILL_HERE}} is Jupiter.
82-
83- ## CORRECT COMPLETION:
84-
85- <COMPLETION>planet from the Sun</COMPLETION>
86-
87- ## EXAMPLE QUERY:
88-
89- function hypothenuse(a, b) {
90- return Math.sqrt({{FILL_HERE}}b ** 2);
91- }
92-
93- ## CORRECT COMPLETION:
94-
95- <COMPLETION>a ** 2 + </COMPLETION>
96- ` ;
97- }
98-
99- userPrompt ( ctx : AutoCompleteContext ) : string {
100- let context = '' ;
101- if ( ctx . filename !== '' ) {
102- context += `// Filename: "${ ctx . filename } " \n` ;
103- }
104- if ( ctx . language !== '' ) {
105- context += `// Programming language: "${ ctx . language } " \n` ;
106- }
107- return `${ context } <QUERY>\n${ ctx . textBeforeCursor } {{FILL_HERE}}${ ctx . textAfterCursor } \n</QUERY>\nTASK: Fill the {{FILL_HERE}} hole. Answer only with the CORRECT completion, and NOTHING ELSE. Do it now.\n<COMPLETION>` ;
108- }
5+ prompt ( params : AutoCompleteContext ) : PromptArgs
1096}
1107
8+ export type PromptArgs = Prompt & {
9+ providerOptions ?: ProviderOptions ;
10+ } ;
11+
12+ export type AutoCompleteContext = {
13+ textBeforeCursor : string ,
14+ textAfterCursor : string ,
15+ currentLineText : string ,
16+ filename ?: string ,
17+ language ?: string ,
18+ }
0 commit comments