diff --git a/bigwork/src/smart_customer_service.py b/bigwork/src/smart_customer_service.py index 484f62b..86e18f7 100644 --- a/bigwork/src/smart_customer_service.py +++ b/bigwork/src/smart_customer_service.py @@ -610,6 +610,11 @@ class SmartCustomerService: def _call_deepseek_api(self, user_id: str, churn_prediction: Dict[str, Any], query: str = "") -> str: """调用DeepSeek API生成挽留措施""" try: + # 检查API密钥是否有效 + if not DEEPSEEK_API_KEY or DEEPSEEK_API_KEY == "your-key-here": + st.warning("DeepSeek API密钥未配置或无效,将使用备用方案") + return self._generate_mock_retention_plan(user_id, churn_prediction, query) + # 构建智能提示词(包含用户查询内容) prompt = self._build_retention_prompt(user_id, churn_prediction, query) @@ -1079,8 +1084,8 @@ class SmartCustomerService: api_url = "https://api.deepseek.com/v1/chat/completions" # 检查API密钥是否配置 - if not api_key: - print("DeepSeek API密钥未配置,返回默认响应") + if not api_key or api_key == "your-key-here": + print("DeepSeek API密钥未配置或无效,返回默认响应") return "感谢您的反馈。我们的客服团队将尽快处理您的问题,并与您联系。" # 构建系统提示 @@ -1320,8 +1325,8 @@ class SmartCustomerService: api_url = "https://api.deepseek.com/v1/chat/completions" # 检查API密钥是否配置 - if not api_key: - print("DeepSeek API密钥未配置,返回默认情感分析结果") + if not api_key or api_key == "your-key-here": + print("DeepSeek API密钥未配置或无效,返回默认情感分析结果") return "neutral" # 构建系统提示