1
1
#!/usr/bin/env node
2
-
3
2
import * as GPT from './GPT.mjs' ;
3
+ import * as Claude from './Claude.mjs' ;
4
4
import process from "process" ;
5
5
import fs from 'fs/promises' ;
6
6
import os from 'os' ;
@@ -10,8 +10,6 @@ const system = `
10
10
You are a HOLE FILLER. You are provided with a file containing holes, formatted
11
11
as '{{HOLE}}'. Your TASK is to answer with a string to replace this hole with.
12
12
13
- #################
14
-
15
13
## EXAMPLE QUERY:
16
14
17
15
function sum_evens(lim) {
@@ -30,20 +28,21 @@ if (i % 2 === 0) {
30
28
sum += i;
31
29
}
32
30
33
- ## NOTICE THE INDENTATION.
34
- ## 1. The first line is NOT indented, because there are already spaces before {{LOOP}}.
35
- ## 2. The other lines ARE indented, to match the identation of the context.
36
- ## THIS IS VERY IMPORTANT.
31
+ ## NOTICE THE INDENTATION:
32
+
33
+ 1. The first line is NOT indented, because there are already spaces before {{LOOP}}.
34
+
35
+ 2. The other lines ARE indented, to match the identation of the context.
37
36
` ;
38
37
39
38
var file = process . argv [ 2 ] ;
40
39
var curr = process . argv [ 3 ] ;
41
- var fast = process . argv [ 4 ] === "--fast ";
40
+ var model = process . argv [ 4 ] || "gpt-4-0125-preview ";
42
41
43
42
if ( ! file ) {
44
- console . log ( "Usage: holefill <file> [<shortened_file>]" ) ;
43
+ console . log ( "Usage: holefill <file> [<shortened_file>] [<model_name>] " ) ;
45
44
console . log ( "" ) ;
46
- console . log ( "This will replace all {{HOLES}} in <file>, using GPT-4." ) ;
45
+ console . log ( "This will replace all {{HOLES}} in <file>, using GPT-4 / Claude-3 ." ) ;
47
46
console . log ( "A shortened file can be used to omit irrelevant parts." ) ;
48
47
process . exit ( ) ;
49
48
}
@@ -68,7 +67,7 @@ while ((match = regex.exec(curr_code)) !== null) {
68
67
69
68
var tokens = GPT . token_count ( curr_code ) ;
70
69
var holes = curr_code . match ( / { { \w + } } / g) || [ ] ;
71
- var model = fast ? "gpt-4-0125-preview" : "gpt-4-32k-0314" ;
70
+ var ask = model . startsWith ( "claude" ) ? Claude . ask : GPT . ask ;
72
71
73
72
console . log ( "holes_found:" , holes ) ;
74
73
console . log ( "token_count:" , tokens ) ;
@@ -77,7 +76,7 @@ console.log("model_label:", model);
77
76
for ( let hole of holes ) {
78
77
console . log ( "next_filled: " + hole + "..." ) ;
79
78
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. DO NOT USE BACKTICKS." ;
80
- var answer = await GPT . ask ( { system, prompt, model} ) ;
79
+ var answer = await ask ( { system, prompt, model} ) ;
81
80
file_code = file_code . replace ( hole , answer ) ;
82
81
}
83
82
0 commit comments