@blank-utils/llm 0.4.9 → 0.4.11
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.
|
@@ -939,7 +939,10 @@ function ChatInput({
|
|
|
939
939
|
const arrayBuffer = e.target?.result;
|
|
940
940
|
if (!arrayBuffer) return;
|
|
941
941
|
const pdfjsLib = await import("pdfjs-dist");
|
|
942
|
-
pdfjsLib.GlobalWorkerOptions.workerSrc =
|
|
942
|
+
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
|
|
943
|
+
"pdfjs-dist/build/pdf.worker.min.mjs",
|
|
944
|
+
import.meta.url
|
|
945
|
+
).toString();
|
|
943
946
|
const pdf = await pdfjsLib.getDocument(arrayBuffer).promise;
|
|
944
947
|
let fullText = "";
|
|
945
948
|
const maxPages = Math.min(pdf.numPages, 10);
|
|
@@ -951,7 +954,14 @@ function ChatInput({
|
|
|
951
954
|
${pageText}
|
|
952
955
|
|
|
953
956
|
`;
|
|
954
|
-
|
|
957
|
+
}
|
|
958
|
+
const newText = `\u{1F4C4} PDF: ${file.name} (${pdf.numPages} pages total, showing images for first ${maxPages} pages)
|
|
959
|
+
|
|
960
|
+
Extracted Text:
|
|
961
|
+
${fullText}`;
|
|
962
|
+
if (onImageAdd) {
|
|
963
|
+
for (let i = 1; i <= maxPages; i++) {
|
|
964
|
+
const page = await pdf.getPage(i);
|
|
955
965
|
const viewport = page.getViewport({ scale: 2 });
|
|
956
966
|
const canvas = document.createElement("canvas");
|
|
957
967
|
const context = canvas.getContext("2d");
|
|
@@ -974,19 +984,22 @@ ${pageText}
|
|
|
974
984
|
}
|
|
975
985
|
const imgFile = new File([u8arr], `__PDF__${file.name}__page${i}.jpg`, { type: mime });
|
|
976
986
|
const id = Math.random().toString(36).substring(7);
|
|
977
|
-
onImageAdd({
|
|
987
|
+
onImageAdd({
|
|
988
|
+
id,
|
|
989
|
+
dataUrl,
|
|
990
|
+
file: imgFile,
|
|
991
|
+
name: imgFile.name,
|
|
992
|
+
extractedText: i === 1 ? newText : void 0
|
|
993
|
+
});
|
|
978
994
|
}
|
|
979
995
|
}
|
|
980
996
|
}
|
|
981
997
|
}
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
Extracted Text:
|
|
986
|
-
${fullText}`;
|
|
987
|
-
onChange(value ? `${value}
|
|
998
|
+
} else {
|
|
999
|
+
onChange(value ? `${value}
|
|
988
1000
|
|
|
989
1001
|
${newText}` : newText);
|
|
1002
|
+
}
|
|
990
1003
|
} catch (err) {
|
|
991
1004
|
console.error("Error extracting PDF:", err);
|
|
992
1005
|
}
|
|
@@ -1416,13 +1429,19 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1416
1429
|
const text = input.trim();
|
|
1417
1430
|
if (!text && images.length === 0) return;
|
|
1418
1431
|
const currentImages = [...images];
|
|
1432
|
+
let finalText = text;
|
|
1433
|
+
for (const img of currentImages) {
|
|
1434
|
+
if (img.extractedText) {
|
|
1435
|
+
finalText += (finalText ? "\n\n" : "") + img.extractedText;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1419
1438
|
setInput("");
|
|
1420
1439
|
setImages([]);
|
|
1421
|
-
onSendProp?.(
|
|
1440
|
+
onSendProp?.(finalText);
|
|
1422
1441
|
if (llm && isReady) {
|
|
1423
|
-
generate(
|
|
1442
|
+
generate(finalText, messages, currentImages);
|
|
1424
1443
|
} else if (isLoading) {
|
|
1425
|
-
setPendingMessage(
|
|
1444
|
+
setPendingMessage(finalText);
|
|
1426
1445
|
}
|
|
1427
1446
|
};
|
|
1428
1447
|
const handleStop = () => {
|
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, D as Device, Q as Quantization, A as AttachOptions } from './index-
|
|
2
|
-
export { c as Chat, d as ChatInput, e as ChatInputProps, f as ChatProps, g as DEFAULT_TRANSFORMERS_MODEL, h as DEFAULT_WEBLLM_MODEL, i as LLMConfig, j as LLMContextValue, k as LLMLoading, l as LLMLoadingProps, m as LLMProvider, n as LLMProviderProps, o as LLMReady, p as LLMReadyProps, q as LoadProgress, r as LocalLLM, M as MessageRole, T as TRANSFORMERS_MODELS, U as UseChatOptions, s as UseChatReturn, t as UseCompletionOptions, u as UseCompletionReturn, v as UseStreamOptions, w as UseStreamReturn, W as WEBLLM_MODELS, x as createLLM, x as default, y as isWebGPUSupported, z as useChat, E as useCompletion, F as useLLM, H as useStream } from './index-
|
|
1
|
+
import { B as BrowserCapabilities, L as LLMProvider, a as Backend, b as LoadProgressCallback, C as ChatMessage, G as GenerateOptions, S as StreamCallback, D as Device, Q as Quantization, A as AttachOptions } from './index-DxcdKb-M.js';
|
|
2
|
+
export { c as Chat, d as ChatInput, e as ChatInputProps, f as ChatProps, g as DEFAULT_TRANSFORMERS_MODEL, h as DEFAULT_WEBLLM_MODEL, i as LLMConfig, j as LLMContextValue, k as LLMLoading, l as LLMLoadingProps, m as LLMProvider, n as LLMProviderProps, o as LLMReady, p as LLMReadyProps, q as LoadProgress, r as LocalLLM, M as MessageRole, T as TRANSFORMERS_MODELS, U as UseChatOptions, s as UseChatReturn, t as UseCompletionOptions, u as UseCompletionReturn, v as UseStreamOptions, w as UseStreamReturn, W as WEBLLM_MODELS, x as createLLM, x as default, y as isWebGPUSupported, z as useChat, E as useCompletion, F as useLLM, H as useStream } from './index-DxcdKb-M.js';
|
|
3
3
|
import 'react/jsx-runtime';
|
|
4
4
|
import 'react';
|
|
5
5
|
|
package/dist/index.js
CHANGED
package/dist/react/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { c as Chat, I as ChatApp, J as ChatAppProps, d as ChatInput, e as ChatInputProps, f as ChatProps, K as ImageAttachment, j as LLMContextValue, k as LLMLoading, l as LLMLoadingProps, m as LLMProvider, n as LLMProviderProps, o as LLMReady, p as LLMReadyProps, U as UseChatOptions, s as UseChatReturn, t as UseCompletionOptions, u as UseCompletionReturn, v as UseStreamOptions, w as UseStreamReturn, z as useChat, E as useCompletion, F as useLLM, H as useStream } from '../index-
|
|
1
|
+
export { c as Chat, I as ChatApp, J as ChatAppProps, d as ChatInput, e as ChatInputProps, f as ChatProps, K as ImageAttachment, j as LLMContextValue, k as LLMLoading, l as LLMLoadingProps, m as LLMProvider, n as LLMProviderProps, o as LLMReady, p as LLMReadyProps, U as UseChatOptions, s as UseChatReturn, t as UseCompletionOptions, u as UseCompletionReturn, v as UseStreamOptions, w as UseStreamReturn, z as useChat, E as useCompletion, F as useLLM, H as useStream } from '../index-DxcdKb-M.js';
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
3
|
import 'react';
|
package/dist/react/index.js
CHANGED
package/package.json
CHANGED