Files
novelty-seeking/backend/app/prompts/expert_transformation_prompt.py
gbanyan bc281b8e0a feat: Add Deduplication Agent with embedding and LLM methods
Implement a new Deduplication Agent that identifies and groups similar
transformation descriptions. Supports two deduplication methods:
- Embedding: Fast vector similarity comparison using cosine similarity
- LLM: Accurate pairwise semantic comparison (slower but more precise)

Backend changes:
- Add deduplication router with /deduplicate endpoint
- Add embedding_service for vector-based similarity
- Add llm_deduplication_service for LLM-based comparison
- Improve expert_transformation error handling and progress reporting

Frontend changes:
- Add DeduplicationPanel with interactive group visualization
- Add useDeduplication hook for state management
- Integrate deduplication tab in main App
- Add threshold slider and method selector in sidebar

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 20:26:17 +08:00

105 lines
3.5 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.
"""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: 生成專家團隊(不依賴主題,純隨機多元)"""
import time
import random
custom_text = ""
if custom_experts and len(custom_experts) > 0:
custom_text = f"(已指定:{', '.join(custom_experts[:expert_count])}"
# 加入時間戳和隨機數來增加多樣性
seed = int(time.time() * 1000) % 10000
diversity_hints = [
"冷門、非主流、跨領域",
"罕見職業、新興領域、邊緣學科",
"非傳統、創新、小眾專業",
"未來趨向、實驗性、非常規",
"跨文化、混合領域、獨特視角"
]
hint = random.choice(diversity_hints)
return f"""/no_think
隨機組建 {expert_count} 個來自完全不同領域的專家團隊{custom_text}
【創新要求】(隨機種子:{seed}
- 優先選擇{hint}的專家
- 避免常見職業(如醫生、工程師、教師、律師等)
- 每個專家必須來自完全不相關的領域
- 越罕見、越創新越好
回傳 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_list = "\n".join([f"- {exp['id']}: {exp['name']}" for exp in experts])
return f"""/no_think
你需要扮演以下專家,為屬性生成創新關鍵字:
【專家名單】
{experts_list}
【任務】
屬性:「{attribute}」(類別:{category}
請為每位專家:
1. 先理解該職業的專業背景、知識領域、工作內容
2. 從該職業的獨特視角思考「{attribute}
3. 生成 {keywords_per_expert} 個與該專業相關的創新關鍵字2-6字
關鍵字必須反映該專家的專業思維方式,例如:
- 會計師 看「移動」→「資金流動」「成本效益」
- 建築師 看「移動」→「動線設計」「空間流動」
- 心理師 看「移動」→「行為動機」「情緒轉變」
回傳 JSON
{{"keywords": [{{"keyword": "詞彙", "expert_id": "expert-X", "expert_name": "名稱"}}, ...]}}
共需 {len(experts) * keywords_per_expert} 個關鍵字,每個關鍵字必須明顯與對應專家的專業領域相關。"""
def get_single_description_prompt(
query: str,
keyword: str,
expert_id: str,
expert_name: str,
expert_domain: str
) -> str:
"""Step 2: 為單一關鍵字生成描述"""
# 如果 domain 是通用的,就只用職業名稱
domain_text = f"{expert_domain}領域)" if expert_domain and expert_domain != "Professional Field" else ""
return f"""/no_think
你是一位{expert_name}{domain_text}
任務:為「{query}」生成一段創新應用描述。
關鍵字:{keyword}
從你的專業視角,說明如何將「{keyword}」的概念應用到「{query}」上。描述要具體、有創意15-30字。
只回傳 JSON不要其他文字
{{"description": "你的創新應用描述"}}"""