1
1
#!/usr/bin/env node
2
-
3
- import * as GPT from './GPT.mjs' ;
4
- import * as Claude from './Claude.mjs' ;
2
+ import { asker , MODELS } from './Ask.mjs' ;
5
3
import process from "process" ;
6
4
import fs from 'fs/promises' ;
7
- import os from 'os' ;
8
5
import path from 'path' ;
9
6
10
7
const system = `
@@ -29,23 +26,33 @@ if (i % 2 === 0) {
29
26
sum += i;
30
27
}
31
28
32
- ## NOTICE THE INDENTATION:
29
+ ## NOTICE THE CONTEXT-AWARE INDENTATION:
33
30
34
31
1. The first line is NOT indented, because there are already spaces before {{LOOP}}.
35
32
36
33
2. The other lines ARE indented, to match the indentation of the context.
34
+
35
+ # NOTICE NO EXTRA EXPLANATORY WORDS:
36
+
37
+ 1. Do NOT add explanatory words like 'here is the code:' in the answer.
38
+
39
+ 2. Unless demanded by context, do NOT add backticks around the answer.
40
+
41
+ 3. Answer just with the correct substitution.
37
42
` ;
38
43
39
44
var file = process . argv [ 2 ] ;
40
45
var curr = process . argv [ 3 ] ;
41
- var model = process . argv [ 4 ] || "gpt-4-turbo-2024-04-09 " ;
46
+ var model = process . argv [ 4 ] || "C " ;
42
47
43
48
if ( ! file ) {
44
- console . log ( "Usage: holefill <file> [<shortened_file>] [<model_name>]" ) ;
45
- console . log ( "" ) ;
46
- console . log ( "This will replace all {{HOLES}} in <file>, using GPT-4 / Claude-3." ) ;
47
- console . log ( "A shortened file can be used to omit irrelevant parts." ) ;
48
- process . exit ( ) ;
49
+ console . log ( "Usage: holefill <file> [<shortened_file>] [<model>]" ) ;
50
+ console . log ( "Replaces {{HOLES}} in <file> using the specified model. Shortcuts:" ) ;
51
+ for ( var key in MODELS ) {
52
+ console . log ( "- " + key + " = " + MODELS [ key ] ) ;
53
+ }
54
+ console . log ( "A shortened file can be used to provide relevant context." ) ;
55
+ process . exit ( 1 ) ;
49
56
}
50
57
51
58
var file_code = await fs . readFile ( file , 'utf-8' ) ;
@@ -68,18 +75,19 @@ while ((match = regex.exec(curr_code)) !== null) {
68
75
69
76
await fs . writeFile ( curr , curr_code , 'utf-8' ) ;
70
77
71
- var tokens = GPT . token_count ( curr_code ) ;
78
+ var tokens = curr_code . length ; // Use the length of the code as a rough estimate of tokens
72
79
var holes = curr_code . match ( / { { \w + } } / g) || [ ] ;
73
- var ask = model . startsWith ( "claude" ) ? Claude . ask : GPT . ask ;
80
+
81
+ var ask = asker ( ) ;
74
82
75
83
console . log ( "holes_found:" , holes ) ;
76
84
console . log ( "token_count:" , tokens ) ;
77
- console . log ( "model_label:" , model ) ;
85
+ console . log ( "model_label:" , MODELS [ model ] || model ) ;
78
86
79
87
for ( let hole of holes ) {
80
88
console . log ( "next_filled: " + hole + "..." ) ;
81
- var prompt = curr_code + "\nTASK: Fill the {{" + hole + "}} hole. Answer only with the EXACT completion to replace {{" + hole + "}} with. INDENT IT BASED ON THE CONTEXT." ;
82
- var answer = await ask ( { system, prompt , model } ) ;
89
+ var prompt = curr_code + "\nTASK: Fill the {{" + hole + "}} hole. Answer only with the EXACT completion to replace {{" + hole + "}} with. INDENT IT BASED ON THE CONTEXT." ;
90
+ var answer = await ask ( prompt , { system, model , temperature : 0 , max_tokens : 256 } ) ;
83
91
file_code = file_code . replace ( hole , answer ) ;
84
92
}
85
93
0 commit comments