Files
novelty-seeking/backend/app/prompts/expert_transformation_prompt.py
gbanyan 5571076406 feat: Add curated expert occupations with local data sources
- Add curated occupations seed files (210 entries in zh/en) with specific domains
- Add DBpedia occupations data (2164 entries) for external source option
- Refactor expert_source_service to read from local JSON files
- Improve keyword generation prompts to leverage expert domain context
- Add architecture analysis documentation (ARCHITECTURE_ANALYSIS.md)
- Fix expert source selection bug (proper handling of empty custom_experts)
- Update frontend to support curated/dbpedia/wikidata expert sources

Key changes:
- backend/app/data/: Local occupation data files
- backend/app/services/expert_source_service.py: Simplified local file reading
- backend/app/prompts/expert_transformation_prompt.py: Better domain-aware prompts
- Removed expert_cache.py (no longer needed with local files)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-04 16:34:35 +08:00

106 lines
3.5 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.
"""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
物件:「{query}
專家:{expert_name}{domain_text}
關鍵字:{keyword}
你是一位{expert_name}。從你的專業視角生成一段創新應用描述15-30字說明如何將「{keyword}」的概念應用到「{query}」上。
描述要體現{expert_name}的專業思維和獨特觀點。
回傳 JSON
{{"description": "應用描述"}}"""