mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 07:49:19 +08:00
feat: 拼多多发布页接入场景智能体与表单改写工具
This commit is contained in:
@@ -45,13 +45,19 @@ class ChatService:
|
||||
)
|
||||
|
||||
async def stream_chat(
|
||||
self, actor: Actor, thread_id: str, content: str
|
||||
self,
|
||||
actor: Actor,
|
||||
thread_id: str,
|
||||
content: str,
|
||||
*,
|
||||
form_snapshot: dict | None = None,
|
||||
) -> AsyncIterator[StreamEvent]:
|
||||
text = (content or "").strip()
|
||||
if not text:
|
||||
raise ValueError("消息不能为空")
|
||||
|
||||
session = await self._sessions.require_owned(actor, thread_id)
|
||||
scene = session.scene or "general"
|
||||
llm = await self._llm_runtime.resolve_runtime(
|
||||
actor.company_id,
|
||||
provider_id=session.llm_provider_id,
|
||||
@@ -67,18 +73,33 @@ class ChatService:
|
||||
changed = True
|
||||
if changed:
|
||||
await self._session_repo.update(session)
|
||||
just_saved = await self._memory.maybe_capture_from_user(
|
||||
actor, thread_id=thread_id, text=text
|
||||
)
|
||||
memory_count = await self._memory.count_active(actor)
|
||||
|
||||
just_saved = None
|
||||
memory_count = 0
|
||||
if scene == "general":
|
||||
just_saved = await self._memory.maybe_capture_from_user(
|
||||
actor, thread_id=thread_id, text=text
|
||||
)
|
||||
memory_count = await self._memory.count_active(actor)
|
||||
|
||||
system_prompt = build_system_prompt(
|
||||
memory_count=memory_count,
|
||||
memory_just_saved=just_saved,
|
||||
scene=scene,
|
||||
)
|
||||
|
||||
client_tools = None
|
||||
if scene == "ecom_goods_publish":
|
||||
from agent.tools.publish_ui import build_publish_client_tools
|
||||
|
||||
client_tools = build_publish_client_tools(form_snapshot=form_snapshot)
|
||||
|
||||
tools = await load_tools_for_turn(
|
||||
self._settings,
|
||||
actor=actor,
|
||||
memory=self._memory,
|
||||
scene=scene,
|
||||
client_tools=client_tools,
|
||||
)
|
||||
|
||||
raw_history = await self._messages.list_recent(
|
||||
|
||||
@@ -25,6 +25,9 @@ class SessionService:
|
||||
title: str | None = None,
|
||||
llm_provider_id: int | None = None,
|
||||
llm_model: str | None = None,
|
||||
*,
|
||||
scene: str | None = None,
|
||||
scene_ref: str | None = None,
|
||||
) -> Session:
|
||||
now = datetime.utcnow()
|
||||
model = (llm_model or "").strip() or None
|
||||
@@ -40,12 +43,16 @@ class SessionService:
|
||||
provider_id = rt.provider_id if rt.provider_id is not None else provider_id
|
||||
except Exception:
|
||||
pass
|
||||
scene_value = (scene or "general").strip() or "general"
|
||||
ref = (scene_ref or "").strip() or None
|
||||
session = Session(
|
||||
thread_id=str(uuid.uuid4()),
|
||||
company_id=actor.company_id,
|
||||
user_id=actor.user_id,
|
||||
title=(title or "新对话").strip() or "新对话",
|
||||
status=SessionStatus.ACTIVE,
|
||||
scene=scene_value,
|
||||
scene_ref=ref,
|
||||
llm_provider_id=provider_id,
|
||||
llm_model=model,
|
||||
created_at=now,
|
||||
@@ -53,8 +60,23 @@ class SessionService:
|
||||
)
|
||||
return await self._sessions.create(session)
|
||||
|
||||
async def list_mine(self, actor: Actor) -> list[Session]:
|
||||
return await self._sessions.list_active(actor.company_id, actor.user_id)
|
||||
async def list_mine(
|
||||
self, actor: Actor, *, scene: str | None = None
|
||||
) -> list[Session]:
|
||||
return await self._sessions.list_active(
|
||||
actor.company_id, actor.user_id, scene=scene
|
||||
)
|
||||
|
||||
async def find_by_scene_ref(
|
||||
self, actor: Actor, *, scene: str, scene_ref: str
|
||||
) -> Session | None:
|
||||
"""同一 scene_ref 复用已有活跃会话(一草稿一会话)。"""
|
||||
return await self._sessions.find_active_by_scene_ref(
|
||||
actor.company_id,
|
||||
actor.user_id,
|
||||
scene=scene,
|
||||
scene_ref=scene_ref,
|
||||
)
|
||||
|
||||
async def require_owned(self, actor: Actor, thread_id: str) -> Session:
|
||||
session = await self._sessions.get(actor.company_id, actor.user_id, thread_id)
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from domain.models import SCENE_ECOM_GOODS_PUBLISH, SCENE_GENERAL
|
||||
|
||||
_BASE_SYSTEM = (
|
||||
"你是电商 DMB 系统的经营助手。回答简洁、可执行、结论先行。"
|
||||
"需要经营数据时优先调用可用工具。"
|
||||
@@ -24,12 +26,31 @@ _BASE_SYSTEM = (
|
||||
"若工具失败或无权限,请说明原因并给出可操作建议。"
|
||||
)
|
||||
|
||||
_PUBLISH_SYSTEM = (
|
||||
"你是电商 DMB 的拼多多商品发布助手,帮助用户在系统草稿里完善标题、规格轴、属性与价格等。"
|
||||
"当前表单在浏览器里;改表单必须调用 ui_ 开头的前端工具,不要只口头说已修改。"
|
||||
"查内部商品/SKU:catalog_search、catalog_sku_detail(按 skuCode)。"
|
||||
"查已同步的拼多多渠道商品:pdd_goods_search、pdd_goods_detail(只查本地库)。"
|
||||
"常见流程:根据表单已有 SKU 编码 → catalog_sku_detail / pdd_goods_search → "
|
||||
"挑选或按用户指定模仿某条渠道商品 → 生成标题并用 ui_set_goods_name 写入;"
|
||||
"规格只通过 ui_set_spec_axes 写规格轴,页面会自动笛卡尔积重建 SKU 行。"
|
||||
"用户未指定时,可自行选择最接近的渠道商品模仿,或结合内部商品信息自由发挥;"
|
||||
"用户指定风格或指定模仿哪条时以用户为准。"
|
||||
"一期不要处理图片上传或改图。"
|
||||
"禁止向用户索要或复述数字 ID;多条命中时用名称/编码说明。"
|
||||
"回答简洁;工具失败时说明原因与可操作建议。"
|
||||
)
|
||||
|
||||
|
||||
def build_system_prompt(
|
||||
*,
|
||||
memory_count: int = 0,
|
||||
memory_just_saved: str | None = None,
|
||||
scene: str = SCENE_GENERAL,
|
||||
) -> str:
|
||||
if (scene or SCENE_GENERAL).strip() == SCENE_ECOM_GOODS_PUBLISH:
|
||||
return _PUBLISH_SYSTEM
|
||||
|
||||
system = _BASE_SYSTEM
|
||||
if memory_count > 0:
|
||||
system += (
|
||||
|
||||
Reference in New Issue
Block a user