mirror of
https://gitee.com/wanwujie/deer-flow
synced 2026-04-03 06:12:14 +08:00
append messages to chat_streams table (#816)
* feat: Implement DeerFlow API server with chat streaming, Langgraph orchestration, and various content generation capabilities. * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * - Use MongoDB `$push` with `$each` to append new messages to existing threads - Use PostgreSQL jsonb concatenation operator to merge messages instead of overwriting - Update comments to reflect append behavior in both database implementations --------- Co-authored-by: Willem Jiang <willem.jiang@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -248,10 +248,13 @@ class ChatStreamManager:
|
||||
current_timestamp = datetime.now()
|
||||
|
||||
if existing_document:
|
||||
# Update existing conversation with new messages
|
||||
# Append new messages to existing conversation
|
||||
update_result = collection.update_one(
|
||||
{"thread_id": thread_id},
|
||||
{"$set": {"messages": messages, "ts": current_timestamp}},
|
||||
{
|
||||
"$push": {"messages": {"$each": messages}},
|
||||
"$set": {"ts": current_timestamp}
|
||||
},
|
||||
)
|
||||
self.logger.info(
|
||||
f"Updated conversation for thread {thread_id}: "
|
||||
@@ -290,11 +293,11 @@ class ChatStreamManager:
|
||||
messages_json = json.dumps(messages)
|
||||
|
||||
if existing_record:
|
||||
# Update existing conversation with new messages
|
||||
# Append new messages to existing conversation
|
||||
cursor.execute(
|
||||
"""
|
||||
UPDATE chat_streams
|
||||
SET messages = %s, ts = %s
|
||||
UPDATE chat_streams
|
||||
SET messages = messages || %s::jsonb, ts = %s
|
||||
WHERE thread_id = %s
|
||||
""",
|
||||
(messages_json, current_timestamp, thread_id),
|
||||
|
||||
Reference in New Issue
Block a user