修复斗鱼日报Dify 400请求并增强错误诊断
变更项:\n1. 在斗鱼插件新增 daily_report_include_structured_inputs 配置(默认 false),Dify 入参默认改为精简字段(task_type/query/system_prompt/user_prompt/room_id 等),避免复杂对象输入触发 400。\n2. 调整 _build_dify_daily_report_inputs:仅在 include_structured_inputs=true 时才附带 report_payload_json,大幅降低 Workflow 入参类型不匹配风险。\n3. 在初始化流程中读取 report_api.include_structured_inputs,支持按环境开关结构化入参。\n4. 在 UnifiedLLMClient 的 Dify 调用中新增 HTTPError 细粒度处理,last_error 与日志会追加 response_body 片段,便于快速定位 Dify 侧具体报错原因。\n5. 更新 douyu 配置模板注释,明确复杂输入导致 400 的风险与开关用途,方便后续维护。
This commit is contained in:
@@ -9,6 +9,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import requests
|
||||
from requests import HTTPError
|
||||
from loguru import logger
|
||||
|
||||
from utils.ai.llm_registry import LLMRegistry
|
||||
@@ -282,6 +283,23 @@ class UnifiedLLMClient:
|
||||
if parsed and parsed.get("text"):
|
||||
return parsed
|
||||
self.last_error = f"empty_model_output:{self.mode}"
|
||||
except HTTPError as exc:
|
||||
# 诊断增强:
|
||||
# 1. Dify 返回 400 时,异常信息默认只包含状态码和 URL,不含具体原因;
|
||||
# 2. 这里把响应体片段追加到 last_error,便于快速定位“入参字段/类型”问题。
|
||||
response_text = ""
|
||||
response_obj = getattr(exc, "response", None)
|
||||
if response_obj is not None:
|
||||
try:
|
||||
response_text = str(response_obj.text or "").strip()
|
||||
except Exception:
|
||||
response_text = ""
|
||||
response_text = response_text[:500] if response_text else ""
|
||||
self.last_error = (
|
||||
f"request_failed:attempt_{attempt}:{exc}"
|
||||
+ (f" | response_body={response_text}" if response_text else "")
|
||||
)
|
||||
self.LOG.warning(f"[UnifiedLLMClient] Dify 请求失败: tag={tag}, attempt={attempt}, error={self.last_error}")
|
||||
except Exception as exc:
|
||||
self.last_error = f"request_failed:attempt_{attempt}:{exc}"
|
||||
self.LOG.warning(f"[UnifiedLLMClient] Dify 请求失败: tag={tag}, attempt={attempt}, error={exc}")
|
||||
|
||||
Reference in New Issue
Block a user