@blank-utils/llm 0.4.15 → 0.4.16

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.
@@ -915,9 +915,10 @@ function ChatInput({
915
915
  const textareaRef = useRef2(null);
916
916
  const fileInputRef = useRef2(null);
917
917
  const [isDragging, setIsDragging] = useState2(false);
918
- const captionerRef = useRef2(null);
918
+ const captionerPromiseRef = useRef2(null);
919
919
  useEffect2(() => {
920
920
  let mounted = true;
921
+ if (captionerPromiseRef.current) return;
921
922
  const initCaptioner = async () => {
922
923
  try {
923
924
  console.log("[ImagePipeline] Initializing Transformers.js background captioner...");
@@ -925,18 +926,16 @@ function ChatInput({
925
926
  env.allowLocalModels = false;
926
927
  env.useBrowserCache = true;
927
928
  const captioner = await pipeline2("image-to-text", "Xenova/vit-gpt2-image-captioning", {
928
- device: "wasm",
929
- dtype: "q8"
929
+ device: "wasm"
930
930
  });
931
- if (mounted) {
932
- console.log("[ImagePipeline] Captioner loaded successfully!");
933
- captionerRef.current = captioner;
934
- }
931
+ if (mounted) console.log("[ImagePipeline] Captioner loaded successfully!");
932
+ return captioner;
935
933
  } catch (err) {
936
934
  console.warn("Failed to initialize background captioner:", err);
935
+ return null;
937
936
  }
938
937
  };
939
- initCaptioner();
938
+ captionerPromiseRef.current = initCaptioner();
940
939
  return () => {
941
940
  mounted = false;
942
941
  };
@@ -1059,22 +1058,27 @@ ${newText}` : newText);
1059
1058
  const id = Math.random().toString(36).substring(7);
1060
1059
  const dataUrl = e.target.result;
1061
1060
  let extractedText;
1062
- if (captionerRef.current) {
1063
- console.log(`[ImagePipeline] Generating caption for ${file.name}...`);
1061
+ if (captionerPromiseRef.current) {
1062
+ console.log(`[ImagePipeline] Generating caption for ${file.name} (Waiting for captioner)...`);
1064
1063
  try {
1065
- const out = await captionerRef.current(dataUrl);
1066
- console.log("[ImagePipeline] Raw captioner output:", out);
1067
- if (Array.isArray(out) && out[0] && out[0].generated_text) {
1068
- extractedText = out[0].generated_text;
1069
- } else if (!Array.isArray(out) && out.generated_text) {
1070
- extractedText = out.generated_text;
1064
+ const captioner = await captionerPromiseRef.current;
1065
+ if (captioner) {
1066
+ const out = await captioner(dataUrl);
1067
+ console.log("[ImagePipeline] Raw captioner output:", out);
1068
+ if (Array.isArray(out) && out[0] && out[0].generated_text) {
1069
+ extractedText = out[0].generated_text;
1070
+ } else if (!Array.isArray(out) && out.generated_text) {
1071
+ extractedText = out.generated_text;
1072
+ }
1073
+ console.log("[ImagePipeline] Extracted caption text:", extractedText);
1074
+ } else {
1075
+ console.log("[ImagePipeline] Captioner initialized to null, skipping caption generation.");
1071
1076
  }
1072
- console.log("[ImagePipeline] Extracted caption text:", extractedText);
1073
1077
  } catch (err) {
1074
1078
  console.warn("[ImagePipeline] Background captioning failed for image:", err);
1075
1079
  }
1076
1080
  } else {
1077
- console.log("[ImagePipeline] Captioner ref is null, skipping caption generation.");
1081
+ console.log("[ImagePipeline] Captioner promise ref is null, skipping caption generation.");
1078
1082
  }
1079
1083
  onImageAdd?.({ id, dataUrl, file, name: file.name, extractedText });
1080
1084
  }
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-AUJSSEB5.js";
29
+ } from "./chunk-YGT6L4HX.js";
30
30
  export {
31
31
  Chat,
32
32
  ChatInput,
@@ -9,7 +9,7 @@ import {
9
9
  useCompletion,
10
10
  useLLM,
11
11
  useStream
12
- } from "../chunk-AUJSSEB5.js";
12
+ } from "../chunk-YGT6L4HX.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.15",
3
+ "version": "0.4.16",
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",