file download working
This commit is contained in:
parent
41a0bc0588
commit
56d97e7c7f
3 changed files with 55 additions and 38 deletions
|
|
@ -49,20 +49,24 @@ export default function ChatMessage({ chat }: { chat: ChatMessageType }) {
|
||||||
)}
|
)}
|
||||||
{chat.thought && chat.thought !== "" && !hidden && <br></br>}
|
{chat.thought && chat.thought !== "" && !hidden && <br></br>}
|
||||||
<div className="w-full px-4 pb-3 pt-3 pr-8">
|
<div className="w-full px-4 pb-3 pt-3 pr-8">
|
||||||
{chat.files ? (
|
|
||||||
<div></div>
|
|
||||||
) : (
|
|
||||||
<span>
|
<span>
|
||||||
{chat.message}
|
{chat.message}
|
||||||
|
{chat.files && (
|
||||||
|
<div className="my-2 w-full">
|
||||||
|
{chat.files.map((file) => {
|
||||||
|
return (
|
||||||
<div className="my-2 w-full">
|
<div className="my-2 w-full">
|
||||||
<FileCard
|
<FileCard
|
||||||
fileName={"FileType"}
|
fileName={"File"}
|
||||||
fileType={"jpeg"}
|
fileType={file.type}
|
||||||
content={""}
|
content={file.data}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,13 @@ export default function ChatModal({
|
||||||
message: string,
|
message: string,
|
||||||
isSend: boolean,
|
isSend: boolean,
|
||||||
thought?: string,
|
thought?: string,
|
||||||
file?:Blob
|
files?: Array<any>
|
||||||
) => {
|
) => {
|
||||||
setChatHistory((old) => {
|
setChatHistory((old) => {
|
||||||
let newChat = _.cloneDeep(old);
|
let newChat = _.cloneDeep(old);
|
||||||
if(file){
|
if (files) {
|
||||||
newChat.push({ message, isSend,file });
|
newChat.push({ message, isSend, files });
|
||||||
}
|
} else if (thought) {
|
||||||
else if (thought) {
|
|
||||||
newChat.push({ message, isSend, thought });
|
newChat.push({ message, isSend, thought });
|
||||||
} else {
|
} else {
|
||||||
newChat.push({ message, isSend });
|
newChat.push({ message, isSend });
|
||||||
|
|
@ -71,35 +70,51 @@ export default function ChatModal({
|
||||||
is_bot: boolean;
|
is_bot: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
type: string;
|
type: string;
|
||||||
data?:string;
|
files?: Array<any>;
|
||||||
}) => {
|
}) => {
|
||||||
if(chatItem.type==="end"){
|
if (chatItem.message) {
|
||||||
newChatHistory.push({
|
newChatHistory.push(
|
||||||
|
chatItem.files
|
||||||
|
? {
|
||||||
isSend: !chatItem.is_bot,
|
isSend: !chatItem.is_bot,
|
||||||
message: chatItem.message,
|
message: chatItem.message,
|
||||||
thought: chatItem.intermediate_steps,
|
thought: chatItem.intermediate_steps,
|
||||||
});
|
files: chatItem.files,
|
||||||
}
|
}
|
||||||
newChatHistory.push({
|
: {
|
||||||
isSend: !chatItem.is_bot,
|
isSend: !chatItem.is_bot,
|
||||||
message: chatItem.message,
|
message: chatItem.message,
|
||||||
thought: chatItem.intermediate_steps,
|
thought: chatItem.intermediate_steps,
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return newChatHistory;
|
return newChatHistory;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (data.type === "end") {
|
if (data.type === "end") {
|
||||||
|
if (data.files) {
|
||||||
|
addChatHistory(
|
||||||
|
data.message,
|
||||||
|
false,
|
||||||
|
data.intermediate_steps,
|
||||||
|
data.files
|
||||||
|
);
|
||||||
|
} else {
|
||||||
addChatHistory(data.message, false, data.intermediate_steps);
|
addChatHistory(data.message, false, data.intermediate_steps);
|
||||||
setLockChat(false)
|
|
||||||
}
|
}
|
||||||
if (data.type=="file"){
|
setLockChat(false);
|
||||||
console.log(data)
|
}
|
||||||
|
if (data.type == "file") {
|
||||||
|
console.log(data);
|
||||||
}
|
}
|
||||||
// Do something with the data received from the WebSocket
|
// Do something with the data received from the WebSocket
|
||||||
};
|
};
|
||||||
newWs.onclose=(e)=>{console.log(e.reason);setLockChat(false)}
|
newWs.onclose = (e) => {
|
||||||
|
console.log(e.code);
|
||||||
|
setLockChat(false);
|
||||||
|
};
|
||||||
setWs(newWs);
|
setWs(newWs);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
|
@ -107,7 +122,6 @@ export default function ChatModal({
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
async function sendAll(data: sendAllProps) {
|
async function sendAll(data: sendAllProps) {
|
||||||
if (ws) {
|
if (ws) {
|
||||||
ws.send(JSON.stringify(data));
|
ws.send(JSON.stringify(data));
|
||||||
|
|
@ -211,8 +225,7 @@ export default function ChatModal({
|
||||||
}
|
}
|
||||||
function clearChat() {
|
function clearChat() {
|
||||||
setChatHistory([]);
|
setChatHistory([]);
|
||||||
ws.send(JSON.stringify({clear_history:true}))
|
ws.send(JSON.stringify({ clear_history: true }));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const { closePopUp } = useContext(PopUpContext);
|
const { closePopUp } = useContext(PopUpContext);
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,5 @@ export type ChatMessageType = {
|
||||||
message: string;
|
message: string;
|
||||||
isSend: boolean;
|
isSend: boolean;
|
||||||
thought?: string;
|
thought?: string;
|
||||||
files?: Array<{content:string,type:string}>;
|
files?: Array<{data:string,type:string}>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue