mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 11:09:19 +08:00
feat: 拼多多发布页接入场景智能体与表单改写工具
This commit is contained in:
@@ -18,6 +18,8 @@ router = APIRouter(prefix="/sessions", tags=["chat"])
|
||||
|
||||
class ChatBody(BaseModel):
|
||||
content: str = Field(min_length=1, max_length=20000)
|
||||
# 发布场景:当前表单快照,供 ui_get_publish_snapshot
|
||||
formSnapshot: dict | None = None
|
||||
|
||||
|
||||
@router.get("/{thread_id}/messages")
|
||||
@@ -57,7 +59,12 @@ async def chat_stream(
|
||||
|
||||
async def gen():
|
||||
try:
|
||||
async for event in svc.stream_chat(actor, thread_id, body.content):
|
||||
async for event in svc.stream_chat(
|
||||
actor,
|
||||
thread_id,
|
||||
body.content,
|
||||
form_snapshot=body.formSnapshot,
|
||||
):
|
||||
if event.kind == "token" and event.text:
|
||||
yield {
|
||||
"event": "token",
|
||||
@@ -75,6 +82,19 @@ async def chat_stream(
|
||||
ensure_ascii=False,
|
||||
),
|
||||
}
|
||||
elif event.kind == "client_tool":
|
||||
yield {
|
||||
"event": "client_tool",
|
||||
"data": json.dumps(
|
||||
{
|
||||
"toolCallId": event.tool_call_id,
|
||||
"name": event.name,
|
||||
"args": event.args or {},
|
||||
"label": event.label,
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
}
|
||||
yield {"event": "done", "data": "{}"}
|
||||
except LookupError as e:
|
||||
yield {"event": "error", "data": json.dumps({"message": str(e)}, ensure_ascii=False)}
|
||||
|
||||
Reference in New Issue
Block a user