fix(smart_customer_service): 检查并处理无效的DeepSeek API密钥
当API密钥未配置或为默认值时,使用备用方案生成挽留措施或返回默认响应,避免直接调用无效API
This commit is contained in:
parent
37f0982809
commit
2c0c045b2f
@ -610,6 +610,11 @@ class SmartCustomerService:
|
|||||||
def _call_deepseek_api(self, user_id: str, churn_prediction: Dict[str, Any], query: str = "") -> str:
|
def _call_deepseek_api(self, user_id: str, churn_prediction: Dict[str, Any], query: str = "") -> str:
|
||||||
"""调用DeepSeek API生成挽留措施"""
|
"""调用DeepSeek API生成挽留措施"""
|
||||||
try:
|
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)
|
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_url = "https://api.deepseek.com/v1/chat/completions"
|
||||||
|
|
||||||
# 检查API密钥是否配置
|
# 检查API密钥是否配置
|
||||||
if not api_key:
|
if not api_key or api_key == "your-key-here":
|
||||||
print("DeepSeek API密钥未配置,返回默认响应")
|
print("DeepSeek API密钥未配置或无效,返回默认响应")
|
||||||
return "感谢您的反馈。我们的客服团队将尽快处理您的问题,并与您联系。"
|
return "感谢您的反馈。我们的客服团队将尽快处理您的问题,并与您联系。"
|
||||||
|
|
||||||
# 构建系统提示
|
# 构建系统提示
|
||||||
@ -1320,8 +1325,8 @@ class SmartCustomerService:
|
|||||||
api_url = "https://api.deepseek.com/v1/chat/completions"
|
api_url = "https://api.deepseek.com/v1/chat/completions"
|
||||||
|
|
||||||
# 检查API密钥是否配置
|
# 检查API密钥是否配置
|
||||||
if not api_key:
|
if not api_key or api_key == "your-key-here":
|
||||||
print("DeepSeek API密钥未配置,返回默认情感分析结果")
|
print("DeepSeek API密钥未配置或无效,返回默认情感分析结果")
|
||||||
return "neutral"
|
return "neutral"
|
||||||
|
|
||||||
# 构建系统提示
|
# 构建系统提示
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user