""" 情景对话模式:场景与话题常量及首句模板 参考:项目文档/情景对话模式设计与改造方案.md """ from typing import Dict, List, Tuple # 场景键 SCENE_DEFAULT = "default" SCENE_WINDOW = "window" # Lumi在窗前看风景 SCENE_READING = "reading" # Lumi在桌前看书 SCENE_EATING = "eating" # Lumi在桌前吃饭 # 场景权重(用于加权随机):default 70%, 三个特殊各 10% SCENE_WEIGHTS: List[Tuple[str, int]] = [ (SCENE_DEFAULT, 70), (SCENE_WINDOW, 10), (SCENE_READING, 10), (SCENE_EATING, 10), ] # 每个特殊场景下的 3 个话题 key SCENARIO_TOPICS: Dict[str, List[str]] = { SCENE_WINDOW: ["weather", "season", "travel"], SCENE_READING: ["reading", "hobbies", "relaxation"], SCENE_EATING: ["favourite_food", "hometown_food", "daily_meal"], } # 话题展示名 (labelEn | labelZh),用于 greeting_context.topics TOPIC_LABELS: Dict[str, Dict[str, str]] = { "weather": {"labelEn": "Weather", "labelZh": "天气"}, "season": {"labelEn": "Season", "labelZh": "季节"}, "travel": {"labelEn": "Travel", "labelZh": "旅行"}, "reading": {"labelEn": "Reading", "labelZh": "阅读"}, "hobbies": {"labelEn": "Hobbies", "labelZh": "爱好"}, "relaxation": {"labelEn": "Relaxation", "labelZh": "放松"}, "favourite_food": {"labelEn": "Favourite food", "labelZh": "喜欢的食物"}, "hometown_food": {"labelEn": "Hometown food", "labelZh": "家乡的食物"}, "daily_meal": {"labelEn": "Daily meal", "labelZh": "日常饮食"}, } # 首句模板:{name} 替换为用户名 SPECIAL_TOPIC_FIRST_LINES: Dict[str, str] = { "weather": "Hi, {name}! The sky is so clear today. How is the weather at your place?", "season": "Hi {name}! The leaves are changing colour. It's fall. What is your favorite season?", "travel": "Hi, {name}! I want to go somewhere far away. Where do you want to travel?", "reading": "Hi, {name}! I am reading. This story is crazy! What book are you reading lately?", "hobbies": "Hi, {name}! I am reading. I love it! What do you do in your free time?", "relaxation": "Hi, {name}! I am reading. It is the only way to relax my brain. What is your way to escape?", "favourite_food": "Hi, {name}! I am having snacks. It's so delicious. What is your favorite food?", "hometown_food": "Hi, {name}! I am having snacks. It's so delicious. What is your hometown's best dish?", "daily_meal": "Hi, {name}! I am having snacks. It's so delicious. What you ate today?", } def get_special_first_line(topic_key: str, user_name: str) -> str: """获取特殊场景某话题的首句(已替换用户名)。""" user_name = (user_name or "").strip() or "Neo" template = SPECIAL_TOPIC_FIRST_LINES.get(topic_key) if not template: return f"Hi, {user_name}! How are you today?" return template.format(name=user_name) def build_topics_payload(available_topic_keys: List[str]) -> List[Dict[str, str]]: """构建 greeting_context.topics 数组:[{ key, labelEn, labelZh }]。""" return [ {"key": k, **TOPIC_LABELS.get(k, {"labelEn": k, "labelZh": k})} for k in available_topic_keys ]