@blank-utils/llm 0.4.14 → 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,24 +915,27 @@ 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 {
924
+ console.log("[ImagePipeline] Initializing Transformers.js background captioner...");
923
925
  const { pipeline: pipeline2, env } = await import("@huggingface/transformers");
924
926
  env.allowLocalModels = false;
925
927
  env.useBrowserCache = true;
926
928
  const captioner = await pipeline2("image-to-text", "Xenova/vit-gpt2-image-captioning", {
927
- device: "wasm",
928
- dtype: "q8"
929
+ device: "wasm"
929
930
  });
930
- if (mounted) captionerRef.current = captioner;
931
+ if (mounted) console.log("[ImagePipeline] Captioner loaded successfully!");
932
+ return captioner;
931
933
  } catch (err) {
932
934
  console.warn("Failed to initialize background captioner:", err);
935
+ return null;
933
936
  }
934
937
  };
935
- initCaptioner();
938
+ captionerPromiseRef.current = initCaptioner();
936
939
  return () => {
937
940
  mounted = false;
938
941
  };
@@ -1055,17 +1058,27 @@ ${newText}` : newText);
1055
1058
  const id = Math.random().toString(36).substring(7);
1056
1059
  const dataUrl = e.target.result;
1057
1060
  let extractedText;
1058
- if (captionerRef.current) {
1061
+ if (captionerPromiseRef.current) {
1062
+ console.log(`[ImagePipeline] Generating caption for ${file.name} (Waiting for captioner)...`);
1059
1063
  try {
1060
- const out = await captionerRef.current(dataUrl);
1061
- if (Array.isArray(out) && out[0] && out[0].generated_text) {
1062
- extractedText = out[0].generated_text;
1063
- } else if (!Array.isArray(out) && out.generated_text) {
1064
- 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.");
1065
1076
  }
1066
1077
  } catch (err) {
1067
- console.warn("Background captioning failed for image:", err);
1078
+ console.warn("[ImagePipeline] Background captioning failed for image:", err);
1068
1079
  }
1080
+ } else {
1081
+ console.log("[ImagePipeline] Captioner promise ref is null, skipping caption generation.");
1069
1082
  }
1070
1083
  onImageAdd?.({ id, dataUrl, file, name: file.name, extractedText });
1071
1084
  }
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  useCompletion,
27
27
  useLLM,
28
28
  useStream
29
- } from "./chunk-L7XEQBE2.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-L7XEQBE2.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.14",
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",