feat: Add Expert Transformation Agent with multi-expert perspective system
- Backend: Add expert transformation router with 3-step SSE pipeline - Step 0: Generate diverse expert team (random domains) - Step 1: Each expert generates keywords for attributes - Step 2: Batch generate descriptions for expert keywords - Backend: Add simplified prompts for reliable JSON output - Frontend: Add TransformationPanel with React Flow visualization - Frontend: Add TransformationInputPanel for expert configuration - Expert count (2-8), keywords per expert (1-3) - Custom expert domains support - Frontend: Add expert keyword nodes with expert badges - Frontend: Improve description card layout (wider cards, more spacing) - Frontend: Add fallback for missing descriptions with visual indicators 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
78
backend/app/prompts/expert_transformation_prompt.py
Normal file
78
backend/app/prompts/expert_transformation_prompt.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""Expert Transformation Agent 提示詞模組"""
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
def get_expert_generation_prompt(
|
||||
query: str,
|
||||
categories: List[str],
|
||||
expert_count: int,
|
||||
custom_experts: Optional[List[str]] = None
|
||||
) -> str:
|
||||
"""Step 0: 生成專家團隊(不依賴主題,純隨機多元)"""
|
||||
custom_text = ""
|
||||
if custom_experts and len(custom_experts) > 0:
|
||||
custom_text = f"(已指定:{', '.join(custom_experts[:expert_count])})"
|
||||
|
||||
return f"""/no_think
|
||||
隨機組建 {expert_count} 個來自完全不同領域的專家團隊{custom_text}。
|
||||
|
||||
回傳 JSON:
|
||||
{{"experts": [{{"id": "expert-0", "name": "職業", "domain": "領域", "perspective": "角度"}}, ...]}}
|
||||
|
||||
規則:
|
||||
- id 為 expert-0 到 expert-{expert_count - 1}
|
||||
- name 填寫職業名稱(非人名),2-5字
|
||||
- 各專家的 domain 必須來自截然不同的領域,越多元越好"""
|
||||
|
||||
|
||||
def get_expert_keyword_generation_prompt(
|
||||
category: str,
|
||||
attribute: str,
|
||||
experts: List[dict], # List[ExpertProfile]
|
||||
keywords_per_expert: int = 1
|
||||
) -> str:
|
||||
"""Step 1: 專家視角關鍵字生成"""
|
||||
experts_info = ", ".join([f"{exp['id']}:{exp['name']}({exp['domain']})" for exp in experts])
|
||||
|
||||
return f"""/no_think
|
||||
專家團隊:{experts_info}
|
||||
屬性:「{attribute}」({category})
|
||||
|
||||
每位專家從自己的專業視角為此屬性生成 {keywords_per_expert} 個創新關鍵字(2-6字)。
|
||||
關鍵字要反映該專家領域的獨特思考方式。
|
||||
|
||||
回傳 JSON:
|
||||
{{"keywords": [{{"keyword": "詞彙", "expert_id": "expert-X", "expert_name": "名稱"}}, ...]}}
|
||||
|
||||
共需 {len(experts) * keywords_per_expert} 個關鍵字。"""
|
||||
|
||||
|
||||
def get_expert_batch_description_prompt(
|
||||
query: str,
|
||||
category: str,
|
||||
expert_keywords: List[dict] # List[ExpertKeyword]
|
||||
) -> str:
|
||||
"""Step 2: 批次生成專家關鍵字的描述"""
|
||||
keywords_info = ", ".join([
|
||||
f"{kw['expert_name']}:{kw['keyword']}"
|
||||
for kw in expert_keywords
|
||||
])
|
||||
|
||||
# 建立 keyword -> (expert_id, expert_name) 的對照
|
||||
keyword_expert_map = ", ".join([
|
||||
f"{kw['keyword']}→{kw['expert_id']}/{kw['expert_name']}"
|
||||
for kw in expert_keywords
|
||||
])
|
||||
|
||||
return f"""/no_think
|
||||
物件:「{query}」
|
||||
關鍵字(專家:詞彙):{keywords_info}
|
||||
對照:{keyword_expert_map}
|
||||
|
||||
為每個關鍵字生成創新描述(15-30字),說明如何將該概念應用到「{query}」上。
|
||||
|
||||
回傳 JSON:
|
||||
{{"descriptions": [{{"keyword": "詞彙", "expert_id": "expert-X", "expert_name": "名稱", "description": "應用描述"}}, ...]}}
|
||||
|
||||
共需 {len(expert_keywords)} 個描述。"""
|
||||
Reference in New Issue
Block a user