@blank-utils/llm 0.4.10 → 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.
@@ -954,7 +954,14 @@ function ChatInput({
954
954
  ${pageText}
955
955
 
956
956
  `;
957
- 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);
958
965
  const viewport = page.getViewport({ scale: 2 });
959
966
  const canvas = document.createElement("canvas");
960
967
  const context = canvas.getContext("2d");
@@ -977,19 +984,22 @@ ${pageText}
977
984
  }
978
985
  const imgFile = new File([u8arr], `__PDF__${file.name}__page${i}.jpg`, { type: mime });
979
986
  const id = Math.random().toString(36).substring(7);
980
- 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
+ });
981
994
  }
982
995
  }
983
996
  }
984
997
  }
985
- }
986
- const newText = `\u{1F4C4} PDF: ${file.name} (${pdf.numPages} pages total, showing images for first ${maxPages} pages)
987
-
988
- Extracted Text:
989
- ${fullText}`;
990
- onChange(value ? `${value}
998
+ } else {
999
+ onChange(value ? `${value}
991
1000
 
992
1001
  ${newText}` : newText);
1002
+ }
993
1003
  } catch (err) {
994
1004
  console.error("Error extracting PDF:", err);
995
1005
  }
@@ -1419,13 +1429,19 @@ ${systemPrompt}` : systemPrompt;
1419
1429
  const text = input.trim();
1420
1430
  if (!text && images.length === 0) return;
1421
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
+ }
1422
1438
  setInput("");
1423
1439
  setImages([]);
1424
- onSendProp?.(text);
1440
+ onSendProp?.(finalText);
1425
1441
  if (llm && isReady) {
1426
- generate(text, messages, currentImages);
1442
+ generate(finalText, messages, currentImages);
1427
1443
  } else if (isLoading) {
1428
- setPendingMessage(text);
1444
+ setPendingMessage(finalText);
1429
1445
  }
1430
1446
  };
1431
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-JD2HWBEJ.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-JD2HWBEJ.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.10",
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",