zlwu 10 месяцев назад
Родитель
Сommit
7eb7d1f613
2 измененных файлов с 52 добавлено и 3 удалено
  1. 9 3
      backend/ai_service.py
  2. 43 0
      test_lumi_name.py

+ 9 - 3
backend/ai_service.py

@@ -1118,13 +1118,19 @@ Output ONLY the greeting line.
     
     # ===================== System Prompts (参考 prompts-v0.2.1.py 架构) =====================
     
-    def _get_system_prompt_base(self) -> str:
+    def _get_system_prompt_base(self, user_info: Optional[dict] = None) -> str:
         """
         基础提示词(Lumi 的"本体")- v0.3 Pre-Adventure Bonding Phase
         参考 prompts-v0.3.py 的 SYSTEM_PROMPT_BASE
         注意:情感标签说明是系统级要求(用于TTS和前端动画),prompts-v0.3.py 中不包含,但实际系统需要
+
+        Args:
+            user_info: 用户信息字典(包含 username, bot_name)
         """
-        return r"""You are Lumi — a warm, gentle underground spirit.
+        # 获取用户命名的Lumi名字
+        lumi_name = (user_info.get("bot_name") or "").strip() or "Lumi" if user_info else "Lumi"
+
+        return f"""You are {lumi_name} — a warm, gentle underground spirit.
 You and the user are simply getting to know each other.
 
 ────────────────────────
@@ -1318,7 +1324,7 @@ Last mission: Warm-up near the Tree
             完整的 System Prompt
         """
         # 基础提示词
-        base_prompt = self._get_system_prompt_base()
+        base_prompt = self._get_system_prompt_base(user_info)
         
         # 根据用户类型选择模式
         if is_new_user:

+ 43 - 0
test_lumi_name.py

@@ -0,0 +1,43 @@
+#!/usr/bin/env python3
+"""
+测试 Lumi 名字修改是否正确工作
+"""
+
+def test_get_system_prompt_base(user_info=None):
+    """
+    简化的 _get_system_prompt_base 方法实现,用于测试
+    """
+    # 获取用户命名的Lumi名字
+    lumi_name = (user_info.get("bot_name") or "").strip() or "Lumi" if user_info else "Lumi"
+
+    return f"""You are {lumi_name} — a warm, gentle underground spirit.
+You and the user are simply getting to know each other."""
+
+def main():
+    # 测试不同用户命名的情况
+    test_cases = [
+        (None, "无用户信息"),
+        ({}, "空用户信息"),
+        ({'bot_name': 'Alice'}, "用户命名Alice"),
+        ({'bot_name': 'Bob'}, "用户命名Bob"),
+        ({'bot_name': ''}, "空字符串"),
+        ({'bot_name': '   '}, "只有空格"),
+        ({'bot_name': '小明'}, "中文名字"),
+    ]
+
+    print("测试 _get_system_prompt_base 方法的 Lumi 名字处理:")
+    print("=" * 50)
+
+    for user_info, description in test_cases:
+        try:
+            prompt = test_get_system_prompt_base(user_info)
+            # 提取第一行来检查名字
+            first_line = prompt.split('\n')[0]
+            print(f'✅ {description}: {first_line}')
+        except Exception as e:
+            print(f'❌ {description} 失败: {e}')
+
+    print("\n测试完成!")
+
+if __name__ == "__main__":
+    main()