@web-llm-wrappers/react 0.0.1
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/LICENSE +7 -0
- package/dist/index.cjs +105 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1904 -0
- package/dist/index.d.mts +1904 -0
- package/dist/index.mjs +105 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2025 Chris Griffing
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
let __mlc_ai_web_llm = require("@mlc-ai/web-llm");
|
|
2
|
+
let react = require("react");
|
|
3
|
+
|
|
4
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/typeof.js
|
|
5
|
+
function _typeof(o) {
|
|
6
|
+
"@babel/helpers - typeof";
|
|
7
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
8
|
+
return typeof o$1;
|
|
9
|
+
} : function(o$1) {
|
|
10
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
11
|
+
}, _typeof(o);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPrimitive.js
|
|
16
|
+
function toPrimitive(t, r) {
|
|
17
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
18
|
+
var e = t[Symbol.toPrimitive];
|
|
19
|
+
if (void 0 !== e) {
|
|
20
|
+
var i = e.call(t, r || "default");
|
|
21
|
+
if ("object" != _typeof(i)) return i;
|
|
22
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
23
|
+
}
|
|
24
|
+
return ("string" === r ? String : Number)(t);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/toPropertyKey.js
|
|
29
|
+
function toPropertyKey(t) {
|
|
30
|
+
var i = toPrimitive(t, "string");
|
|
31
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/defineProperty.js
|
|
36
|
+
function _defineProperty(e, r, t) {
|
|
37
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
38
|
+
value: t,
|
|
39
|
+
enumerable: !0,
|
|
40
|
+
configurable: !0,
|
|
41
|
+
writable: !0
|
|
42
|
+
}) : e[r] = t, e;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region \0@oxc-project+runtime@0.98.0/helpers/objectSpread2.js
|
|
47
|
+
function ownKeys(e, r) {
|
|
48
|
+
var t = Object.keys(e);
|
|
49
|
+
if (Object.getOwnPropertySymbols) {
|
|
50
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
51
|
+
r && (o = o.filter(function(r$1) {
|
|
52
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
53
|
+
})), t.push.apply(t, o);
|
|
54
|
+
}
|
|
55
|
+
return t;
|
|
56
|
+
}
|
|
57
|
+
function _objectSpread2(e) {
|
|
58
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
59
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
60
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
61
|
+
_defineProperty(e, r$1, t[r$1]);
|
|
62
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
63
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return e;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/index.ts
|
|
71
|
+
function getAvailableModels() {
|
|
72
|
+
return __mlc_ai_web_llm.prebuiltAppConfig.model_list;
|
|
73
|
+
}
|
|
74
|
+
function useWebLLM({ modelId, engineConfig, chatOptions, debug = false }) {
|
|
75
|
+
const [engine, setEngine] = (0, react.useState)(null);
|
|
76
|
+
const [progressReport, setProgressReport] = (0, react.useState)();
|
|
77
|
+
const loadModel = (0, react.useCallback)((modelId$1) => {
|
|
78
|
+
if (engine) return engine.reload(modelId$1, chatOptions);
|
|
79
|
+
}, [engine, chatOptions]);
|
|
80
|
+
(0, react.useEffect)(() => {
|
|
81
|
+
if (modelId) (0, __mlc_ai_web_llm.CreateMLCEngine)(modelId, engineConfig, chatOptions).then((engine$1) => {
|
|
82
|
+
setEngine(engine$1);
|
|
83
|
+
});
|
|
84
|
+
else setEngine(new __mlc_ai_web_llm.MLCEngine(_objectSpread2(_objectSpread2({}, engineConfig), {}, { initProgressCallback: (progressReport$1) => {
|
|
85
|
+
var _engineConfig$initPro;
|
|
86
|
+
setProgressReport(progressReport$1);
|
|
87
|
+
engineConfig === null || engineConfig === void 0 || (_engineConfig$initPro = engineConfig.initProgressCallback) === null || _engineConfig$initPro === void 0 || _engineConfig$initPro.call(engineConfig, progressReport$1);
|
|
88
|
+
if (debug) console.log("DEBUG: WebLLM React:", { progressReport: progressReport$1 });
|
|
89
|
+
} })));
|
|
90
|
+
return () => {
|
|
91
|
+
engine === null || engine === void 0 || engine.unload();
|
|
92
|
+
setEngine(null);
|
|
93
|
+
};
|
|
94
|
+
}, [engineConfig, debug]);
|
|
95
|
+
return {
|
|
96
|
+
engine,
|
|
97
|
+
progressReport,
|
|
98
|
+
getAvailableModels,
|
|
99
|
+
loadModel
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.useWebLLM = useWebLLM;
|
|
105
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["prebuiltAppConfig","modelId","engine","MLCEngine","progressReport"],"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\nexport function useWebLLM({\n modelId,\n engineConfig,\n chatOptions,\n debug = false,\n}: {\n modelId?: string | string[];\n engineConfig?: MLCEngineConfig;\n chatOptions?: ChatOptions;\n debug?: boolean;\n}) {\n const [engine, setEngine] = useState<MLCEngine | null>(null);\n const [progressReport, setProgressReport] = useState<InitProgressReport>();\n\n const loadModel = useCallback(\n (modelId: string) => {\n if (engine) {\n return engine.reload(modelId, chatOptions);\n }\n },\n [engine, chatOptions]\n );\n\n useEffect(() => {\n 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]);\n\n return { engine, progressReport, getAvailableModels, loadModel };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,SAAS,qBAAqB;AAC5B,QAAOA,mCAAkB;;AAG3B,SAAgB,UAAU,EACxB,SACA,cACA,aACA,QAAQ,SAMP;CACD,MAAM,CAAC,QAAQ,iCAAwC,KAAK;CAC5D,MAAM,CAAC,gBAAgB,0CAAmD;CAE1E,MAAM,oCACH,cAAoB;AACnB,MAAI,OACF,QAAO,OAAO,OAAOC,WAAS,YAAY;IAG9C,CAAC,QAAQ,YAAY,CACtB;AAED,4BAAgB;AACd,MAAI,QACF,uCAAgB,SAAS,cAAc,YAAY,CAAC,MAAM,aAAW;AACnE,aAAUC,SAAO;IACjB;MAEF,WACE,IAAIC,6DACC,qBACH,uBAAuB,qBAAmB;;AACxC,qBAAkBC,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,CAAC,cAAc,MAAM,CAAC;AAEzB,QAAO;EAAE;EAAQ;EAAgB;EAAoB;EAAW"}
|