From 2c0c045b2fce8a576d104332b9996200452a8390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=A0=E7=9A=84=E5=A7=93=E5=90=8D?= <你的邮箱@example.com> Date: Thu, 15 Jan 2026 23:45:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(smart=5Fcustomer=5Fservice):=20=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E5=B9=B6=E5=A4=84=E7=90=86=E6=97=A0=E6=95=88=E7=9A=84?= =?UTF-8?q?DeepSeek=20API=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当API密钥未配置或为默认值时,使用备用方案生成挽留措施或返回默认响应,避免直接调用无效API --- bigwork/src/smart_customer_service.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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" # 构建系统提示