@@ -29,71 +29,21 @@ export async function autocomplete(args: {
29
29
// Receiving tokens
30
30
let res = '' ;
31
31
let totalLines = 1 ;
32
- let blockStack : ( '[' | '(' | '{' ) [ ] = [ ] ;
33
- outer: for await ( let tokens of ollamaTokenGenerator ( args . endpoint + '/api/generate' , data , args . bearerToken ) ) {
32
+ for await ( let tokens of ollamaTokenGenerator ( args . endpoint + '/api/generate' , data , args . bearerToken ) ) {
34
33
if ( args . canceled && args . canceled ( ) ) {
35
34
break ;
36
35
}
37
36
38
- // Block stack
39
- for ( let c of tokens . response ) {
40
-
41
- // Open block
42
- if ( c === '[' ) {
43
- blockStack . push ( '[' ) ;
44
- } else if ( c === '(' ) {
45
- blockStack . push ( '(' ) ;
46
- }
47
- if ( c === '{' ) {
48
- blockStack . push ( '{' ) ;
49
- }
50
-
51
- // Close block
52
- if ( c === ']' ) {
53
- if ( blockStack . length > 0 && blockStack [ blockStack . length - 1 ] === '[' ) {
54
- blockStack . pop ( ) ;
55
- } else {
56
- info ( 'Block stack error, breaking.' ) ;
57
- break outer;
58
- }
59
- }
60
- if ( c === ')' ) {
61
- if ( blockStack . length > 0 && blockStack [ blockStack . length - 1 ] === '(' ) {
62
- blockStack . pop ( ) ;
63
- } else {
64
- info ( 'Block stack error, breaking.' ) ;
65
- break outer;
66
- }
67
- }
68
- if ( c === '}' ) {
69
- if ( blockStack . length > 0 && blockStack [ blockStack . length - 1 ] === '{' ) {
70
- blockStack . pop ( ) ;
71
- } else {
72
- info ( 'Block stack error, breaking.' ) ;
73
- break outer;
74
- }
75
- }
76
-
77
- // Append charater
78
- res += c ;
79
- }
37
+ res = res + tokens . response ;
80
38
81
39
// Update total lines
82
40
totalLines += countSymbol ( tokens . response , '\n' ) ;
83
41
// Break if too many lines and on top level
84
- if ( totalLines > args . maxLines && blockStack . length === 0 ) {
42
+ if ( totalLines > args . maxLines ) {
85
43
info ( 'Too many lines, breaking.' ) ;
86
44
break ;
87
45
}
88
46
}
89
47
90
- // Remove <EOT>
91
- if ( res . endsWith ( '<EOT>' ) ) {
92
- res = res . slice ( 0 , res . length - 5 ) ;
93
- }
94
-
95
- // Trim ends of all lines since sometimes the AI completion will add extra spaces
96
- res = res . split ( '\n' ) . map ( ( v ) => v . trimEnd ( ) ) . join ( '\n' ) ;
97
-
98
48
return res ;
99
49
}
0 commit comments