is_ai is set to true if sender is null

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-20 23:11:18 -03:00
commit 9adb4b97d4

View file

@ -30,7 +30,7 @@ export default function newChatView(): JSX.Element {
getFlow, getFlow,
CleanFlowPool, CleanFlowPool,
} = useFlowStore(); } = useFlowStore();
const { setErrorData,setNoticeData } = useAlertStore(); const { setErrorData, setNoticeData } = useAlertStore();
const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId); const currentFlowId = useFlowsManagerStore((state) => state.currentFlowId);
const [lockChat, setLockChat] = useState(false); const [lockChat, setLockChat] = useState(false);
const messagesRef = useRef<HTMLDivElement | null>(null); const messagesRef = useRef<HTMLDivElement | null>(null);
@ -41,11 +41,10 @@ export default function newChatView(): JSX.Element {
const outputTypes = outputs.map((obj) => obj.type); const outputTypes = outputs.map((obj) => obj.type);
useEffect(() => { useEffect(() => {
if(!outputTypes.includes("ChatOutput")) if (!outputTypes.includes("ChatOutput")) {
{ setNoticeData({ title: "There is no ChatOutput node in the flow." });
setNoticeData({title:"There is no ChatOutput node in the flow."})
} }
},[]); }, []);
//build chat history //build chat history
useEffect(() => { useEffect(() => {
@ -68,15 +67,19 @@ export default function newChatView(): JSX.Element {
.sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp)) .sort((a, b) => Date.parse(a.timestamp) - Date.parse(b.timestamp))
.filter((output) => !!output.data.artifacts?.message) .filter((output) => !!output.data.artifacts?.message)
.map((output) => { .map((output) => {
try{ try {
const { sender, message, sender_name } = output.data const { sender, message, sender_name } = output.data
.artifacts as ChatOutputType; .artifacts as ChatOutputType;
const is_ai = sender === "Machine";
return { isSend: !is_ai, message: message, sender_name }; const is_ai = sender === "Machine" || sender === null;
} return { isSend: !is_ai, message: message, sender_name };
catch(e){ } catch (e) {
console.error(e); console.error(e);
return { isSend: false, message: "Error parsing message", sender_name: "Error" }; return {
isSend: false,
message: "Error parsing message",
sender_name: "Error",
};
} }
}); });
setChatHistory(chatMessages); setChatHistory(chatMessages);