feat: Enhance emoji and image management with asynchronous background processing

- Added support for scheduling background tasks to build emoji and image descriptions when not found in cache.
- Improved error handling and logging for emoji and image processing.
- Updated `SessionMessage` processing to allow for optional heavy media analysis and voice transcription.
- Refactored logging messages for better clarity and consistency across various modules.
- Introduced a new function to build outbound log previews for messages, enhancing logging capabilities.
This commit is contained in:
DrSmoothl
2026-03-26 23:03:47 +08:00
parent 777d4cb0d2
commit 0a08973c41
17 changed files with 488 additions and 167 deletions

View File

@@ -627,7 +627,7 @@ class GeminiClient(AdapterClient[AsyncIterator[GenerateContentResponse], Generat
try:
thinking_budget = int(extra_params["thinking_budget"])
except (TypeError, ValueError):
logger.warning("无效的 thinking_budget=%s,已回退为自动模式", extra_params["thinking_budget"])
logger.warning(f"无效的 thinking_budget={extra_params['thinking_budget']},已回退为自动模式")
limits: Dict[str, int | bool] | None = None
if model_id in THINKING_BUDGET_LIMITS:
@@ -646,21 +646,21 @@ class GeminiClient(AdapterClient[AsyncIterator[GenerateContentResponse], Generat
return THINKING_BUDGET_DISABLED
if limits:
minimum_value = int(limits["min"])
logger.warning("模型 %s 不支持禁用思考预算,已回退为最小值 %s", model_id, minimum_value)
logger.warning(f"模型 {model_id} 不支持禁用思考预算,已回退为最小值 {minimum_value}")
return minimum_value
return THINKING_BUDGET_AUTO
if limits is None:
logger.warning("模型 %s 未配置思考预算范围,已回退为自动模式", model_id)
logger.warning(f"模型 {model_id} 未配置思考预算范围,已回退为自动模式")
return THINKING_BUDGET_AUTO
minimum_value = int(limits["min"])
maximum_value = int(limits["max"])
if thinking_budget < minimum_value:
logger.warning("模型 %s 的 thinking_budget=%s 过小,已调整为 %s", model_id, thinking_budget, minimum_value)
logger.warning(f"模型 {model_id} 的 thinking_budget={thinking_budget} 过小,已调整为 {minimum_value}")
return minimum_value
if thinking_budget > maximum_value:
logger.warning("模型 %s 的 thinking_budget=%s 过大,已调整为 %s", model_id, thinking_budget, maximum_value)
logger.warning(f"模型 {model_id} 的 thinking_budget={thinking_budget} 过大,已调整为 {maximum_value}")
return maximum_value
return thinking_budget

View File

@@ -103,7 +103,7 @@ def _normalize_reasoning_parse_mode(parse_mode: str | ReasoningParseMode) -> Rea
try:
return ReasoningParseMode(parse_mode)
except ValueError:
logger.warning("未识别的推理解析模式 %s,已回退为 auto", parse_mode)
logger.warning(f"未识别的推理解析模式 {parse_mode},已回退为 auto")
return ReasoningParseMode.AUTO
@@ -121,7 +121,7 @@ def _normalize_tool_argument_parse_mode(parse_mode: str | ToolArgumentParseMode)
try:
return ToolArgumentParseMode(parse_mode)
except ValueError:
logger.warning("未识别的工具参数解析模式 %s,已回退为 auto", parse_mode)
logger.warning(f"未识别的工具参数解析模式 {parse_mode},已回退为 auto")
return ToolArgumentParseMode.AUTO
@@ -425,7 +425,7 @@ def _log_length_truncation(finish_reason: str | None, model_name: str | None) ->
model_name: 上游返回的模型标识。
"""
if finish_reason == "length":
logger.info("模型%s因为超过最大 max_token 限制,可能仅输出部分内容,可视情况调整", model_name or "")
logger.info(f"模型{model_name or ''}因为超过最大 max_token 限制,可能仅输出部分内容,可视情况调整")
def _coerce_openai_argument(value: Any) -> Any | Omit: