This commit is contained in:
geoffsee
2025-06-13 14:03:53 -04:00
parent 39ca507911
commit ee137774d3
6 changed files with 62 additions and 2 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@
prompt.md
todo
.toak-ignore
/google_gemma-3-1b-it-Q6_K.llamafile

BIN
bun.lockb

Binary file not shown.

View File

@@ -45,7 +45,9 @@
"lint:fix": "eslint src/ --fix",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,yml,yaml}\"",
"fix": "bun format && bun lint:fix",
"release": "bunx release-it"
"release": "bunx release-it",
"run:inference": "./google_gemma-3-1b-it-Q6_K.llamafile --server --nobrowser",
"download:inference": "./download_optimization_model.sh"
},
"dependencies": {
"glob": "^11.0.1",

View File

@@ -0,0 +1,4 @@
MODEL_URL=https://huggingface.co/Mozilla/gemma-3-1b-it-llamafile/resolve/main/google_gemma-3-1b-it-Q6_K.llamafile?download=true
wget "${MODEL_URL}"

30
scripts/optimize-ignore.ts Executable file
View File

@@ -0,0 +1,30 @@
export async function optimizeToakIgnore(content: string) {
const inferenceProcess = Bun.spawn(['bun', 'run:inference']);
await new Promise(resolve => setTimeout(resolve, 5000));
const prompt = `You are a helpful assistant.
## Context
~~~
${content}
~~~
Respond with a list of files that should be added to the .toak-ignore file to reduce noise in the context. No extra text or explanations.`;
async function run() {
try {
const response = await fetch('http://127.0.0.1:8080/completion', {
method: 'POST',
body: JSON.stringify({
prompt,
n_predict: 512,
}),
});
const data = await response.json();
console.log(data.content);
} catch (error) {
console.error('Error:', error);
}
}
await run();
inferenceProcess.kill();
}

View File

@@ -3,10 +3,22 @@ import type { PresetPrompt } from './prompts';
console.log('RUNNING TOKENIZER');
import { MarkdownGenerator, type MarkdownGeneratorOptions } from './MarkdownGenerator';
import { optimizeToakIgnore } from '../scripts/optimize-ignore.ts';
let output = '';
process.stdout.write = (write => {
return (str: string | Uint8Array, ...args: any) => {
output += str.toString();
return write.apply(process.stdout, [str, ...args]);
};
})(process.stdout.write);
let optimizeIgnore = false;
const args = process.argv.slice(2);
const options: { prompt?: PresetPrompt; } & MarkdownGeneratorOptions = {
};
type ValidArg = keyof MarkdownGeneratorOptions;
@@ -18,6 +30,10 @@ for (let i = 0; i < args.length; i++) {
options["todoPrompt"] = args[i + 1]
i++;
}
if (args[i] === '--optimize-ignore') {
optimizeIgnore = true;
i++;
}
const arg = args[i].replace(/^--/, '');
if (arg as any satisfies ValidArg) {
// @ts-ignore - arg can't be used to index options
@@ -30,12 +46,19 @@ for (let i = 0; i < args.length; i++) {
}
const generator = new MarkdownGenerator(options);
generator
.createMarkdownDocument()
.then((result: { success: boolean }) => {
.then(async (result: { success: boolean }) => {
if (!result.success) {
process.exit(1);
}
if (optimizeIgnore) {
await optimizeToakIgnore(output);
}
})
.catch((error: any) => {
console.error('Error:', error);