feat:接入mcp,为模型提供图表信息
This commit is contained in:
+48
-21
@@ -53,6 +53,46 @@ REPAIR_TASK_PROMPT = """# 当前阶段:修正重试
|
||||
"""
|
||||
|
||||
|
||||
FIELD_QUERY_PROMPT = """# 查询组件字段
|
||||
field_groups 按物料类型列出本次相关组件的字段分组,节点的 type 就是物料类型
|
||||
确定要改的字段:用用户原话中对属性的说法(input_context 中的提问,不用改写后的需求)调用 search_fields;
|
||||
返回多个字段时,依据字段说明判断用户指的是哪一个;用户看的是大屏画面,没有提到图层列表、属性面板等编辑器位置时,按画面上看得到的内容理解
|
||||
需要了解一组相关字段时用 get_fields,一次可查多个分组
|
||||
只能使用查询到的字段路径,值须符合字段的类型、可选值和取值范围;查不到对应字段说明不支持,不自行编造路径
|
||||
"""
|
||||
|
||||
# 这些动作会写组件属性,需要先查物料字段
|
||||
FIELD_ACTIONS = frozenset({"update", "add"})
|
||||
|
||||
|
||||
def action_types(requirement: Requirement, screen_plan: ScreenPlan | None) -> set[str]:
|
||||
"""本次需要的动作类型:简单修改按需求变更,规划按各组件的处理方式"""
|
||||
if screen_plan is None:
|
||||
return {
|
||||
"update_canvas" if change.target_scope == "canvas" else change.operation
|
||||
for change in requirement.changes
|
||||
}
|
||||
types = set()
|
||||
if screen_plan.canvas_changes:
|
||||
types.add("update_canvas")
|
||||
for item in screen_plan.components:
|
||||
if item.disposition in ("add", "replace"):
|
||||
types.add("add")
|
||||
elif item.disposition == "remove":
|
||||
types.add("delete")
|
||||
elif item.disposition == "modify":
|
||||
types.update(("move", "resize"))
|
||||
if item.design:
|
||||
types.add("update")
|
||||
return types
|
||||
|
||||
|
||||
def uses_material_fields(
|
||||
requirement: Requirement, screen_plan: ScreenPlan | None
|
||||
) -> bool:
|
||||
return bool(action_types(requirement, screen_plan) & FIELD_ACTIONS)
|
||||
|
||||
|
||||
def build_action_prompt(
|
||||
requirement: Requirement,
|
||||
screen_plan: ScreenPlan | None = None,
|
||||
@@ -60,40 +100,27 @@ def build_action_prompt(
|
||||
repairing: bool = False,
|
||||
) -> str:
|
||||
"""只组合本次任务需要的规则,不改变 Schema 或后端校验范围"""
|
||||
types = action_types(requirement, screen_plan)
|
||||
sections = [ACTION_SYSTEM_PROMPT]
|
||||
if screen_plan is None:
|
||||
sections.append(SIMPLE_TASK_PROMPT)
|
||||
action_types = {
|
||||
"update_canvas" if change.target_scope == "canvas" else change.operation
|
||||
for change in requirement.changes
|
||||
}
|
||||
else:
|
||||
sections.append(PLAN_TASK_PROMPT)
|
||||
action_types = set()
|
||||
dispositions = {item.disposition for item in screen_plan.components}
|
||||
if screen_plan.canvas_changes:
|
||||
sections.append(
|
||||
"## 调整画布\n将 canvas_changes 中的最终属性值转换为 update_canvas,完整覆盖且不添加其他画布字段"
|
||||
)
|
||||
action_types.add("update_canvas")
|
||||
if any(item.disposition == "add" for item in screen_plan.components):
|
||||
action_types.add("add")
|
||||
if any(item.disposition == "replace" for item in screen_plan.components):
|
||||
if "replace" in dispositions:
|
||||
sections.append(REPLACE_PLAN_PROMPT)
|
||||
action_types.add("add")
|
||||
if any(item.disposition == "remove" for item in screen_plan.components):
|
||||
action_types.add("delete")
|
||||
modifications = [
|
||||
item for item in screen_plan.components if item.disposition == "modify"
|
||||
]
|
||||
if modifications:
|
||||
if "modify" in dispositions:
|
||||
sections.append(MODIFY_PLAN_PROMPT)
|
||||
action_types.update(("move", "resize"))
|
||||
if any(item.design for item in modifications):
|
||||
action_types.add("update")
|
||||
if types & FIELD_ACTIONS:
|
||||
sections.append(FIELD_QUERY_PROMPT)
|
||||
|
||||
# 排序保证提示词顺序稳定,缺少动作说明时直接报错,避免静默遗漏
|
||||
sections.append("# 本次可用动作\n" + "、".join(sorted(action_types)))
|
||||
sections.extend(ACTION_RULES[name] for name in sorted(action_types))
|
||||
sections.append("# 本次可用动作\n" + "、".join(sorted(types)))
|
||||
sections.extend(ACTION_RULES[name] for name in sorted(types))
|
||||
if repairing:
|
||||
sections.append(REPAIR_TASK_PROMPT)
|
||||
return "\n\n".join(section.strip() for section in sections)
|
||||
|
||||
Reference in New Issue
Block a user