Skip to content

Commit ef07a65

Browse files
committed
updates
1 parent 19cfc27 commit ef07a65

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

chatsh.mjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import readline from 'readline';
44
import { exec } from 'child_process';
55
import { promisify } from 'util';
6-
import { makeStatefulAsker, MODELS } from './Ask.mjs';
6+
import { asker, MODELS } from './Ask.mjs';
77

88
const execAsync = promisify(exec);
99

1010
// Default model if not specified
11-
const DEFAULT_MODEL = "cf";
11+
const DEFAULT_MODEL = "g";
1212
// Get model from environment variable or use default
1313
const MODEL = process.argv[2] || DEFAULT_MODEL;
1414

@@ -22,13 +22,16 @@ When the user asks you to perform a task:
2222
- Do NOT include any explanatory text along with the code.
2323
2424
If the user asks an open question that is not demanding a task:
25-
- Treat it as a chat, and ask as an assistant instead.
26-
- As an assistant, you're helpful, friendly, intelligent and truthful.
25+
- Treat it as a chat, and answer as you would normally.
26+
- Always answer the user's questions friendly, intelligently and truthfully.
2727
2828
Guidelines:
2929
- When asked to write/modify a file, provide a shell command to do it instead of just showing the file contents.
3030
- When asked to query an API, write a shell command to make the request.
3131
- Always assume common commands/tools are available. Don't write install commands.
32+
33+
User shell:
34+
${await get_shell()}
3235
`;
3336

3437
// Create readline interface for user input/output
@@ -39,7 +42,7 @@ const rl = readline.createInterface({
3942
});
4043

4144
// Create a stateful asker
42-
const ask = makeStatefulAsker();
45+
const ask = asker();
4346

4447
// Utility function to prompt the user for input
4548
async function prompt(query) {
@@ -92,4 +95,10 @@ function extractCode(text) {
9295
return match ? match[1].trim() : null;
9396
}
9497

98+
99+
async function get_shell() {
100+
const shellInfo = (await execAsync('uname -a && $SHELL --version')).stdout.trim();
101+
return shellInfo;
102+
}
103+
95104
main();

holefill.mjs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/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';
53
import process from "process";
64
import fs from 'fs/promises';
7-
import os from 'os';
85
import path from 'path';
96

107
const system = `
@@ -29,23 +26,33 @@ if (i % 2 === 0) {
2926
sum += i;
3027
}
3128
32-
## NOTICE THE INDENTATION:
29+
## NOTICE THE CONTEXT-AWARE INDENTATION:
3330
3431
1. The first line is NOT indented, because there are already spaces before {{LOOP}}.
3532
3633
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.
3742
`;
3843

3944
var file = process.argv[2];
4045
var curr = process.argv[3];
41-
var model = process.argv[4] || "gpt-4-turbo-2024-04-09";
46+
var model = process.argv[4] || "C";
4247

4348
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);
4956
}
5057

5158
var file_code = await fs.readFile(file, 'utf-8');
@@ -68,18 +75,19 @@ while ((match = regex.exec(curr_code)) !== null) {
6875

6976
await fs.writeFile(curr, curr_code, 'utf-8');
7077

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
7279
var holes = curr_code.match(/{{\w+}}/g) || [];
73-
var ask = model.startsWith("claude") ? Claude.ask : GPT.ask;
80+
81+
var ask = asker();
7482

7583
console.log("holes_found:", holes);
7684
console.log("token_count:", tokens);
77-
console.log("model_label:", model);
85+
console.log("model_label:", MODELS[model] || model);
7886

7987
for (let hole of holes) {
8088
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 });
8391
file_code = file_code.replace(hole, answer);
8492
}
8593

0 commit comments

Comments
 (0)