@blank-utils/llm 0.4.23 → 0.5.0
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.
|
@@ -34,15 +34,8 @@ function checkWasm() {
|
|
|
34
34
|
async function detectCapabilities() {
|
|
35
35
|
const webgpu = await checkWebGPU();
|
|
36
36
|
const wasm = checkWasm();
|
|
37
|
-
let recommendedBackend = "
|
|
38
|
-
let recommendedDevice = "
|
|
39
|
-
if (webgpu) {
|
|
40
|
-
recommendedBackend = "webllm";
|
|
41
|
-
recommendedDevice = "webgpu";
|
|
42
|
-
} else if (wasm) {
|
|
43
|
-
recommendedBackend = "transformers";
|
|
44
|
-
recommendedDevice = "wasm";
|
|
45
|
-
}
|
|
37
|
+
let recommendedBackend = "webllm";
|
|
38
|
+
let recommendedDevice = "webgpu";
|
|
46
39
|
return {
|
|
47
40
|
webgpu,
|
|
48
41
|
wasm,
|
|
@@ -101,21 +94,6 @@ var WEBLLM_MODELS = {
|
|
|
101
94
|
"hermes-3-llama-3.2-3b": "Hermes-3-Llama-3.2-3B-q4f16_1-MLC",
|
|
102
95
|
"hermes-3-llama-3.1-8b": "Hermes-3-Llama-3.1-8B-q4f16_1-MLC"
|
|
103
96
|
};
|
|
104
|
-
var DEFAULT_TRANSFORMERS_MODEL = "onnx-community/Qwen2.5-0.5B-Instruct";
|
|
105
|
-
var TRANSFORMERS_MODELS = {
|
|
106
|
-
// === Qwen 2.5 Models (Alibaba) - Excellent quality ===
|
|
107
|
-
"qwen-2.5-0.5b": "onnx-community/Qwen2.5-0.5B-Instruct",
|
|
108
|
-
"qwen-2.5-1.5b": "onnx-community/Qwen2.5-1.5B-Instruct",
|
|
109
|
-
"qwen-2.5-coder-0.5b": "onnx-community/Qwen2.5-Coder-0.5B-Instruct",
|
|
110
|
-
"qwen-2.5-coder-1.5b": "onnx-community/Qwen2.5-Coder-1.5B-Instruct",
|
|
111
|
-
// === Vision Models ===
|
|
112
|
-
"phi-3.5-vision": "onnx-community/Phi-3.5-vision-instruct",
|
|
113
|
-
// === SmolLM2 Models (HuggingFace) - Ultra lightweight ===
|
|
114
|
-
"smollm2-135m": "HuggingFaceTB/SmolLM2-135M-Instruct",
|
|
115
|
-
"smollm2-1.7b": "HuggingFaceTB/SmolLM2-1.7B-Instruct",
|
|
116
|
-
// === Phi Models (Microsoft) ===
|
|
117
|
-
"phi-3-mini": "Xenova/Phi-3-mini-4k-instruct"
|
|
118
|
-
};
|
|
119
97
|
|
|
120
98
|
// src/backends/webllm.ts
|
|
121
99
|
function resolveModelId(model) {
|
|
@@ -206,119 +184,6 @@ function createWebLLMProvider() {
|
|
|
206
184
|
return new WebLLMProvider();
|
|
207
185
|
}
|
|
208
186
|
|
|
209
|
-
// src/backends/transformers.ts
|
|
210
|
-
import "@huggingface/transformers";
|
|
211
|
-
function isVisionModel(modelId) {
|
|
212
|
-
const lower = modelId.toLowerCase();
|
|
213
|
-
return lower.includes("vl") || lower.includes("vision") || lower.includes("moondream");
|
|
214
|
-
}
|
|
215
|
-
function mapQuantization(quantization) {
|
|
216
|
-
const map = {
|
|
217
|
-
q4: "q4",
|
|
218
|
-
q8: "q8",
|
|
219
|
-
fp16: "fp16",
|
|
220
|
-
fp32: "fp32"
|
|
221
|
-
};
|
|
222
|
-
return map[quantization] ?? "q4";
|
|
223
|
-
}
|
|
224
|
-
var TransformersProvider = class {
|
|
225
|
-
backend = "transformers";
|
|
226
|
-
pipeline = null;
|
|
227
|
-
currentModel = null;
|
|
228
|
-
device;
|
|
229
|
-
quantization;
|
|
230
|
-
constructor(config = {}) {
|
|
231
|
-
this.device = config.device ?? "auto";
|
|
232
|
-
this.quantization = config.quantization ?? "q4";
|
|
233
|
-
}
|
|
234
|
-
get isReady() {
|
|
235
|
-
return this.pipeline !== null && this.currentModel !== null;
|
|
236
|
-
}
|
|
237
|
-
get modelId() {
|
|
238
|
-
return this.currentModel;
|
|
239
|
-
}
|
|
240
|
-
async load(modelId, onProgress) {
|
|
241
|
-
const resolvedModel = modelId in TRANSFORMERS_MODELS ? TRANSFORMERS_MODELS[modelId] : modelId;
|
|
242
|
-
const { pipeline: pipeline2, env } = await import("@huggingface/transformers");
|
|
243
|
-
env.allowLocalModels = false;
|
|
244
|
-
env.useBrowserCache = true;
|
|
245
|
-
let deviceOption = "wasm";
|
|
246
|
-
if (this.device === "auto" || this.device === "webgpu") {
|
|
247
|
-
if (typeof navigator !== "undefined" && "gpu" in navigator) {
|
|
248
|
-
try {
|
|
249
|
-
const gpu = navigator.gpu;
|
|
250
|
-
const adapter = await gpu.requestAdapter();
|
|
251
|
-
if (adapter) {
|
|
252
|
-
deviceOption = "webgpu";
|
|
253
|
-
}
|
|
254
|
-
} catch {
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
const task = isVisionModel(resolvedModel) ? "image-text-to-text" : "text-generation";
|
|
259
|
-
const dtype = mapQuantization(this.quantization);
|
|
260
|
-
this.pipeline = await pipeline2(task, resolvedModel, {
|
|
261
|
-
dtype,
|
|
262
|
-
device: deviceOption,
|
|
263
|
-
progress_callback: (progress) => {
|
|
264
|
-
if (onProgress) {
|
|
265
|
-
const loadProgress = {
|
|
266
|
-
progress: Math.round((progress.progress ?? 0) * 100),
|
|
267
|
-
status: progress.status
|
|
268
|
-
};
|
|
269
|
-
onProgress(loadProgress);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
this.currentModel = resolvedModel;
|
|
274
|
-
}
|
|
275
|
-
async chat(messages, options) {
|
|
276
|
-
if (!this.pipeline || !this.currentModel) {
|
|
277
|
-
throw new Error("Model not loaded. Call load() first.");
|
|
278
|
-
}
|
|
279
|
-
const result = await this.pipeline(messages, {
|
|
280
|
-
max_new_tokens: options?.maxTokens ?? 512,
|
|
281
|
-
temperature: options?.temperature ?? 0.7,
|
|
282
|
-
top_p: options?.topP ?? 0.95,
|
|
283
|
-
do_sample: true,
|
|
284
|
-
return_full_text: false
|
|
285
|
-
});
|
|
286
|
-
const output = Array.isArray(result) ? result[0] : result;
|
|
287
|
-
return output.generated_text ?? "";
|
|
288
|
-
}
|
|
289
|
-
async stream(messages, onToken, options) {
|
|
290
|
-
if (!this.pipeline || !this.currentModel) {
|
|
291
|
-
throw new Error("Model not loaded. Call load() first.");
|
|
292
|
-
}
|
|
293
|
-
const { TextStreamer } = await import("@huggingface/transformers");
|
|
294
|
-
let fullText = "";
|
|
295
|
-
const streamer = new TextStreamer(this.pipeline.tokenizer, {
|
|
296
|
-
skip_prompt: true,
|
|
297
|
-
skip_special_tokens: true,
|
|
298
|
-
callback_function: (token) => {
|
|
299
|
-
fullText += token;
|
|
300
|
-
onToken(token, fullText);
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
await this.pipeline(messages, {
|
|
304
|
-
max_new_tokens: options?.maxTokens ?? 512,
|
|
305
|
-
temperature: options?.temperature ?? 0.7,
|
|
306
|
-
top_p: options?.topP ?? 0.95,
|
|
307
|
-
do_sample: true,
|
|
308
|
-
return_full_text: false,
|
|
309
|
-
streamer
|
|
310
|
-
});
|
|
311
|
-
return fullText;
|
|
312
|
-
}
|
|
313
|
-
async unload() {
|
|
314
|
-
this.pipeline = null;
|
|
315
|
-
this.currentModel = null;
|
|
316
|
-
}
|
|
317
|
-
};
|
|
318
|
-
function createTransformersProvider(config) {
|
|
319
|
-
return new TransformersProvider(config);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
187
|
// src/helpers.ts
|
|
323
188
|
function getElement(selector) {
|
|
324
189
|
if (typeof selector === "string") {
|
|
@@ -475,37 +340,15 @@ async function createLLM(config = {}) {
|
|
|
475
340
|
onLoadProgress
|
|
476
341
|
} = config;
|
|
477
342
|
const capabilities = await detectCapabilities();
|
|
478
|
-
let useBackend;
|
|
479
343
|
const explicitModel = config.model;
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (requestedBackend === "auto") {
|
|
483
|
-
if (explicitModel && isTransformersValue && !isWebLLMValue) {
|
|
484
|
-
useBackend = "transformers";
|
|
485
|
-
} else {
|
|
486
|
-
useBackend = capabilities.webgpu ? "webllm" : "transformers";
|
|
487
|
-
}
|
|
488
|
-
} else if (requestedBackend === "webllm") {
|
|
489
|
-
if (!capabilities.webgpu) {
|
|
490
|
-
console.warn("[LocalLLM] WebLLM requested but WebGPU not available. Falling back to Transformers.js");
|
|
491
|
-
useBackend = "transformers";
|
|
492
|
-
} else if (explicitModel && isTransformersValue && !isWebLLMValue) {
|
|
493
|
-
console.warn("[LocalLLM] Model specified is only compatible with Transformers.js. Falling back from explicit WebLLM.");
|
|
494
|
-
useBackend = "transformers";
|
|
495
|
-
} else {
|
|
496
|
-
useBackend = "webllm";
|
|
497
|
-
}
|
|
498
|
-
} else {
|
|
499
|
-
useBackend = "transformers";
|
|
344
|
+
if (requestedBackend === "webllm" && !capabilities.webgpu) {
|
|
345
|
+
console.warn("[LocalLLM] WebLLM requested but WebGPU not available. May fail.");
|
|
500
346
|
}
|
|
501
|
-
const
|
|
347
|
+
const useBackend = "webllm";
|
|
348
|
+
const model = config.model ?? DEFAULT_WEBLLM_MODEL;
|
|
502
349
|
console.log(`[LocalLLM] Using ${useBackend} backend with model: ${model}`);
|
|
503
350
|
let provider;
|
|
504
|
-
|
|
505
|
-
provider = new WebLLMProvider();
|
|
506
|
-
} else {
|
|
507
|
-
provider = new TransformersProvider({ device, quantization });
|
|
508
|
-
}
|
|
351
|
+
provider = new WebLLMProvider();
|
|
509
352
|
await provider.load(model, onLoadProgress);
|
|
510
353
|
const llm = {
|
|
511
354
|
get isReady() {
|
|
@@ -1225,8 +1068,8 @@ var DEFAULT_SYSTEM_PROMPT = `You are a helpful AI assistant.
|
|
|
1225
1068
|
B -- No --> D[Error]
|
|
1226
1069
|
\`\`\`
|
|
1227
1070
|
- You can use LaTeX math ($$ ... $$).`;
|
|
1228
|
-
var ALL_MODELS = { ...WEBLLM_MODELS
|
|
1229
|
-
function
|
|
1071
|
+
var ALL_MODELS = { ...WEBLLM_MODELS };
|
|
1072
|
+
function isVisionModel(modelId) {
|
|
1230
1073
|
if (!modelId) return false;
|
|
1231
1074
|
const lower = modelId.toLowerCase();
|
|
1232
1075
|
return lower.includes("vl") || lower.includes("vision") || lower.includes("moondream");
|
|
@@ -1267,7 +1110,7 @@ function ModelSelector({
|
|
|
1267
1110
|
if (!currentModel) return "Select Model";
|
|
1268
1111
|
const id = currentModel.split("/").pop() || currentModel;
|
|
1269
1112
|
let label = id.length > 25 ? id.substring(0, 25) + "..." : id;
|
|
1270
|
-
if (
|
|
1113
|
+
if (isVisionModel(currentModel)) {
|
|
1271
1114
|
label += " [VISION]";
|
|
1272
1115
|
}
|
|
1273
1116
|
return label;
|
|
@@ -1305,27 +1148,7 @@ function ModelSelector({
|
|
|
1305
1148
|
children: [
|
|
1306
1149
|
key,
|
|
1307
1150
|
" ",
|
|
1308
|
-
|
|
1309
|
-
]
|
|
1310
|
-
},
|
|
1311
|
-
key
|
|
1312
|
-
)),
|
|
1313
|
-
/* @__PURE__ */ jsx3("div", { className: "px-3 py-2 text-[10px] font-light text-current opacity-50 uppercase tracking-widest mt-4 border-b border-current/10 mb-1", children: "Transformers.js" }),
|
|
1314
|
-
Object.entries(TRANSFORMERS_MODELS).map(([key, value]) => /* @__PURE__ */ jsxs3(
|
|
1315
|
-
"button",
|
|
1316
|
-
{
|
|
1317
|
-
className: cn(
|
|
1318
|
-
"block w-full text-left px-3 py-2.5 text-[11px] font-light uppercase tracking-widest truncate transition-colors text-current",
|
|
1319
|
-
currentModel === value ? theme === "dark" ? "bg-white text-black" : "bg-black text-white" : "hover:opacity-60"
|
|
1320
|
-
),
|
|
1321
|
-
onClick: () => {
|
|
1322
|
-
onSelect(value);
|
|
1323
|
-
setIsOpen(false);
|
|
1324
|
-
},
|
|
1325
|
-
children: [
|
|
1326
|
-
key,
|
|
1327
|
-
" ",
|
|
1328
|
-
isVisionModel2(value) && /* @__PURE__ */ jsx3("span", { className: "ml-2 text-[9px] opacity-50", children: "[VISION]" })
|
|
1151
|
+
isVisionModel(value) && /* @__PURE__ */ jsx3("span", { className: "ml-2 text-[9px] opacity-50", children: "[VISION]" })
|
|
1329
1152
|
]
|
|
1330
1153
|
},
|
|
1331
1154
|
key
|
|
@@ -1391,7 +1214,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1391
1214
|
}
|
|
1392
1215
|
currentMessages.forEach((m) => {
|
|
1393
1216
|
let content = m.content;
|
|
1394
|
-
if (m.role === "user" && m.images && m.images.length > 0 &&
|
|
1217
|
+
if (m.role === "user" && m.images && m.images.length > 0 && isVisionModel(modelId || "")) {
|
|
1395
1218
|
if (llm.backend === "webllm") {
|
|
1396
1219
|
content = [
|
|
1397
1220
|
{ type: "text", text: m.content },
|
|
@@ -1407,7 +1230,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1407
1230
|
apiMessages.push({ role: m.role, content });
|
|
1408
1231
|
});
|
|
1409
1232
|
let finalUserContent = userContent;
|
|
1410
|
-
if (attachedImages.length > 0 &&
|
|
1233
|
+
if (attachedImages.length > 0 && isVisionModel(modelId || "")) {
|
|
1411
1234
|
if (llm.backend === "webllm") {
|
|
1412
1235
|
finalUserContent = [
|
|
1413
1236
|
{ type: "text", text: userContent },
|
|
@@ -1454,16 +1277,16 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1454
1277
|
setInput("");
|
|
1455
1278
|
setImages([]);
|
|
1456
1279
|
abortRef.current = false;
|
|
1457
|
-
if (!
|
|
1280
|
+
if (!isVisionModel(modelId || "")) {
|
|
1458
1281
|
const needsCaptioning = currentImages.filter((img) => !img.extractedText && !img.isSvg && !img.isPdf);
|
|
1459
1282
|
if (needsCaptioning.length > 0) {
|
|
1460
1283
|
setIsGenerating(true);
|
|
1461
1284
|
setStreamingText("[System: Initializing detailed image-to-text captioning pipeline (Florence-2)...]\n");
|
|
1462
1285
|
try {
|
|
1463
|
-
const { pipeline
|
|
1286
|
+
const { pipeline, env } = await import("@huggingface/transformers");
|
|
1464
1287
|
env.allowLocalModels = false;
|
|
1465
1288
|
env.useBrowserCache = true;
|
|
1466
|
-
const captioner = await
|
|
1289
|
+
const captioner = await pipeline("image-to-text", "Xenova/vit-gpt2-image-captioning", { device: "wasm", dtype: "q8" });
|
|
1467
1290
|
for (let i = 0; i < needsCaptioning.length; i++) {
|
|
1468
1291
|
if (abortRef.current) break;
|
|
1469
1292
|
const img = needsCaptioning[i];
|
|
@@ -1503,7 +1326,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1503
1326
|
|
|
1504
1327
|
\u{1F4C4} SVG Source Code (${img.name}):
|
|
1505
1328
|
`;
|
|
1506
|
-
} else if (!img.isPdf && !
|
|
1329
|
+
} else if (!img.isPdf && !isVisionModel(modelId || "")) {
|
|
1507
1330
|
prefix = `
|
|
1508
1331
|
|
|
1509
1332
|
\u{1F5BC}\uFE0F System Image Representation (${img.name}) - [IMPORTANT SYSTEM INSTRUCTION: The user provided an image. Since you are a text model, here is an automated visual description of the image. DO NOT refuse the user's prompt. Answer as if you can see the image using this context:]
|
|
@@ -1685,7 +1508,7 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1685
1508
|
}
|
|
1686
1509
|
function ChatApp({
|
|
1687
1510
|
defaultModel = "qwen-2.5-0.5b",
|
|
1688
|
-
defaultBackend = "
|
|
1511
|
+
defaultBackend = "webllm",
|
|
1689
1512
|
autoLoad = true,
|
|
1690
1513
|
onModelChange,
|
|
1691
1514
|
...chatProps
|
|
@@ -1720,12 +1543,8 @@ export {
|
|
|
1720
1543
|
logCapabilities,
|
|
1721
1544
|
DEFAULT_WEBLLM_MODEL,
|
|
1722
1545
|
WEBLLM_MODELS,
|
|
1723
|
-
DEFAULT_TRANSFORMERS_MODEL,
|
|
1724
|
-
TRANSFORMERS_MODELS,
|
|
1725
1546
|
WebLLMProvider,
|
|
1726
1547
|
createWebLLMProvider,
|
|
1727
|
-
TransformersProvider,
|
|
1728
|
-
createTransformersProvider,
|
|
1729
1548
|
createOutputStreamer,
|
|
1730
1549
|
attachToElements,
|
|
1731
1550
|
createChatUI,
|
|
@@ -41,33 +41,11 @@ declare const WEBLLM_MODELS: {
|
|
|
41
41
|
readonly 'hermes-3-llama-3.2-3b': "Hermes-3-Llama-3.2-3B-q4f16_1-MLC";
|
|
42
42
|
readonly 'hermes-3-llama-3.1-8b': "Hermes-3-Llama-3.1-8B-q4f16_1-MLC";
|
|
43
43
|
};
|
|
44
|
-
/**
|
|
45
|
-
* Default model for Transformers.js backend
|
|
46
|
-
* Using Qwen2.5 0.5B as it's well-tested with ONNX
|
|
47
|
-
*/
|
|
48
|
-
declare const DEFAULT_TRANSFORMERS_MODEL = "onnx-community/Qwen2.5-0.5B-Instruct";
|
|
49
|
-
/**
|
|
50
|
-
* Transformers.js compatible models (must have ONNX weights)
|
|
51
|
-
* These are specifically converted for browser use via transformers.js
|
|
52
|
-
*
|
|
53
|
-
* @see https://huggingface.co/onnx-community for more models
|
|
54
|
-
*/
|
|
55
|
-
declare const TRANSFORMERS_MODELS: {
|
|
56
|
-
readonly 'qwen-2.5-0.5b': "onnx-community/Qwen2.5-0.5B-Instruct";
|
|
57
|
-
readonly 'qwen-2.5-1.5b': "onnx-community/Qwen2.5-1.5B-Instruct";
|
|
58
|
-
readonly 'qwen-2.5-coder-0.5b': "onnx-community/Qwen2.5-Coder-0.5B-Instruct";
|
|
59
|
-
readonly 'qwen-2.5-coder-1.5b': "onnx-community/Qwen2.5-Coder-1.5B-Instruct";
|
|
60
|
-
readonly 'phi-3.5-vision': "onnx-community/Phi-3.5-vision-instruct";
|
|
61
|
-
readonly 'smollm2-135m': "HuggingFaceTB/SmolLM2-135M-Instruct";
|
|
62
|
-
readonly 'smollm2-1.7b': "HuggingFaceTB/SmolLM2-1.7B-Instruct";
|
|
63
|
-
readonly 'phi-3-mini': "Xenova/Phi-3-mini-4k-instruct";
|
|
64
|
-
};
|
|
65
44
|
type WebLLMModelID = keyof typeof WEBLLM_MODELS;
|
|
66
|
-
type TransformersModelID = keyof typeof TRANSFORMERS_MODELS;
|
|
67
45
|
/**
|
|
68
46
|
* Union of all supported model IDs for type safety
|
|
69
47
|
*/
|
|
70
|
-
type SupportedModel = WebLLMModelID |
|
|
48
|
+
type SupportedModel = WebLLMModelID | (string & {});
|
|
71
49
|
|
|
72
50
|
/**
|
|
73
51
|
* Local LLM - Browser-based LLM inference library
|
|
@@ -76,7 +54,7 @@ type SupportedModel = WebLLMModelID | TransformersModelID | (string & {});
|
|
|
76
54
|
/**
|
|
77
55
|
* Supported backend engines
|
|
78
56
|
*/
|
|
79
|
-
type Backend = 'webllm'
|
|
57
|
+
type Backend = 'webllm';
|
|
80
58
|
/**
|
|
81
59
|
* Device to run inference on
|
|
82
60
|
*/
|
|
@@ -92,7 +70,7 @@ type Quantization = 'q4' | 'q8' | 'fp16' | 'fp32';
|
|
|
92
70
|
interface LLMConfig {
|
|
93
71
|
/**
|
|
94
72
|
* Model identifier. For WebLLM, use MLC model IDs.
|
|
95
|
-
*
|
|
73
|
+
* Use WebLLM compatible model IDs.
|
|
96
74
|
* @default 'Phi-3-mini-4k-instruct-q4f16_1-MLC' for WebLLM
|
|
97
75
|
*/
|
|
98
76
|
model?: SupportedModel;
|
|
@@ -270,7 +248,7 @@ interface LocalLLM {
|
|
|
270
248
|
/**
|
|
271
249
|
* The backend being used
|
|
272
250
|
*/
|
|
273
|
-
readonly backend: 'webllm'
|
|
251
|
+
readonly backend: 'webllm';
|
|
274
252
|
/**
|
|
275
253
|
* Generate a chat response
|
|
276
254
|
*/
|
|
@@ -608,7 +586,7 @@ interface ChatProps {
|
|
|
608
586
|
}
|
|
609
587
|
interface ChatAppProps extends ChatProps {
|
|
610
588
|
defaultModel?: SupportedModel;
|
|
611
|
-
defaultBackend?: 'webllm'
|
|
589
|
+
defaultBackend?: 'webllm';
|
|
612
590
|
autoLoad?: boolean;
|
|
613
591
|
}
|
|
614
592
|
declare function Chat({ systemPrompt, placeholder, theme, className, maxHeight, inputActions, onSend: onSendProp, onResponse, onError: onErrorProp, showHeader, showProgress, welcomeMessage, onModelChange, }: ChatProps): React.JSX.Element;
|
|
@@ -642,4 +620,4 @@ interface ChatInputProps {
|
|
|
642
620
|
}
|
|
643
621
|
declare function ChatInput({ value, onChange, onSend, onStop, disabled, isGenerating, placeholder, maxRows, actions, className, images, onImageAdd, onImageRemove, modelSelector, theme, }: ChatInputProps): react_jsx_runtime.JSX.Element;
|
|
644
622
|
|
|
645
|
-
export { type AttachOptions as A, type BrowserCapabilities as B, type ChatMessage as C,
|
|
623
|
+
export { type AttachOptions as A, type BrowserCapabilities as B, type ChatMessage as C, DEFAULT_WEBLLM_MODEL as D, useLLM as E, useStream as F, type GenerateOptions as G, ChatApp as H, type ChatAppProps as I, type ImageAttachment as J, type LLMProvider$1 as L, type MessageRole as M, type Quantization as Q, type StreamCallback as S, type UseChatOptions as U, WEBLLM_MODELS as W, type Backend as a, type LoadProgressCallback as b, Chat as c, ChatInput as d, type ChatInputProps as e, type ChatProps as f, type Device as g, type LLMConfig as h, type LLMContextValue as i, LLMLoading as j, type LLMLoadingProps as k, LLMProvider as l, type LLMProviderProps as m, LLMReady as n, type LLMReadyProps as o, type LoadProgress as p, type LocalLLM as q, type UseChatReturn as r, type UseCompletionOptions as s, type UseCompletionReturn as t, type UseStreamOptions as u, type UseStreamReturn as v, createLLM as w, isWebGPUSupported as x, useChat as y, useCompletion as z };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BrowserCapabilities, L as LLMProvider, a as Backend, b as LoadProgressCallback, C as ChatMessage, G as GenerateOptions, S as StreamCallback,
|
|
2
|
-
export { c as Chat, d as ChatInput, e as ChatInputProps, f as ChatProps,
|
|
1
|
+
import { B as BrowserCapabilities, L as LLMProvider, a as Backend, b as LoadProgressCallback, C as ChatMessage, G as GenerateOptions, S as StreamCallback, A as AttachOptions } from './index-DJmiDzY3.js';
|
|
2
|
+
export { c as Chat, d as ChatInput, e as ChatInputProps, f as ChatProps, D as DEFAULT_WEBLLM_MODEL, g as Device, h as LLMConfig, i as LLMContextValue, j as LLMLoading, k as LLMLoadingProps, l as LLMProvider, m as LLMProviderProps, n as LLMReady, o as LLMReadyProps, p as LoadProgress, q as LocalLLM, M as MessageRole, Q as Quantization, U as UseChatOptions, r as UseChatReturn, s as UseCompletionOptions, t as UseCompletionReturn, u as UseStreamOptions, v as UseStreamReturn, W as WEBLLM_MODELS, w as createLLM, w as default, x as isWebGPUSupported, y as useChat, z as useCompletion, E as useLLM, F as useStream } from './index-DJmiDzY3.js';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
|
@@ -48,40 +48,6 @@ declare class WebLLMProvider implements LLMProvider {
|
|
|
48
48
|
*/
|
|
49
49
|
declare function createWebLLMProvider(): WebLLMProvider;
|
|
50
50
|
|
|
51
|
-
/**
|
|
52
|
-
* Transformers.js Backend Implementation
|
|
53
|
-
* Fallback backend using HuggingFace Transformers.js with ONNX runtime
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Configuration for TransformersProvider
|
|
58
|
-
*/
|
|
59
|
-
interface TransformersProviderConfig {
|
|
60
|
-
device?: Device;
|
|
61
|
-
quantization?: Quantization;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Transformers.js provider implementation
|
|
65
|
-
*/
|
|
66
|
-
declare class TransformersProvider implements LLMProvider {
|
|
67
|
-
readonly backend: Backend;
|
|
68
|
-
private pipeline;
|
|
69
|
-
private currentModel;
|
|
70
|
-
private device;
|
|
71
|
-
private quantization;
|
|
72
|
-
constructor(config?: TransformersProviderConfig);
|
|
73
|
-
get isReady(): boolean;
|
|
74
|
-
get modelId(): string | null;
|
|
75
|
-
load(modelId: string, onProgress?: LoadProgressCallback): Promise<void>;
|
|
76
|
-
chat(messages: ChatMessage[], options?: GenerateOptions): Promise<string>;
|
|
77
|
-
stream(messages: ChatMessage[], onToken: StreamCallback, options?: GenerateOptions): Promise<string>;
|
|
78
|
-
unload(): Promise<void>;
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Create a Transformers.js provider instance
|
|
82
|
-
*/
|
|
83
|
-
declare function createTransformersProvider(config?: TransformersProviderConfig): TransformersProvider;
|
|
84
|
-
|
|
85
51
|
/**
|
|
86
52
|
* DOM Helper Utilities
|
|
87
53
|
* Easy integration with HTML input/output elements
|
|
@@ -117,4 +83,4 @@ declare function createLoadingIndicator(containerSelector: string | HTMLElement)
|
|
|
117
83
|
element: HTMLDivElement;
|
|
118
84
|
};
|
|
119
85
|
|
|
120
|
-
export { AttachOptions, Backend, BrowserCapabilities, ChatMessage,
|
|
86
|
+
export { AttachOptions, Backend, BrowserCapabilities, ChatMessage, GenerateOptions, LLMProvider as LLMProviderInterface, LoadProgressCallback, StreamCallback, WebLLMProvider, attachToElements, checkWasm, checkWebGPU, createChatUI, createLoadingIndicator, createOutputStreamer, createWebLLMProvider, detectCapabilities, logCapabilities };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Chat,
|
|
3
3
|
ChatInput,
|
|
4
|
-
DEFAULT_TRANSFORMERS_MODEL,
|
|
5
4
|
DEFAULT_WEBLLM_MODEL,
|
|
6
5
|
LLMLoading,
|
|
7
6
|
LLMProvider,
|
|
8
7
|
LLMReady,
|
|
9
|
-
TRANSFORMERS_MODELS,
|
|
10
|
-
TransformersProvider,
|
|
11
8
|
WEBLLM_MODELS,
|
|
12
9
|
WebLLMProvider,
|
|
13
10
|
attachToElements,
|
|
@@ -17,7 +14,6 @@ import {
|
|
|
17
14
|
createLLM,
|
|
18
15
|
createLoadingIndicator,
|
|
19
16
|
createOutputStreamer,
|
|
20
|
-
createTransformersProvider,
|
|
21
17
|
createWebLLMProvider,
|
|
22
18
|
detectCapabilities,
|
|
23
19
|
isWebGPUSupported,
|
|
@@ -26,17 +22,14 @@ import {
|
|
|
26
22
|
useCompletion,
|
|
27
23
|
useLLM,
|
|
28
24
|
useStream
|
|
29
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-A7TUIC5G.js";
|
|
30
26
|
export {
|
|
31
27
|
Chat,
|
|
32
28
|
ChatInput,
|
|
33
|
-
DEFAULT_TRANSFORMERS_MODEL,
|
|
34
29
|
DEFAULT_WEBLLM_MODEL,
|
|
35
30
|
LLMLoading,
|
|
36
31
|
LLMProvider,
|
|
37
32
|
LLMReady,
|
|
38
|
-
TRANSFORMERS_MODELS,
|
|
39
|
-
TransformersProvider,
|
|
40
33
|
WEBLLM_MODELS,
|
|
41
34
|
WebLLMProvider,
|
|
42
35
|
attachToElements,
|
|
@@ -46,7 +39,6 @@ export {
|
|
|
46
39
|
createLLM,
|
|
47
40
|
createLoadingIndicator,
|
|
48
41
|
createOutputStreamer,
|
|
49
|
-
createTransformersProvider,
|
|
50
42
|
createWebLLMProvider,
|
|
51
43
|
createLLM as default,
|
|
52
44
|
detectCapabilities,
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { c as Chat,
|
|
1
|
+
export { c as Chat, H as ChatApp, I as ChatAppProps, d as ChatInput, e as ChatInputProps, f as ChatProps, J as ImageAttachment, i as LLMContextValue, j as LLMLoading, k as LLMLoadingProps, l as LLMProvider, m as LLMProviderProps, n as LLMReady, o as LLMReadyProps, U as UseChatOptions, r as UseChatReturn, s as UseCompletionOptions, t as UseCompletionReturn, u as UseStreamOptions, v as UseStreamReturn, y as useChat, z as useCompletion, E as useLLM, F as useStream } from '../index-DJmiDzY3.js';
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
3
|
import 'react';
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED