feat:优化意图识别

This commit is contained in:
2026-09-30 21:31:20 -07:00
parent 1b727cde42
commit 8e37d30ef2
7 changed files with 138 additions and 52 deletions
+9 -3
View File
@@ -1,7 +1,11 @@
"""需求操作名词表的单一来源,需求协议、提示词、能力检查和范围校验都引用这里"""
# 模型可能使用的同义操作名,统一成词表中的标准名称;新增别名只改这里
OPERATION_ALIASES: dict[str, str] = {"restyle": "update"}
OPERATION_ALIASES: dict[str, str] = {
"restyle": "update",
"change_type": "replace",
"convert": "replace",
}
# 直接修改已有组件支持的操作,每一项都要有对应的动作规则
NODE_OPERATIONS: tuple[str, ...] = ("move", "resize", "update", "delete")
@@ -18,13 +22,15 @@ PLAN_ADJUST_OPERATIONS: tuple[str, ...] = (
"layout",
)
# 只能通过规划完成的操作:新增要从物料目录选型并安排位置,重排要整体布局
PLAN_ONLY_OPERATIONS: tuple[str, ...] = ("add", "reflow", "layout")
# 只能通过规划完成的操作:新增要从物料目录选型并安排位置,重排要整体布局,
# 更换组件类型实际是换成另一种物料,要从目录选型,不能靠修改属性完成
PLAN_ONLY_OPERATIONS: tuple[str, ...] = ("add", "reflow", "layout", "replace")
# 写进协议描述和提示词的操作说明,词表变化时自动同步
OPERATION_GUIDE = (
f"修改已有组件用 {'、'.join(NODE_OPERATIONS)},"
"修改画布用 update 或 resize,新增用 add;"
"更换已有组件的类型(如折线图改饼图)用 replace,目标类型写入 parameters,不用 update;"
"颜色、背景、文字等样式和属性修改统一用 update,具体内容写入 parameters"
)
+6 -3
View File
@@ -24,8 +24,9 @@ class PlanComponent(ExtensibleModel):
plan_id: NonBlankString = Field(
description="规划内的组件编号,用于关联资源,不作为新增组件的实际 ID"
)
disposition: Literal["keep", "modify", "add", "remove"] = Field(
description="保留、调整、新增或移除,只表达规划意图,不代表执行能力已经支持"
disposition: Literal["keep", "modify", "add", "remove", "replace"] = Field(
description="保留、调整、新增、移除或更换类型,只表达规划意图,不代表执行能力已经支持;"
"replace 表示把 target_id 换成 component_type 对应的物料,保留原位置"
)
target_id: NonBlankString | None = Field(
default=None, description="已有组件 ID,新增时必须为空"
@@ -53,7 +54,9 @@ class PlanComponent(ExtensibleModel):
if self.target_id is not None:
raise ValueError("新增组件不能指定已有 target_id")
elif self.target_id is None:
raise ValueError("保留、调整或移除组件必须提供 target_id")
raise ValueError("保留、调整、移除或更换组件必须提供 target_id")
if self.disposition == "replace" and self.component_type is None:
raise ValueError("更换组件必须指定新的 component_type")
return self