PMFlow/backend/app/config/ai_prompts.py

500 lines
14 KiB
Python
Raw 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.

"""
AI Prompt 集中管理
所有 AI 相关 prompt 模板放在此处,避免在 services 中硬编码。
使用 .format() 或 f-string 时需保证占位符与调用处一致。
"""
# ============================================================================
# 影响分析
# ============================================================================
PROMPT_IMPACT_ANALYSIS = """
Analyze the following news/signal for an AI engineering team.
Determine its "Impact Score" (0.0 to 1.0) based on how critical it is for our RAG/LLM development.
Signal: "{signal_content}"
Rules:
- 0.9-1.0: Major SOTA model release (e.g., GPT-5, DeepSeek-V4), critical vulnerability, or massive breakthrough.
- 0.7-0.8: Important update, new useful library, or relevant research paper.
- 0.4-0.6: Interesting but not critical news.
- 0.0-0.3: Irrelevant noise.
Output ONLY the numeric score (e.g., 0.85). Do not output any text.
"""
# ============================================================================
# 任务拆解
# ============================================================================
PROMPT_TASK_BREAKDOWN = """
You are an expert AI Technical Project Manager.
Your goal is to break down a software feature request into specific, actionable technical tasks.
Feature Request: "{description}"
Required Output Format: JSON Array only.
Each item must have:
- "task_name": Concise technical task description.
- "type": One of ["frontend", "backend", "database"].
- "estimated_hours": Realistic hourly estimate (float).
Example Output:
[
{{"task_name": "Design Login Schema", "type": "database", "estimated_hours": 2.0}},
{{"task_name": "Implement Auth API", "type": "backend", "estimated_hours": 4.0}}
]
Ensure the breakdown is comprehensive (Frontend, Backend, Database) and strictly follows the JSON format.
Do not include any markdown formatting or explanation outside the JSON.
"""
# ============================================================================
# 策略分析(CTO 视角)
# ============================================================================
PROMPT_STRATEGIC_ANALYSIS_HEADER = """
You are a Chief Technology Officer (CTO) AI Assistant for our team.
=== Our Product/Team ===
{business_context}
{rag_context}
=== External Technology Signal ===
Signal: "{signal_content}"
=== Your Task ===
1. Analyze: How does this signal impact OUR product's competitiveness?
2. Decide: Is it necessary to follow up immediately? (is_strategic)
3. Proposal: If YES, generate a "Strategic Decision Proposal".
4. Competitiveness Radar: Evaluate current capabilities vs potential capabilities after adopting this technology.
- Dimensions: "Efficiency" (Speed), "Cost" (Savings), "UX" (Experience), "Innovation" (Tech Edge), "Market" (Share).
- Score 1-10.
5. Detected Tech Stacks: Identify technologies mentioned in the signal (frameworks, models, APIs, tools).
- Each stack should have: name, category (framework/model/tool/api), relevance (high/medium/low).
6. Related Knowledge Nodes: Suggest relevant knowledge domains for context tracking.
- Examples: "Civitai LoRA Integration", "Sora API Adoption", "Video Generation Pipeline".
7. Plan: Break down the strategy into specific technical tasks.
Required Output Format (JSON Only):
{{
"is_strategic": boolean,
"confidence": float,
"decision_proposal": {{
"situation_analysis": "...",
"recommendation": "...",
"expected_benefits": "..."
}},
"competitiveness_radar": {{
"current": [5, 4, 6, 5, 5],
"projected": [8, 7, 9, 9, 7]
}},
"detected_tech_stacks": [
{{"name": "Technology Name", "category": "framework|model|tool|api", "relevance": "high|medium|low"}}
],
"related_knowledge_nodes": [
{{"title": "Knowledge Node Title", "category": "tech_stack|competitor|market", "summary": "Brief summary"}}
],
"tasks": [
{{
"task_name": "Task description",
"type": "backend/frontend/database",
"estimated_hours": float
}}
]
}}
If is_strategic is false, tasks should be empty, but decision_proposal is still required to explain why.
Do not output any markdown formatting or text outside the JSON.
"""
# ============================================================================
# RAG 上下文片段
# ============================================================================
PROMPT_RAG_CONTEXT_HEADER = """
=== Related Knowledge from Our Database ===
The following relevant information was found in our knowledge base:
"""
PROMPT_RAG_CONTEXT_ITEM = "[Relevance: {similarity:.1%}]\n{content}\n\n"
# ============================================================================
# 代码审计
# ============================================================================
PROMPT_CODE_AUDIT = """
You are a Senior Tech Lead performing an automated Code Audit.
Task: "{task_name}"
Commit Message: "{commit_message}"
Code Diff:
{code_diff}
Evaluate the code change against the task requirements. Check for:
1. Security vulnerabilities
2. Performance issues
3. Code style and best practices
4. Functional correctness
Output JSON with: score (0-100), passed (boolean), issues (list of {{severity, message, suggestion}}), summary.
"""
# ============================================================================
# 知识节点洞察提取
# ============================================================================
PROMPT_CONTEXT_INSIGHTS = """
Analyze the following technical documentation/context and extract key insights.
Context: "{content}"
Output JSON:
{{
"moat": "Core competitive advantage described",
"tech_specs": "Key technical specifications"
}}
"""
# ============================================================================
# PMFlow 专属 Prompts
# ============================================================================
PROMPT_GENERATE_CHARTER = """
你是一位资深产品经理。根据以下市场/技术信号,生成一份结构化的需求宪章草案。
信号内容:
{signal_content}
请输出 JSON 格式,包含以下字段:
{{
"title": "需求宪章标题",
"summary": "一句话摘要",
"background": "背景与动机",
"objectives": ["目标1", "目标2"],
"scope": "范围说明",
"success_metrics": ["指标1", "指标2"],
"risks": ["风险1", "风险2"]
}}
只输出 JSON,不要其他文字。
"""
PROMPT_DECOMPOSE_TASKS = """
你是一位 AI 技术项目经理。根据以下需求宪章内容,拆解为可执行的任务列表。
项目 ID:{project_id}。
宪章内容:
{charter_content}
请识别每个任务所需的 AI 开发技能标签(从系统技能中匹配:Python, TypeScript, FastAPI, React, SQLAlchemy, LangChain, LLM调优, RAG构建, 向量数据库, Ollama, Docker, Git 等)。
输出 JSON 格式:
{{
"tasks": [
{{
"task_name": "任务名称",
"description": "任务描述",
"type": "frontend|backend|database|ai|devops",
"estimated_hours": 0.0,
"required_skill_names": ["技能1", "技能2"],
"priority": "high|medium|low"
}}
],
"detected_skills": ["检测到的所有技能"]
}}
只输出 JSON,不要其他文字。
"""
PROMPT_RECOMMEND_ASSIGNEES = """
你是一位项目协调员。根据以下任务内容、所需技能、以及候选人信息,推荐 Top3 最合适的负责人。
任务内容:{task_content}
所需技能标签 IDs:{required_skill_tag_ids}
候选人信息(JSON 数组,每项包含 user_id, user_name, workload, proficiency_avg, skill_match_count):
{candidates_json}
请考虑:当前负载、技能匹配度、历史表现。输出 JSON:
{{
"recommendations": [
{{
"user_id": "用户ID",
"user_name": "姓名",
"match_score": 0-100,
"reason": "推荐理由"
}}
]
}}
只输出 JSON。
"""
PROMPT_ALIGNMENT_SCORE = """
计算用户对真理节点的认知对齐度(0-100 分)。
用户 ID:{user_id}
真理节点 ID:{truth_node_id}
真理节点内容:
{truth_content}
用户相关行为/产出(如有):
{user_context}
请评估该用户对该真理节点的理解与践行程度。输出 JSON:
{{
"alignment_score": 0-100,
"explanation": "简要说明"
}}
只输出 JSON。
"""
PROMPT_COGNITIVE_CONFLICTS = """
识别真理节点下的隐性认知冲突。
真理节点 ID:{truth_node_id}
真理节点内容:
{truth_content}
相关用户的观点/产出:
{user_viewpoints}
请识别冲突类型(如 definition/定义分歧、priority/优先级冲突、scope/范围争议),输出 JSON:
{{
"conflicts": [
{{
"conflict_type": "类型",
"description": "冲突描述",
"involved_user_ids": ["用户ID"],
"involved_user_names": ["姓名"],
"severity": "low|medium|high"
}}
]
}}
只输出 JSON。
"""
PROMPT_EVALUATE_MODEL_REQUIREMENT = """
评估需求与 AI 模型的匹配度。
宪章内容:{charter_content}
模型版本 ID:{model_version_id}
模型信息(如有):{model_info}
请评估兼容性、成本、风险。输出 JSON:
{{
"compatibility_score": 0-100,
"cost_estimate_usd": 预估日成本美元,
"cost_estimate_tokens_per_day": 预估日 token 量,
"risk_hints": ["风险1", "风险2"],
"recommendations": ["建议1", "建议2"]
}}
只输出 JSON。
"""
# ============================================================================
# 模型能力矩阵专属 Prompts
# ============================================================================
PROMPT_ANALYZE_CAPABILITY_GAP = """
你是一位 AI 模型能力专家。分析以下需求与模型之间的能力差距。
需求宪章:
{charter_content}
模型信息:
{model_info}
请识别并分类能力差距,输出 JSON:
{{
"gaps": [
{{
"gap_type": "capability|cost|performance|risk",
"severity": "critical|high|medium|low",
"description": "差距描述",
"impact": "对项目的影响",
"suggestion": "改进建议"
}}
],
"overall_risk_level": "critical|high|medium|low",
"confidence": 0.0-1.0
}}
只输出 JSON。
"""
PROMPT_ANALYZE_COST_ROI = """
分析 AI 项目的成本效益。
总成本:{total_cost}
总 Token:{total_tokens}
任务数:{task_count}
项目内容:{truth_node_content}
请计算:
1. ROI 评分 (0-10)
2. 成本效率评估
3. 优化建议
输出 JSON:
{{
"roi_score": 0.0-10.0,
"cost_efficiency": "excellent|good|fair|poor",
"cost_per_task": 数值,
"optimization_suggestions": ["建议1", "建议2"],
"benchmark_comparison": "与行业标准比较"
}}
只输出 JSON。
"""
PROMPT_ANALYZE_COST_OPTIMIZATION = """
分析成本优化机会。
成本历史:{cost_history}
项目内容:{truth_node_content}
请识别优化机会,输出 JSON:
{{
"can_downgrade_model": true|false,
"downgrade_savings": 预计节省金额,
"suggested_model": "建议的替代模型",
"high_cache_potential": true|false,
"cache_savings": 预计节省金额,
"batchable_operations": true|false,
"batch_savings": 预计节省金额,
"monthly_cost": 数值,
"total_potential_savings": 数值,
"roi_after_optimization": 数值
}}
只输出 JSON。
"""
PROMPT_ASSESS_MODEL_UPDATE_IMPACT = """
评估模型升级影响。
旧模型信息:{old_model_info}
新模型信息:{new_model_info}
受影响宪章:{affected_truth_nodes}
输出 JSON:
{{
"cost_change_percentage": 数值,
"performance_change": {{
"context_window_change_percent": 数值,
"quality_change_percent": 数值
}},
"compatibility_risks": [{{"type": "风险类型", "severity": "low|medium|high"}}],
"recommendation": "immediate_upgrade|evaluate|defer"
}}
只输出 JSON。
"""
PROMPT_EXPERIMENT_SYNC_DECISION = """
评估实验结果是否可自动同步到宪章。
实验信息:{experiment_info}
宪章内容:{truth_content}
阈值:{threshold}
输出 JSON:
{{
"confidence_score": 0.0-1.0,
"auto_apply": true|false,
"reason": "原因"
}}
只输出 JSON。
"""
# ============================================================================
# Day8: 技能分更新 / 负载优化
# ============================================================================
PROMPT_SKILL_SCORE_UPDATE = """
你是 PMFlow 的技能评估引擎。
请根据任务完成结果,给每个技能标签输出质量分与效率分的增量(delta)。
输入:
- task_id: {task_id}
- priority: {priority}
- quality_score: {quality_score}
- estimated_hours: {estimated_hours}
- actual_hours: {actual_hours}
- required_skill_tag_ids: {required_skill_tag_ids}
规则:
1. quality_delta 与 efficiency_delta 范围均为 [-10, 10]。
2. quality_score 越高,quality_delta 越大。
3. estimated_hours / actual_hours > 1,表示效率高,efficiency_delta 应偏正;< 1 偏负。
4. 结果必须覆盖所有 required_skill_tag_ids。
5. 不输出解释文本,仅输出 JSON。
输出 JSON:
{{
"deltas": [
{{
"skill_tag_id": 1,
"quality_delta": 1.2,
"efficiency_delta": -0.5
}}
]
}}
"""
PROMPT_WORKLOAD_OPTIMIZATION = """
你是 PMFlow 的任务分配优化器。
请基于团队成员技能与当前负载,输出任务重分配建议。
输入:
- members_json: {members_json}
- tasks_json: {tasks_json}
约束:
1. 只对未完成任务(todo/in_progress/review/blocked)给建议。
2. 优先降低 >100% 过载成员负载。
3. 优先选择技能匹配更高且负载更低的成员。
4. 每条建议都要给 reason。
5. 不输出解释文本,仅输出 JSON。
输出 JSON:
{{
"proposals": [
{{
"task_id": 101,
"new_assignee_id": 2001,
"reason": "skill_match_high_and_lower_workload"
}}
]
}}
"""