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:
parent
18c7c60c52
commit
3eaeec5249
|
|
@ -248,10 +248,13 @@ class ChatStreamManager:
|
||||||
current_timestamp = datetime.now()
|
current_timestamp = datetime.now()
|
||||||
|
|
||||||
if existing_document:
|
if existing_document:
|
||||||
# Update existing conversation with new messages
|
# Append new messages to existing conversation
|
||||||
update_result = collection.update_one(
|
update_result = collection.update_one(
|
||||||
{"thread_id": thread_id},
|
{"thread_id": thread_id},
|
||||||
{"$set": {"messages": messages, "ts": current_timestamp}},
|
{
|
||||||
|
"$push": {"messages": {"$each": messages}},
|
||||||
|
"$set": {"ts": current_timestamp}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
self.logger.info(
|
self.logger.info(
|
||||||
f"Updated conversation for thread {thread_id}: "
|
f"Updated conversation for thread {thread_id}: "
|
||||||
|
|
@ -290,11 +293,11 @@ class ChatStreamManager:
|
||||||
messages_json = json.dumps(messages)
|
messages_json = json.dumps(messages)
|
||||||
|
|
||||||
if existing_record:
|
if existing_record:
|
||||||
# Update existing conversation with new messages
|
# Append new messages to existing conversation
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE chat_streams
|
UPDATE chat_streams
|
||||||
SET messages = %s, ts = %s
|
SET messages = messages || %s::jsonb, ts = %s
|
||||||
WHERE thread_id = %s
|
WHERE thread_id = %s
|
||||||
""",
|
""",
|
||||||
(messages_json, current_timestamp, thread_id),
|
(messages_json, current_timestamp, thread_id),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue