Re-organized functions and added semantic embeddings
All checks were successful
Publish Library / Build NPM Project (push) Successful in 46s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2025-12-19 11:16:05 -05:00
parent c896b585d0
commit 435c6127b1
9 changed files with 987 additions and 123 deletions

25
src/vision.ts Normal file
View File

@@ -0,0 +1,25 @@
import {createWorker} from 'tesseract.js';
import {Ai} from './ai.ts';
export class Vision {
constructor(private ai: Ai) { }
/**
* Convert image to text using Optical Character Recognition
* @param {string} path Path to image
* @returns {{abort: Function, response: Promise<string | null>}} Abort function & Promise of extracted text
*/
ocr(path: string): {abort: () => void, response: Promise<string | null>} {
let worker: any;
return {
abort: () => { worker?.terminate(); },
response: new Promise(async res => {
worker = await createWorker('eng');
const {data} = await worker.recognize(path);
await worker.terminate();
res(data.text.trim() || null);
})
}
}
}