@blank-utils/llm 0.4.15 → 0.4.17
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
|
|
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
|
-
|
|
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 (
|
|
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
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
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
|
}
|
|
@@ -1615,7 +1619,15 @@ ${systemPrompt}` : systemPrompt;
|
|
|
1615
1619
|
mermaid: mermaidOptions,
|
|
1616
1620
|
controls: streamdownControls,
|
|
1617
1621
|
parseMarkdownIntoBlocksFn: sanitizeMarkdownLanguageBlocks,
|
|
1618
|
-
children:
|
|
1622
|
+
children: [
|
|
1623
|
+
{ match: "\u{1F4C4} PDF:", index: msg.content.indexOf("\u{1F4C4} PDF:") },
|
|
1624
|
+
{ match: "\u{1F4C4} SVG Source Code", index: msg.content.indexOf("\u{1F4C4} SVG Source Code") },
|
|
1625
|
+
{ match: "\u{1F5BC}\uFE0F Image Auto-Caption", index: msg.content.indexOf("\u{1F5BC}\uFE0F Image Auto-Caption") }
|
|
1626
|
+
].filter((m) => m.index !== -1).reduce((min, m) => m.index < min ? m.index : min, msg.content.length) !== msg.content.length ? msg.content.substring(0, [
|
|
1627
|
+
{ match: "\u{1F4C4} PDF:", index: msg.content.indexOf("\u{1F4C4} PDF:") },
|
|
1628
|
+
{ match: "\u{1F4C4} SVG Source Code", index: msg.content.indexOf("\u{1F4C4} SVG Source Code") },
|
|
1629
|
+
{ match: "\u{1F5BC}\uFE0F Image Auto-Caption", index: msg.content.indexOf("\u{1F5BC}\uFE0F Image Auto-Caption") }
|
|
1630
|
+
].filter((m) => m.index !== -1).reduce((min, m) => m.index < min ? m.index : min, msg.content.length)).trim() : msg.content
|
|
1619
1631
|
}
|
|
1620
1632
|
) })
|
|
1621
1633
|
] }) : /* @__PURE__ */ jsxs3("div", { className: "prose prose-base dark:prose-invert max-w-none py-2 w-full min-w-0 font-mono bg-transparent mt-2 !text-current", children: [
|
package/dist/index.js
CHANGED
package/dist/react/index.js
CHANGED
package/package.json
CHANGED