feat: 优化部分代码及提示词
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""将简单修改或新增规划转换为动作列表"""
|
||||
"""将简单修改或包含新增、调整的规划转换为动作列表"""
|
||||
|
||||
import json
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.actions.plan import assemble_plan_actions, plan_block_reason, plan_mate
|
||||
from app.clients.llm import get_llm
|
||||
from app.processor.base import BaseNode
|
||||
from app.processor.state import QueryState
|
||||
from app.prompt.action import ACTION_SYSTEM_PROMPT
|
||||
from app.prompt.action import build_action_prompt
|
||||
from app.schemas.action_validation import ActionValidationError, schema_errors
|
||||
from app.schemas.actions import ActionBatch, AddAction
|
||||
|
||||
@@ -93,7 +93,13 @@ class ActionNode(BaseNode):
|
||||
try:
|
||||
result = await llm_client.ainvoke(
|
||||
[
|
||||
SystemMessage(content=ACTION_SYSTEM_PROMPT),
|
||||
SystemMessage(
|
||||
content=build_action_prompt(
|
||||
state["requirement"],
|
||||
state.get("screen_plan"),
|
||||
repairing=state.get("repair_plan") is not None,
|
||||
)
|
||||
),
|
||||
HumanMessage(content=json.dumps(payload, ensure_ascii=False)),
|
||||
]
|
||||
)
|
||||
@@ -215,9 +221,29 @@ if __name__ == "__main__":
|
||||
}
|
||||
],
|
||||
)
|
||||
# 加 --modify 测试规划到已有组件调整,无需新增物料
|
||||
if "--modify" in sys.argv:
|
||||
state["change_scope"].needs_planning = True
|
||||
state["screen_plan"] = ScreenPlan(
|
||||
goal="向右移动 50px",
|
||||
design_summary="调整图表位置",
|
||||
layout_description="保留尺寸,向右移动",
|
||||
components=[
|
||||
{
|
||||
"plan_id": "sales-position",
|
||||
"disposition": "modify",
|
||||
"target_id": "sales-chart",
|
||||
"purpose": "调整位置",
|
||||
"layout": {"x": 150, "y": 200, "width": 400, "height": 300},
|
||||
}
|
||||
],
|
||||
)
|
||||
node = ActionNode()
|
||||
final_state = await node.process(state)
|
||||
if "--add" in sys.argv and final_state.get("actions") is not None:
|
||||
if (
|
||||
state.get("screen_plan") is not None
|
||||
and final_state.get("actions") is not None
|
||||
):
|
||||
final_state = ValidatorNode().process(final_state)
|
||||
print(
|
||||
json.dumps(
|
||||
|
||||
Reference in New Issue
Block a user