Configure model path for all libraries
This commit is contained in:
@@ -8,9 +8,9 @@ export type AiOptions = LLMOptions & {
|
|||||||
binary: string;
|
binary: string;
|
||||||
/** Model: `ggml-base.en.bin` */
|
/** Model: `ggml-base.en.bin` */
|
||||||
model: string;
|
model: string;
|
||||||
/** Path to models */
|
|
||||||
path: string;
|
|
||||||
}
|
}
|
||||||
|
/** Path to models */
|
||||||
|
path: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Ai {
|
export class Ai {
|
||||||
@@ -25,6 +25,7 @@ export class Ai {
|
|||||||
vision!: Vision;
|
vision!: Vision;
|
||||||
|
|
||||||
constructor(public readonly options: AiOptions) {
|
constructor(public readonly options: AiOptions) {
|
||||||
|
process.env.TRANSFORMERS_CACHE = options.path;
|
||||||
this.audio = new Audio(this);
|
this.audio = new Audio(this);
|
||||||
this.language = new LLM(this);
|
this.language = new LLM(this);
|
||||||
this.vision = new Vision(this);
|
this.vision = new Vision(this);
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export class Audio {
|
|||||||
async downloadAsrModel(model: string = this.whisperModel): Promise<string> {
|
async downloadAsrModel(model: string = this.whisperModel): Promise<string> {
|
||||||
if(!this.ai.options.whisper?.binary) throw new Error('Whisper not configured');
|
if(!this.ai.options.whisper?.binary) throw new Error('Whisper not configured');
|
||||||
if(!model.endsWith('.bin')) model += '.bin';
|
if(!model.endsWith('.bin')) model += '.bin';
|
||||||
const p = Path.join(this.ai.options.whisper.path, model);
|
const p = Path.join(this.ai.options.path, model);
|
||||||
if(await fs.stat(p).then(() => true).catch(() => false)) return p;
|
if(await fs.stat(p).then(() => true).catch(() => false)) return p;
|
||||||
if(!!this.downloads[model]) return this.downloads[model];
|
if(!!this.downloads[model]) return this.downloads[model];
|
||||||
this.downloads[model] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${model}`)
|
this.downloads[model] = fetch(`https://huggingface.co/ggerganov/whisper.cpp/resolve/main/${model}`)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export class Vision {
|
|||||||
return {
|
return {
|
||||||
abort: () => { worker?.terminate(); },
|
abort: () => { worker?.terminate(); },
|
||||||
response: new Promise(async res => {
|
response: new Promise(async res => {
|
||||||
worker = await createWorker('eng');
|
worker = await createWorker('eng', 1, {langPath: this.ai.options.path});
|
||||||
const {data} = await worker.recognize(path);
|
const {data} = await worker.recognize(path);
|
||||||
await worker.terminate();
|
await worker.terminate();
|
||||||
res(data.text.trim() || null);
|
res(data.text.trim() || null);
|
||||||
|
|||||||
Reference in New Issue
Block a user