refactor: split websocket flows and add brain action decision pipeline

This commit is contained in:
2026-03-02 16:04:33 +08:00
parent 4022ed8f7a
commit b5153048c4
22 changed files with 2325 additions and 2426 deletions

View File

@@ -0,0 +1,23 @@
async def save_conversation_summary_flow(client, customer_id: str, buyer_msg: str, agent_reply: str):
"""用 AI 生成一句话对话摘要并持久化。"""
try:
from db.customer_db import db
from openai import AsyncOpenAI
api_client = AsyncOpenAI(
api_key=client.agent.api_key if client.agent else None,
base_url=client.agent.base_url if client.agent else None,
)
resp = await api_client.chat.completions.create(
model=client.agent.model_name if client.agent else "gpt-4o-mini",
messages=[
{"role": "system", "content": "用一句话15字以内总结这段对话的核心内容只输出摘要文字。"},
{"role": "user", "content": f"买家:{buyer_msg}\n客服:{agent_reply}"},
],
max_tokens=30,
temperature=0.3,
)
summary = resp.choices[0].message.content.strip()
db.save_conversation_summary(customer_id, summary)
except Exception:
client.logger.debug("保存对话摘要失败(不影响主流程)", exc_info=True)