mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 21:49:19 +08:00
feat: 拼多多发布页接入场景智能体与表单改写工具
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""发布场景前端工具:读快照用请求体注入;写工具由 streamer 推 client_tool 事件。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
|
||||
from langchain_core.tools import StructuredTool
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class _EmptyArgs(BaseModel):
|
||||
pass
|
||||
|
||||
|
||||
class SetGoodsNameArgs(BaseModel):
|
||||
goodsName: str = Field(description="商品标题,建议 60 字内")
|
||||
|
||||
|
||||
class SetGoodsDescArgs(BaseModel):
|
||||
goodsDesc: str = Field(description="商品描述纯文本")
|
||||
|
||||
|
||||
class SpecAxis(BaseModel):
|
||||
name: str = Field(description="规格维名称,如 颜色、尺码")
|
||||
values: list[str] = Field(description="该维下的规格值列表")
|
||||
|
||||
|
||||
class SetSpecAxesArgs(BaseModel):
|
||||
axes: list[SpecAxis] = Field(
|
||||
description="完整规格轴;将替换表单现有规格轴并重建 SKU 行"
|
||||
)
|
||||
|
||||
|
||||
def build_publish_client_tools(
|
||||
*,
|
||||
form_snapshot: dict[str, Any] | None,
|
||||
) -> list[Any]:
|
||||
def get_snapshot() -> str:
|
||||
return json.dumps(form_snapshot or {}, ensure_ascii=False, default=str)
|
||||
|
||||
def set_goods_name(goodsName: str) -> str:
|
||||
return f"已请求写入标题:{goodsName}"
|
||||
|
||||
def set_goods_desc(goodsDesc: str) -> str:
|
||||
return "已请求写入商品描述"
|
||||
|
||||
def set_spec_axes(axes: list[Any]) -> str:
|
||||
n = len(axes or [])
|
||||
return f"已请求写入 {n} 个规格维,页面将重建 SKU 行"
|
||||
|
||||
return [
|
||||
StructuredTool.from_function(
|
||||
func=get_snapshot,
|
||||
name="ui_get_publish_snapshot",
|
||||
description="读取当前发布表单快照:标题、描述、类目、规格轴、SKU 行(含商家编码)等。改表前应先调用。",
|
||||
args_schema=_EmptyArgs,
|
||||
),
|
||||
StructuredTool.from_function(
|
||||
func=set_goods_name,
|
||||
name="ui_set_goods_name",
|
||||
description="写入商品标题到发布表单。",
|
||||
args_schema=SetGoodsNameArgs,
|
||||
),
|
||||
StructuredTool.from_function(
|
||||
func=set_goods_desc,
|
||||
name="ui_set_goods_desc",
|
||||
description="写入商品描述到发布表单。",
|
||||
args_schema=SetGoodsDescArgs,
|
||||
),
|
||||
StructuredTool.from_function(
|
||||
func=set_spec_axes,
|
||||
name="ui_set_spec_axes",
|
||||
description="设置规格轴(维名+值列表)。页面会按笛卡尔积重建 SKU 行。",
|
||||
args_schema=SetSpecAxesArgs,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
def is_client_tool_name(name: str) -> bool:
|
||||
return (name or "").startswith("ui_")
|
||||
Reference in New Issue
Block a user