Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 69b3297bb3 | |||
| 710c6ce52c | |||
| 4ac3036000 | |||
| 3121d542d4 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/ai-utils",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.6",
|
||||
"description": "AI Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -95,7 +95,7 @@ Rules:
|
||||
- ONLY extract decisions that were MADE during this conversation
|
||||
- DO NOT extract anything the AI said, its name, capabilities, or how it introduced itself
|
||||
- DO NOT extract greetings, pleasantries or generic exchanges
|
||||
- If nothing worth remembering was said, call NO tools
|
||||
- If nothing worth remembering was said, dont do anything, skip calling tools
|
||||
|
||||
For each fact decide whether it belongs in an existing document or needs a new one, then call the \`extract_facts\` tool.
|
||||
|
||||
|
||||
@@ -12,12 +12,31 @@ export class Vision {
|
||||
*/
|
||||
ocr(path: string): AbortablePromise<string | null> {
|
||||
let worker: any;
|
||||
const p = new Promise<string | null>(async res => {
|
||||
let reject: (err: any) => void;
|
||||
|
||||
const handler = (err: Error) => {
|
||||
if(err.stack?.includes('tesseract.js')) {
|
||||
process.off('uncaughtException', handler);
|
||||
reject?.(err);
|
||||
return;
|
||||
}
|
||||
throw err;
|
||||
};
|
||||
process.on('uncaughtException', handler);
|
||||
|
||||
const p = (async () => {
|
||||
worker = await createWorker(this.ai.options.ocr || 'eng', 2, {cachePath: this.ai.options.path});
|
||||
const {data} = await worker.recognize(path);
|
||||
await worker.terminate();
|
||||
res(data.text.trim() || null);
|
||||
}).finally(() => worker?.terminate());
|
||||
return await new Promise<string | null>((res, rej) => {
|
||||
reject = rej;
|
||||
worker.recognize(path)
|
||||
.then(({data}: any) => res(data.text.trim() || null))
|
||||
.catch(rej);
|
||||
});
|
||||
})().finally(() => {
|
||||
process.off('uncaughtException', handler);
|
||||
worker?.terminate();
|
||||
});
|
||||
|
||||
return Object.assign(p, {abort: () => worker?.terminate()});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user