feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估

- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
hugo committed 2026-08-02 19:26:35 +08:00
1 parent cef3d5b26a
commit 3a9fbac2fc
226 files changed
+25010 -2098

No files matched your search

+19 -10
View File
@@ -134,6 +134,23 @@ class DifyService:
return "当前会话上下文过长,模型无法继续回答。请新建对话后重新查询。"
return f"{resolved_agent_name}暂时无法完成查询,请稍后重试。"
@staticmethod
def _friendly_stream_request_failure_message(error: requests.exceptions.RequestException) -> str:
"""
将对话连接异常转换成可安全展示的业务提示。
Args:
error: requests 抛出的上游连接异常;原始内容只用于服务端日志。
Returns:
不包含服务名称、地址、密钥或异常正文的用户提示。
"""
if isinstance(error, requests.exceptions.ReadTimeout):
return "回答生成时间较长,本次请求未能完成,请稍后重试。"
if isinstance(error, requests.exceptions.ConnectTimeout):
return "当前服务连接超时,请稍后重试。"
return "当前服务暂时无法完成回答,请稍后重试。"
@staticmethod
def _merge_stream_answer_text(
streamed_text: str,
@@ -1187,20 +1204,12 @@ class DifyService:
if not is_timeout and attempt < max_retries:
time.sleep(attempt * 2)
continue
if isinstance(e, requests.exceptions.ReadTimeout):
message = (
f"Dify 在 {int(getattr(Config, 'DIFY_CHAT_READ_TIMEOUT_SECONDS', 30) or 30)} 秒内没有返回响应。"
"请检查 Dify 应用地址/API Key、Chatflow 是否发布,以及 Dify 服务是否能正常执行。"
)
elif isinstance(e, requests.exceptions.ConnectTimeout):
message = "连接 Dify 超时,请检查 Dify API Base URL 和网络连通性。"
else:
message = str(e)
message = DifyService._friendly_stream_request_failure_message(e)
# [STEP 4] 错误事件与持久化对象必须是同一个 dict,确保 chat_log_id 能继续传给 relay/领域 Handler。
error_event = {
'event': 'error',
'conversation_id': normalized_conversation_id,
'answer': f"[Error: {message}]",
'answer': message,
'message': message,
'metadata': {},
}