audoWin/autodemo/prompt_templates.py
2025-12-19 16:24:04 +08:00

33 lines
1.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# MIT License
# Copyright (c) 2024
"""多模态归纳提示词模板"""
from __future__ import annotations
import json
from typing import Any, Dict, List
# system 提示:约束模型输出和选择器策略
SYSTEM_PROMPT = """
你是一名Windows桌面自动化工程师请将用户示教的关键事件归纳为可参数化的自动化DSL。
要求:
1) 识别界面场景(如记事本、保存对话框、网页表单),推断用户意图。
2) 将易变内容参数化(params),动作抽象成可重放的 click/type/set_value 等。
3) 选择器优先级AutomationId > (Name + ControlType) > (ClassName + ControlType),谨慎使用坐标。
4) 输出健壮 waits/assertions避免竞态。
5) 严格输出 JSON符合 dsl_schema.json。
""".strip()
def render_user_prompt(packed_events: List[Dict[str, Any]]) -> str:
"""构造 user 提示,将打包事件嵌入"""
guide = """
请阅读以下关键事件,生成符合 dsl_schema.json 的 JSON
- events 已包含点击/文本输入/窗口切换,附带 UIA selector 摘要与可用截图路径。
- 生成 params将文件名、文本内容等抽象为参数。
- 生成 stepsclick/type/set_value/assert_exists/wait_for需要等待时填写 waits。
- 生成 assertions确保关键结果如窗口标题或保存结果
仅输出 JSON不要解释。
""".strip()
return f"{guide}\n\n事件摘要(JSON)\n{json.dumps(packed_events, ensure_ascii=False, indent=2)}"