feat:简化部分代码

This commit is contained in:
2026-09-29 07:23:42 -07:00
parent af84485e8d
commit 352d144823
13 changed files with 123 additions and 306 deletions
+7 -10
View File
@@ -4,7 +4,7 @@ import json
from langchain_core.exceptions import OutputParserException
from langchain_core.messages import HumanMessage, SystemMessage
from pydantic import BaseModel, ValidationError
from pydantic import ValidationError
from app.actions.plan import assemble_plan_actions, plan_block_reason, plan_materials
from app.clients.llm import get_llm
@@ -84,12 +84,6 @@ class ActionNode(BaseNode):
)
return updated_state
# 如果未通过动作能力检查,抛出异常,阻止不受支持的需求进入生成流程
if not can_generate_actions(state):
raise ValueError(
"ActionNode 当前只支持无需规划和资源的 move、resize、update、delete、update_canvas 需求"
)
# 将输入上下文、结构化需求和修改范围转成字典,作为本次模型输入
payload = {
"input_context": state["input_context"].model_dump(mode="json"),
@@ -143,11 +137,13 @@ class ActionNode(BaseNode):
]
)
# 将模型对象转成字典,非模型返回值保持原样,统一交给后面的协议校验
raw = result.model_dump() if isinstance(result, BaseModel) else result
# 响应中没有工具调用时解析器会返回 None
if result is None:
raise OutputParserException("模型未返回结构化结果")
raw = result.model_dump()
# 规划生成的新增节点只保留显式提供的字段,避免模型默认值覆盖物料默认配置
if isinstance(result, ActionBatch) and state.get("screen_plan") is not None:
if state.get("screen_plan") is not None:
# 将原动作对象与序列化结果逐项对应,只调整新增动作的节点数据
for source, target in zip(result.actions, raw["actions"]):
if isinstance(source, AddAction):
@@ -277,6 +273,7 @@ if __name__ == "__main__":
)
# 加 --modify 测试规划到已有组件调整,无需新增物料
if "--modify" in sys.argv:
state = ComponentResourceNode().process(state)
state["change_scope"].needs_planning = True
state["screen_plan"] = ScreenPlan(
goal="向右移动 50px",