@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 = `https://unpkg.com/pdfjs-dist@${pdfjsLib.version}/build/pdf.worker.min.mjs`;
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
- if (i <= maxPages && onImageAdd) {
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({ id, dataUrl, file: imgFile, name: imgFile.name });
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
- const newText = `\u{1F4C4} PDF: ${file.name} (${pdf.numPages} pages total, showing images for first ${maxPages} pages)
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?.(text);
1440
+ onSendProp?.(finalText);
1422
1441
  if (llm && isReady) {
1423
- generate(text, messages, currentImages);
1442
+ generate(finalText, messages, currentImages);
1424
1443
  } else if (isLoading) {
1425
- setPendingMessage(text);
1444
+ setPendingMessage(finalText);
1426
1445
  }
1427
1446
  };
1428
1447
  const handleStop = () => {
@@ -619,6 +619,7 @@ interface ImageAttachment {
619
619
  dataUrl: string;
620
620
  file: File;
621
621
  name: string;
622
+ extractedText?: string;
622
623
  }
623
624
  interface ChatInputProps {
624
625
  value: string;
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-C3lo7t8l.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-C3lo7t8l.js';
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
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-ZCKQLTCD.js";
29
+ } from "./chunk-XDCST2X2.js";
30
30
  export {
31
31
  Chat,
32
32
  ChatInput,
@@ -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-C3lo7t8l.js';
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';
@@ -9,7 +9,7 @@ import {
9
9
  useCompletion,
10
10
  useLLM,
11
11
  useStream
12
- } from "../chunk-ZCKQLTCD.js";
12
+ } from "../chunk-XDCST2X2.js";
13
13
  export {
14
14
  Chat,
15
15
  ChatApp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blank-utils/llm",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Run LLMs directly in your browser with WebGPU acceleration. Supports React hooks and eager background loading.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",