wip
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
|||||||
prompt.md
|
prompt.md
|
||||||
todo
|
todo
|
||||||
.toak-ignore
|
.toak-ignore
|
||||||
|
/google_gemma-3-1b-it-Q6_K.llamafile
|
||||||
|
@@ -45,7 +45,9 @@
|
|||||||
"lint:fix": "eslint src/ --fix",
|
"lint:fix": "eslint src/ --fix",
|
||||||
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,yml,yaml}\"",
|
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,yml,yaml}\"",
|
||||||
"fix": "bun format && bun lint:fix",
|
"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": {
|
"dependencies": {
|
||||||
"glob": "^11.0.1",
|
"glob": "^11.0.1",
|
||||||
|
4
scripts/download_optimization_model.sh
Normal file
4
scripts/download_optimization_model.sh
Normal 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
30
scripts/optimize-ignore.ts
Executable 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();
|
||||||
|
}
|
25
src/cli.ts
25
src/cli.ts
@@ -3,10 +3,22 @@ import type { PresetPrompt } from './prompts';
|
|||||||
|
|
||||||
console.log('RUNNING TOKENIZER');
|
console.log('RUNNING TOKENIZER');
|
||||||
import { MarkdownGenerator, type MarkdownGeneratorOptions } from './MarkdownGenerator';
|
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 args = process.argv.slice(2);
|
||||||
const options: { prompt?: PresetPrompt; } & MarkdownGeneratorOptions = {
|
const options: { prompt?: PresetPrompt; } & MarkdownGeneratorOptions = {
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
type ValidArg = keyof MarkdownGeneratorOptions;
|
type ValidArg = keyof MarkdownGeneratorOptions;
|
||||||
|
|
||||||
@@ -18,6 +30,10 @@ for (let i = 0; i < args.length; i++) {
|
|||||||
options["todoPrompt"] = args[i + 1]
|
options["todoPrompt"] = args[i + 1]
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (args[i] === '--optimize-ignore') {
|
||||||
|
optimizeIgnore = true;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
const arg = args[i].replace(/^--/, '');
|
const arg = args[i].replace(/^--/, '');
|
||||||
if (arg as any satisfies ValidArg) {
|
if (arg as any satisfies ValidArg) {
|
||||||
// @ts-ignore - arg can't be used to index options
|
// @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);
|
const generator = new MarkdownGenerator(options);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
generator
|
generator
|
||||||
.createMarkdownDocument()
|
.createMarkdownDocument()
|
||||||
.then((result: { success: boolean }) => {
|
.then(async (result: { success: boolean }) => {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
if (optimizeIgnore) {
|
||||||
|
await optimizeToakIgnore(output);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error: any) => {
|
.catch((error: any) => {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
|
Reference in New Issue
Block a user