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:
2025-12-03 16:26:17 +08:00
parent 1ed1dab78f
commit 534fdbbcc4
25 changed files with 3114 additions and 27 deletions

View File

@@ -0,0 +1,97 @@
"""Transformation Agent 提示詞模組"""
from typing import List
def get_keyword_generation_prompt(
category: str,
attributes: List[str],
keyword_count: int = 3
) -> str:
"""
Step 1: 生成新關鍵字
給定類別和現有屬性,生成全新的、有創意的關鍵字。
不考慮原始查詢,只專注於類別本身可能的延伸。
"""
attrs_text = "".join(attributes)
return f"""/no_think
你是一個創意發想專家。給定一個類別和該類別下的現有屬性,請生成全新的、有創意的關鍵字或描述片段。
【類別】{category}
【現有屬性】{attrs_text}
【重要規則】
1. 生成 {keyword_count} 個全新的關鍵字
2. 關鍵字必須符合「{category}」這個類別的範疇
3. 關鍵字要有創意,不能與現有屬性重複或太相似
4. 不要考慮任何特定物件,只專注於這個類別本身可能的延伸
5. 每個關鍵字應該是 2-6 個字的詞彙或短語
只回傳 JSON
{{
"keywords": ["關鍵字1", "關鍵字2", "關鍵字3"]
}}"""
def get_description_generation_prompt(
query: str,
category: str,
keyword: str
) -> str:
"""
Step 2: 結合原始查詢生成描述
用新關鍵字創造一個與原始查詢相關的創新應用描述。
"""
return f"""/no_think
你是一個創新應用專家。請將一個新的關鍵字概念應用到特定物件上,創造出創新的應用描述。
【物件】{query}
【類別】{category}
【新關鍵字】{keyword}
【任務】
請用「{keyword}」這個概念,為「{query}」創造一個創新的應用描述。
描述應該是一個完整的句子或短語,說明如何將這個新概念應用到物件上。
【範例格式】
- 如果物件是「腳踏車」,關鍵字是「監視」,可以生成「腳踏車監視騎乘者的身體健康狀況」
- 如果物件是「雨傘」,關鍵字是「發電」,可以生成「雨傘利用雨滴撞擊發電」
只回傳 JSON
{{
"description": "創新應用描述"
}}"""
def get_batch_description_prompt(
query: str,
category: str,
keywords: List[str]
) -> str:
"""
批次生成描述(可選的優化版本,一次處理多個關鍵字)
"""
keywords_text = "".join(keywords)
keywords_json = ", ".join([f'"{k}"' for k in keywords])
return f"""/no_think
你是一個創新應用專家。請將多個新的關鍵字概念應用到特定物件上,為每個關鍵字創造創新的應用描述。
【物件】{query}
【類別】{category}
【新關鍵字】{keywords_text}
【任務】
為每個關鍵字創造一個與「{query}」相關的創新應用描述。
每個描述應該是一個完整的句子或短語。
只回傳 JSON
{{
"descriptions": [
{{"keyword": "關鍵字1", "description": "描述1"}},
{{"keyword": "關鍵字2", "description": "描述2"}}
]
}}"""