newtw
This commit is contained in:
@@ -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
|
||||
|
||||
# --- 客户相关 (异步化) ---
|
||||
|
||||
Reference in New Issue
Block a user