diff --git a/src/chatbox.tsx b/src/chatbox.tsx index 63b8469..117e007 100644 --- a/src/chatbox.tsx +++ b/src/chatbox.tsx @@ -34,6 +34,8 @@ export default function ChatBOX(props: { // prevent error if (chatStore === undefined) return
; const [inputMsg, setInputMsg] = useState(""); + const [images, setImages] = useState([]); + const [showAddImage, setShowAddImage] = useState(false); const [showGenerating, setShowGenerating] = useState(false); const [generatingMessage, setGeneratingMessage] = useState(""); const [showRetry, setShowRetry] = useState(false); @@ -216,26 +218,38 @@ export default function ChatBOX(props: { }; // when user click the "send" button or ctrl+Enter in the textarea - const send = async (msg = "") => { + const send = async (msg = "", call_complete = true) => { const inputMsg = msg.trim(); if (!inputMsg) { console.log("empty message"); return; } - chatStore.responseModelName = ""; + if (call_complete) chatStore.responseModelName = ""; + + let content: string | MessageDetail[] = inputMsg; + if (images.length > 0) { + content = images; + } + if (inputMsg.trim()) { + content = [{ type: "text", text: inputMsg }, ...images]; + } chatStore.history.push({ role: "user", - content: inputMsg.trim(), + content, hide: false, token: calculate_token_length(inputMsg.trim()), example: false, }); + // manually calculate token length chatStore.totalTokens += client.calculate_token_length(inputMsg.trim()); client.total_tokens += client.calculate_token_length(inputMsg.trim()); setChatStore({ ...chatStore }); setInputMsg(""); - await complete(); + setImages([]); + if (call_complete) { + await complete(); + } }; const [showSettings, setShowSettings] = useState(false); @@ -261,7 +275,6 @@ export default function ChatBOX(props: { ); _setTemplateAPIs(templateAPIs); }; - const [images, setImages] = useState([]); return (
@@ -587,7 +600,130 @@ export default function ChatBOX(props: { )}
+ {images.length > 0 && ( +
+ {images.map((image, index) => ( +
+ {image.type === "image_url" && ( + + )} +
+ ))} +
+ )} +
+ + {showAddImage && ( +
{ + setShowAddImage(false); + }} + > +
{ + event.stopPropagation(); + }} + > +

Add Images

+ + + + +
+ {images.map((image, index) => ( +
+ {image.type === "image_url" && ( + + )} + + + + +
+ ))} +
+
+
+ )} + ) : ( +
event.stopPropagation()} + > + {chat.content.map((mdt, index) => ( +
+
+ {mdt.type === "text" ? ( + + ) : ( + <> + { + window.open(mdt.image_url, "_blank"); + }} + /> + + + + )} + + +
+
+ ))} + + +
)}