diff --git a/splicing/backend/app/api/endpoints/converse.py b/splicing/backend/app/api/endpoints/converse.py index 41f93c2..9fbcd74 100644 --- a/splicing/backend/app/api/endpoints/converse.py +++ b/splicing/backend/app/api/endpoints/converse.py @@ -165,8 +165,11 @@ async def event_generator(): if chunk: yield json.dumps(chunk) + CHUNK_DELIMITER - snapshot = await graph.aget_state(config) - logger.debug("CONVERSE - response: %s", snapshot.values["messages"][-1]) + # get the new snapshot + snapshot = await graph.aget_state(config) + response = snapshot.values["messages"][-1] + + logger.debug("CONVERSE - response: %s", response) return StreamingResponse(event_generator(), media_type="application/x-ndjson") diff --git a/splicing/frontend/app/project/[id]/page.tsx b/splicing/frontend/app/project/[id]/page.tsx index c578689..f09cdab 100644 --- a/splicing/frontend/app/project/[id]/page.tsx +++ b/splicing/frontend/app/project/[id]/page.tsx @@ -47,7 +47,7 @@ export default function ProjectPage({ params }: { params: { id: string } }) {
-
+
diff --git a/splicing/frontend/components/chat/chat-bottom-bar.tsx b/splicing/frontend/components/chat/chat-bottom-bar.tsx index 8919e03..1218aaa 100644 --- a/splicing/frontend/components/chat/chat-bottom-bar.tsx +++ b/splicing/frontend/components/chat/chat-bottom-bar.tsx @@ -7,6 +7,7 @@ import useProjectStore from "@/store/project"; const ChatBottomBar = () => { const [message, setMessage] = useState(""); + const [isStreamingMessage, setIsStreamingMessage] = useState(false); const [addMessage, loadingMessage] = useProjectStore((state) => [ state.addMessage, state.loadingMessage, @@ -18,13 +19,18 @@ const ChatBottomBar = () => { }; const handleSend = async () => { - if (message.trim()) { + if (message.trim() && !isStreamingMessage) { const newMessage = { role: "user", content: message.trim(), }; setMessage(""); - await addMessage(newMessage); + setIsStreamingMessage(true); + try { + await addMessage(newMessage); + } finally { + setIsStreamingMessage(false); + } if (inputRef.current) { inputRef.current.focus(); @@ -92,7 +98,8 @@ const ChatBottomBar = () => { - - Reset - - -
- -
-
+
+
+
+

+ Assistant +

+ + + + + + Reset + + +
+ +
+ +
+
{messages?.map( (message, index) => @@ -164,7 +164,8 @@ const Chat = () => {
-
+ +
diff --git a/splicing/frontend/store/project.ts b/splicing/frontend/store/project.ts index 8ddeee7..a5665a5 100644 --- a/splicing/frontend/store/project.ts +++ b/splicing/frontend/store/project.ts @@ -313,12 +313,12 @@ const useProjectStore = create((set, get) => ({ responseMessage.content = chunk.data; } set((state) => ({ - messages: [...state.messages.slice(0, -1), responseMessage!] + messages: [...state.messages.slice(0, -1), { ...responseMessage! }] })); } } else if (chunk.type === 'generate-result') { const currentSection = get().getCurrentSection(); - if (currentSection && currentSection.currentBlockId) { + if (currentSection?.currentBlockId) { const updatedBlocks = currentSection.blocks.map((block) => block.id === currentSection.currentBlockId ? { ...block, generateResult: JSON.parse(chunk.data) } : block );