@web-llm-wrappers/react 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.mjs +22 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -71,14 +71,26 @@ function _objectSpread2(e) {
|
|
|
71
71
|
function getAvailableModels() {
|
|
72
72
|
return __mlc_ai_web_llm.prebuiltAppConfig.model_list;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
const singletons = { engine: new __mlc_ai_web_llm.MLCEngine({ initProgressCallback: (progressReport) => {
|
|
75
|
+
console.log("DEBUG: WebLLM React:", { progressReport });
|
|
76
|
+
} }) };
|
|
77
|
+
function useWebLLM({ modelId, engineConfig, chatOptions, debug = false, singleton = false }) {
|
|
75
78
|
const [engine, setEngine] = (0, react.useState)(null);
|
|
76
79
|
const [progressReport, setProgressReport] = (0, react.useState)();
|
|
80
|
+
const [modelsLoaded, setModelsLoaded] = (0, react.useState)({});
|
|
77
81
|
const loadModel = (0, react.useCallback)((modelId$1) => {
|
|
78
|
-
if (engine) return engine.reload(modelId$1, chatOptions)
|
|
82
|
+
if (engine) return engine.reload(modelId$1, chatOptions).then(() => {
|
|
83
|
+
setModelsLoaded((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { [modelId$1]: true }));
|
|
84
|
+
});
|
|
79
85
|
}, [engine, chatOptions]);
|
|
80
86
|
(0, react.useEffect)(() => {
|
|
81
|
-
if (
|
|
87
|
+
if (singleton) {
|
|
88
|
+
setEngine(singletons.engine);
|
|
89
|
+
singletons.engine.setInitProgressCallback((progressReport$1) => {
|
|
90
|
+
setProgressReport(progressReport$1);
|
|
91
|
+
if (debug) console.log("DEBUG: WebLLM React:", { progressReport: progressReport$1 });
|
|
92
|
+
});
|
|
93
|
+
} else if (modelId) (0, __mlc_ai_web_llm.CreateMLCEngine)(modelId, engineConfig, chatOptions).then((engine$1) => {
|
|
82
94
|
setEngine(engine$1);
|
|
83
95
|
});
|
|
84
96
|
else setEngine(new __mlc_ai_web_llm.MLCEngine(_objectSpread2(_objectSpread2({}, engineConfig), {}, { initProgressCallback: (progressReport$1) => {
|
|
@@ -91,12 +103,17 @@ function useWebLLM({ modelId, engineConfig, chatOptions, debug = false }) {
|
|
|
91
103
|
engine === null || engine === void 0 || engine.unload();
|
|
92
104
|
setEngine(null);
|
|
93
105
|
};
|
|
94
|
-
}, [
|
|
106
|
+
}, [
|
|
107
|
+
engineConfig,
|
|
108
|
+
debug,
|
|
109
|
+
singleton
|
|
110
|
+
]);
|
|
95
111
|
return {
|
|
96
112
|
engine,
|
|
97
113
|
progressReport,
|
|
98
114
|
getAvailableModels,
|
|
99
|
-
loadModel
|
|
115
|
+
loadModel,
|
|
116
|
+
modelsLoaded
|
|
100
117
|
};
|
|
101
118
|
}
|
|
102
119
|
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["prebuiltAppConfig","
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["prebuiltAppConfig","MLCEngine","modelId","progressReport","engine"],"sources":["../src/index.ts"],"sourcesContent":["import {\n MLCEngine,\n ChatOptions,\n MLCEngineConfig,\n InitProgressReport,\n prebuiltAppConfig,\n CreateMLCEngine,\n} from \"@mlc-ai/web-llm\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nfunction getAvailableModels() {\n return prebuiltAppConfig.model_list;\n}\n\nconst singletons = {\n engine: new MLCEngine({\n initProgressCallback: (progressReport) => {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n },\n }),\n};\n\nexport function useWebLLM({\n modelId,\n engineConfig,\n chatOptions,\n debug = false,\n singleton = false,\n}: {\n modelId?: string | string[];\n engineConfig?: MLCEngineConfig;\n chatOptions?: ChatOptions;\n debug?: boolean;\n singleton?: boolean;\n}) {\n const [engine, setEngine] = useState<MLCEngine | null>(null);\n // TODO: add support for a singleton version of these\n const [progressReport, setProgressReport] = useState<InitProgressReport>();\n const [modelsLoaded, setModelsLoaded] = useState<Record<string, boolean>>({});\n\n const loadModel = useCallback(\n (modelId: string) => {\n if (engine) {\n return engine.reload(modelId, chatOptions).then(() => {\n setModelsLoaded((prev) => ({ ...prev, [modelId]: true }));\n });\n }\n },\n [engine, chatOptions]\n );\n\n useEffect(() => {\n if (singleton) {\n setEngine(singletons.engine);\n singletons.engine.setInitProgressCallback((progressReport) => {\n setProgressReport(progressReport);\n if (debug) {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n }\n });\n } else if (modelId) {\n CreateMLCEngine(modelId, engineConfig, chatOptions).then((engine) => {\n setEngine(engine);\n });\n } else {\n setEngine(\n new MLCEngine({\n ...engineConfig,\n initProgressCallback: (progressReport) => {\n setProgressReport(progressReport);\n engineConfig?.initProgressCallback?.(progressReport);\n\n if (debug) {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n }\n },\n })\n );\n }\n\n return () => {\n engine?.unload();\n setEngine(null);\n };\n }, [engineConfig, debug, singleton]);\n\n return {\n engine,\n progressReport,\n getAvailableModels,\n loadModel,\n modelsLoaded,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,qBAAqB;AAC5B,QAAOA,mCAAkB;;AAG3B,MAAM,aAAa,EACjB,QAAQ,IAAIC,2BAAU,EACpB,uBAAuB,mBAAmB;AACxC,SAAQ,IAAI,wBAAwB,EAAE,gBAAgB,CAAC;GAE1D,CAAC,EACH;AAED,SAAgB,UAAU,EACxB,SACA,cACA,aACA,QAAQ,OACR,YAAY,SAOX;CACD,MAAM,CAAC,QAAQ,iCAAwC,KAAK;CAE5D,MAAM,CAAC,gBAAgB,0CAAmD;CAC1E,MAAM,CAAC,cAAc,uCAAqD,EAAE,CAAC;CAE7E,MAAM,oCACH,cAAoB;AACnB,MAAI,OACF,QAAO,OAAO,OAAOC,WAAS,YAAY,CAAC,WAAW;AACpD,oBAAiB,2CAAe,cAAOA,YAAU,QAAQ;IACzD;IAGN,CAAC,QAAQ,YAAY,CACtB;AAED,4BAAgB;AACd,MAAI,WAAW;AACb,aAAU,WAAW,OAAO;AAC5B,cAAW,OAAO,yBAAyB,qBAAmB;AAC5D,sBAAkBC,iBAAe;AACjC,QAAI,MACF,SAAQ,IAAI,wBAAwB,EAAE,kCAAgB,CAAC;KAEzD;aACO,QACT,uCAAgB,SAAS,cAAc,YAAY,CAAC,MAAM,aAAW;AACnE,aAAUC,SAAO;IACjB;MAEF,WACE,IAAIH,6DACC,qBACH,uBAAuB,qBAAmB;;AACxC,qBAAkBE,iBAAe;AACjC,6FAAc,+GAAuBA,iBAAe;AAEpD,OAAI,MACF,SAAQ,IAAI,wBAAwB,EAAE,kCAAgB,CAAC;OAG3D,CACH;AAGH,eAAa;AACX,kDAAQ,QAAQ;AAChB,aAAU,KAAK;;IAEhB;EAAC;EAAc;EAAO;EAAU,CAAC;AAEpC,QAAO;EACL;EACA;EACA;EACA;EACA;EACD"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1887,17 +1887,20 @@ declare function useWebLLM({
|
|
|
1887
1887
|
modelId,
|
|
1888
1888
|
engineConfig,
|
|
1889
1889
|
chatOptions,
|
|
1890
|
-
debug
|
|
1890
|
+
debug,
|
|
1891
|
+
singleton
|
|
1891
1892
|
}: {
|
|
1892
1893
|
modelId?: string | string[];
|
|
1893
1894
|
engineConfig?: MLCEngineConfig;
|
|
1894
1895
|
chatOptions?: ChatOptions;
|
|
1895
1896
|
debug?: boolean;
|
|
1897
|
+
singleton?: boolean;
|
|
1896
1898
|
}): {
|
|
1897
1899
|
engine: MLCEngine;
|
|
1898
1900
|
progressReport: InitProgressReport;
|
|
1899
1901
|
getAvailableModels: typeof getAvailableModels;
|
|
1900
1902
|
loadModel: (modelId: string) => Promise<void>;
|
|
1903
|
+
modelsLoaded: Record<string, boolean>;
|
|
1901
1904
|
};
|
|
1902
1905
|
//#endregion
|
|
1903
1906
|
export { useWebLLM };
|
package/dist/index.d.mts
CHANGED
|
@@ -1887,17 +1887,20 @@ declare function useWebLLM({
|
|
|
1887
1887
|
modelId,
|
|
1888
1888
|
engineConfig,
|
|
1889
1889
|
chatOptions,
|
|
1890
|
-
debug
|
|
1890
|
+
debug,
|
|
1891
|
+
singleton
|
|
1891
1892
|
}: {
|
|
1892
1893
|
modelId?: string | string[];
|
|
1893
1894
|
engineConfig?: MLCEngineConfig;
|
|
1894
1895
|
chatOptions?: ChatOptions;
|
|
1895
1896
|
debug?: boolean;
|
|
1897
|
+
singleton?: boolean;
|
|
1896
1898
|
}): {
|
|
1897
1899
|
engine: MLCEngine;
|
|
1898
1900
|
progressReport: InitProgressReport;
|
|
1899
1901
|
getAvailableModels: typeof getAvailableModels;
|
|
1900
1902
|
loadModel: (modelId: string) => Promise<void>;
|
|
1903
|
+
modelsLoaded: Record<string, boolean>;
|
|
1901
1904
|
};
|
|
1902
1905
|
//#endregion
|
|
1903
1906
|
export { useWebLLM };
|
package/dist/index.mjs
CHANGED
|
@@ -71,14 +71,26 @@ function _objectSpread2(e) {
|
|
|
71
71
|
function getAvailableModels() {
|
|
72
72
|
return prebuiltAppConfig.model_list;
|
|
73
73
|
}
|
|
74
|
-
|
|
74
|
+
const singletons = { engine: new MLCEngine({ initProgressCallback: (progressReport) => {
|
|
75
|
+
console.log("DEBUG: WebLLM React:", { progressReport });
|
|
76
|
+
} }) };
|
|
77
|
+
function useWebLLM({ modelId, engineConfig, chatOptions, debug = false, singleton = false }) {
|
|
75
78
|
const [engine, setEngine] = useState(null);
|
|
76
79
|
const [progressReport, setProgressReport] = useState();
|
|
80
|
+
const [modelsLoaded, setModelsLoaded] = useState({});
|
|
77
81
|
const loadModel = useCallback((modelId$1) => {
|
|
78
|
-
if (engine) return engine.reload(modelId$1, chatOptions)
|
|
82
|
+
if (engine) return engine.reload(modelId$1, chatOptions).then(() => {
|
|
83
|
+
setModelsLoaded((prev) => _objectSpread2(_objectSpread2({}, prev), {}, { [modelId$1]: true }));
|
|
84
|
+
});
|
|
79
85
|
}, [engine, chatOptions]);
|
|
80
86
|
useEffect(() => {
|
|
81
|
-
if (
|
|
87
|
+
if (singleton) {
|
|
88
|
+
setEngine(singletons.engine);
|
|
89
|
+
singletons.engine.setInitProgressCallback((progressReport$1) => {
|
|
90
|
+
setProgressReport(progressReport$1);
|
|
91
|
+
if (debug) console.log("DEBUG: WebLLM React:", { progressReport: progressReport$1 });
|
|
92
|
+
});
|
|
93
|
+
} else if (modelId) CreateMLCEngine(modelId, engineConfig, chatOptions).then((engine$1) => {
|
|
82
94
|
setEngine(engine$1);
|
|
83
95
|
});
|
|
84
96
|
else setEngine(new MLCEngine(_objectSpread2(_objectSpread2({}, engineConfig), {}, { initProgressCallback: (progressReport$1) => {
|
|
@@ -91,12 +103,17 @@ function useWebLLM({ modelId, engineConfig, chatOptions, debug = false }) {
|
|
|
91
103
|
engine === null || engine === void 0 || engine.unload();
|
|
92
104
|
setEngine(null);
|
|
93
105
|
};
|
|
94
|
-
}, [
|
|
106
|
+
}, [
|
|
107
|
+
engineConfig,
|
|
108
|
+
debug,
|
|
109
|
+
singleton
|
|
110
|
+
]);
|
|
95
111
|
return {
|
|
96
112
|
engine,
|
|
97
113
|
progressReport,
|
|
98
114
|
getAvailableModels,
|
|
99
|
-
loadModel
|
|
115
|
+
loadModel,
|
|
116
|
+
modelsLoaded
|
|
100
117
|
};
|
|
101
118
|
}
|
|
102
119
|
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["modelId","
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["modelId","progressReport","engine"],"sources":["../src/index.ts"],"sourcesContent":["import {\n MLCEngine,\n ChatOptions,\n MLCEngineConfig,\n InitProgressReport,\n prebuiltAppConfig,\n CreateMLCEngine,\n} from \"@mlc-ai/web-llm\";\nimport { useCallback, useEffect, useState } from \"react\";\n\nfunction getAvailableModels() {\n return prebuiltAppConfig.model_list;\n}\n\nconst singletons = {\n engine: new MLCEngine({\n initProgressCallback: (progressReport) => {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n },\n }),\n};\n\nexport function useWebLLM({\n modelId,\n engineConfig,\n chatOptions,\n debug = false,\n singleton = false,\n}: {\n modelId?: string | string[];\n engineConfig?: MLCEngineConfig;\n chatOptions?: ChatOptions;\n debug?: boolean;\n singleton?: boolean;\n}) {\n const [engine, setEngine] = useState<MLCEngine | null>(null);\n // TODO: add support for a singleton version of these\n const [progressReport, setProgressReport] = useState<InitProgressReport>();\n const [modelsLoaded, setModelsLoaded] = useState<Record<string, boolean>>({});\n\n const loadModel = useCallback(\n (modelId: string) => {\n if (engine) {\n return engine.reload(modelId, chatOptions).then(() => {\n setModelsLoaded((prev) => ({ ...prev, [modelId]: true }));\n });\n }\n },\n [engine, chatOptions]\n );\n\n useEffect(() => {\n if (singleton) {\n setEngine(singletons.engine);\n singletons.engine.setInitProgressCallback((progressReport) => {\n setProgressReport(progressReport);\n if (debug) {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n }\n });\n } else if (modelId) {\n CreateMLCEngine(modelId, engineConfig, chatOptions).then((engine) => {\n setEngine(engine);\n });\n } else {\n setEngine(\n new MLCEngine({\n ...engineConfig,\n initProgressCallback: (progressReport) => {\n setProgressReport(progressReport);\n engineConfig?.initProgressCallback?.(progressReport);\n\n if (debug) {\n console.log(\"DEBUG: WebLLM React:\", { progressReport });\n }\n },\n })\n );\n }\n\n return () => {\n engine?.unload();\n setEngine(null);\n };\n }, [engineConfig, debug, singleton]);\n\n return {\n engine,\n progressReport,\n getAvailableModels,\n loadModel,\n modelsLoaded,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"author": "",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"peerDependencies": {
|
|
28
|
+
"react": ">= 18.0",
|
|
28
29
|
"@mlc-ai/web-llm": "^0.2.79"
|
|
29
30
|
},
|
|
30
|
-
"dependencies": {
|
|
31
|
-
"react": "^19.2.0"
|
|
32
|
-
},
|
|
31
|
+
"dependencies": {},
|
|
33
32
|
"devDependencies": {
|
|
33
|
+
"react": "^19.2.0",
|
|
34
34
|
"@types/react": "^19.2.5",
|
|
35
35
|
"tsdown": "^0.16.6",
|
|
36
36
|
"typescript": "^5.9.3"
|