@blank-utils/llm 0.4.20 → 0.4.23

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.
@@ -989,7 +989,8 @@ ${fullText}`;
989
989
  dataUrl,
990
990
  file: imgFile,
991
991
  name: imgFile.name,
992
- extractedText: i === 1 ? newText : void 0
992
+ extractedText: i === 1 ? newText : void 0,
993
+ isPdf: true
993
994
  });
994
995
  }
995
996
  }
@@ -1019,7 +1020,8 @@ ${newText}` : newText);
1019
1020
  dataUrl,
1020
1021
  file,
1021
1022
  name: file.name,
1022
- extractedText: text
1023
+ extractedText: text,
1024
+ isSvg: true
1023
1025
  });
1024
1026
  }
1025
1027
  };
@@ -1453,7 +1455,7 @@ ${systemPrompt}` : systemPrompt;
1453
1455
  setImages([]);
1454
1456
  abortRef.current = false;
1455
1457
  if (!isVisionModel2(modelId || "")) {
1456
- const needsCaptioning = currentImages.filter((img) => !img.extractedText && !img.name.toLowerCase().endsWith(".svg") && !img.name.toLowerCase().endsWith(".pdf"));
1458
+ const needsCaptioning = currentImages.filter((img) => !img.extractedText && !img.isSvg && !img.isPdf);
1457
1459
  if (needsCaptioning.length > 0) {
1458
1460
  setIsGenerating(true);
1459
1461
  setStreamingText("[System: Initializing detailed image-to-text captioning pipeline (Florence-2)...]\n");
@@ -1496,15 +1498,19 @@ ${systemPrompt}` : systemPrompt;
1496
1498
  for (const img of currentImages) {
1497
1499
  if (img.extractedText) {
1498
1500
  let prefix = "";
1499
- if (img.name.toLowerCase().endsWith(".svg")) {
1500
- prefix = `\u{1F4C4} SVG Source Code (${img.name}):
1501
+ if (img.isSvg) {
1502
+ prefix = `
1503
+
1504
+ \u{1F4C4} SVG Source Code (${img.name}):
1501
1505
  `;
1502
- } else if (!isVisionModel2(modelId || "")) {
1503
- prefix = `\u{1F5BC}\uFE0F Image Auto-Caption (${img.name}):
1506
+ } else if (!img.isPdf && !isVisionModel2(modelId || "")) {
1507
+ prefix = `
1508
+
1509
+ \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:]
1504
1510
  `;
1505
1511
  }
1506
- if (prefix || img.name.toLowerCase().endsWith(".pdf")) {
1507
- finalText += (finalText ? "\n\n" : "") + `${prefix}${img.extractedText}`;
1512
+ if (prefix || img.isPdf) {
1513
+ finalText += `${prefix}${img.isPdf ? "\n\n" : ""}${img.extractedText}`;
1508
1514
  }
1509
1515
  }
1510
1516
  }
@@ -1615,11 +1621,11 @@ ${systemPrompt}` : systemPrompt;
1615
1621
  children: [
1616
1622
  { match: "\u{1F4C4} PDF:", index: msg.content.indexOf("\u{1F4C4} PDF:") },
1617
1623
  { match: "\u{1F4C4} SVG Source Code", index: msg.content.indexOf("\u{1F4C4} SVG Source Code") },
1618
- { match: "\u{1F5BC}\uFE0F Image Auto-Caption", index: msg.content.indexOf("\u{1F5BC}\uFE0F Image Auto-Caption") }
1624
+ { match: "\u{1F5BC}\uFE0F System Image", index: msg.content.indexOf("\u{1F5BC}\uFE0F System Image") }
1619
1625
  ].filter((m) => m.index !== -1).reduce((min, m) => m.index < min ? m.index : min, msg.content.length) !== msg.content.length ? msg.content.substring(0, [
1620
1626
  { match: "\u{1F4C4} PDF:", index: msg.content.indexOf("\u{1F4C4} PDF:") },
1621
1627
  { match: "\u{1F4C4} SVG Source Code", index: msg.content.indexOf("\u{1F4C4} SVG Source Code") },
1622
- { match: "\u{1F5BC}\uFE0F Image Auto-Caption", index: msg.content.indexOf("\u{1F5BC}\uFE0F Image Auto-Caption") }
1628
+ { match: "\u{1F5BC}\uFE0F System Image", index: msg.content.indexOf("\u{1F5BC}\uFE0F System Image") }
1623
1629
  ].filter((m) => m.index !== -1).reduce((min, m) => m.index < min ? m.index : min, msg.content.length)).trim() : msg.content
1624
1630
  }
1625
1631
  ) })
@@ -620,6 +620,8 @@ interface ImageAttachment {
620
620
  file: File;
621
621
  name: string;
622
622
  extractedText?: string;
623
+ isPdf?: boolean;
624
+ isSvg?: boolean;
623
625
  }
624
626
  interface ChatInputProps {
625
627
  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-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';
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-Dp-zMbxY.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-Dp-zMbxY.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-T4VK6BPC.js";
29
+ } from "./chunk-IOEC4YOD.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-DxcdKb-M.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-Dp-zMbxY.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-T4VK6BPC.js";
12
+ } from "../chunk-IOEC4YOD.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.20",
3
+ "version": "0.4.23",
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",