This commit is contained in:
2026-03-06 12:44:57 +08:00
parent fa61b11b02
commit 006b035de4
132 changed files with 1361 additions and 17400 deletions

View File

@@ -18,24 +18,33 @@ class DataRepository:
# --- 聊天记录 (异步化) ---
async def save_chat(self, platform: str, user_id: str, content: str, direction: str, acc_id: str = ""):
async def save_chat(self, platform: str, user_id: str, content: str, direction: str, acc_id: str = "", image_urls: list = None):
"""异步持久化存储聊天记录"""
# 将图片URL列表转为\n分隔的字符串
urls_str = "\n".join(image_urls) if image_urls else ""
return await asyncio.to_thread(
log_message,
customer_id=user_id,
message=content,
direction=direction,
platform=platform,
acc_id=acc_id
acc_id=acc_id,
image_urls=urls_str
)
async def get_chat_history(self, user_id: str, limit: int = 10) -> List[dict]:
async def get_chat_history(self, user_id: str, limit: int = 10, acc_id: str = "") -> List[dict]:
"""异步获取历史记录"""
rows = await asyncio.to_thread(get_conversation, user_id, limit=limit)
rows = await asyncio.to_thread(get_conversation, user_id, limit=limit, acc_id=acc_id)
history = []
for r in rows:
role = "user" if r["direction"] == "in" else "assistant"
history.append({"role": role, "content": r["message"]})
history.append(
{
"role": role,
"content": r["message"],
"timestamp": r.get("timestamp", ""),
}
)
return history
# --- 客户相关 (异步化) ---