From fab8bc7f198a12dca6a73dcf1338196b6cddc9cf Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 3 May 2024 18:00:32 +0800 Subject: [PATCH] feat: support multiple variant load --- lib/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 49c9f54..cef6453 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -7,9 +7,10 @@ export interface LlamaModelOptionsExtended extends LlamaModelOptions { lib_variant?: string } -let module: Module | null = null +const mods: { [key: string]: Module } = {} export const loadModel = async (options: LlamaModelOptionsExtended): Promise => { - module ??= await loadModule(options.lib_variant) - return new module.LlamaContext(options) + const variant = options.lib_variant ?? 'default' + mods[variant] ??= await loadModule(options.lib_variant) + return new mods[variant].LlamaContext(options) }