feat(deps): 引入 filetype 库替代废弃的 imghdr

为了应对 Python 3.13 中 `imghdr` 库被废弃的问题,本项目引入 `filetype` 库作为替代方案。

`filetype` 提供了更现代、更可靠的文件类型推断功能。本次更新已将 `content_service.py` 中用于识别图片格式的逻辑从 `imghdr` 切换到 `filetype`,并相应地更新了 `pyproject.toml` 和 `requirements.txt` 依赖文件。

哎呀,`imghdr` 那个老古董总算是要被淘汰了,再不换掉,迟早要变成历史遗留问题。哼,这种事情还得我来提醒主人,真是让人操心。
This commit is contained in:
minecraft1024a
2025-11-08 20:30:11 +08:00
parent e418b83419
commit c5f1d6610d
3 changed files with 6 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ dependencies = [
"faiss-cpu>=1.11.0", "faiss-cpu>=1.11.0",
"fastapi>=0.116.0", "fastapi>=0.116.0",
"google>=3.0.0", "google>=3.0.0",
"filetype>=1.2.0",
"google-genai>=1.29.0", "google-genai>=1.29.0",
"httpx>=0.28.1", "httpx>=0.28.1",
"json-repair>=0.47.6", "json-repair>=0.47.6",

View File

@@ -11,6 +11,7 @@ dotenv
faiss-cpu faiss-cpu
fastapi fastapi
fastmcp fastmcp
filetype
rjieba rjieba
jsonlines jsonlines
maim_message maim_message

View File

@@ -6,7 +6,7 @@
import asyncio import asyncio
import base64 import base64
import datetime import datetime
import imghdr import filetype
from collections.abc import Callable from collections.abc import Callable
import aiohttp import aiohttp
@@ -238,11 +238,11 @@ class ContentService:
continue continue
image_bytes = await resp.read() image_bytes = await resp.read()
image_format = imghdr.what(None, image_bytes) kind = filetype.guess(image_bytes)
if not image_format: if kind is None:
logger.error(f"无法识别图片格式: {image_url}") logger.error(f"无法识别图片格式: {image_url}")
return None return None
image_format = kind.extension
image_base64 = base64.b64encode(image_bytes).decode("utf-8") image_base64 = base64.b64encode(image_bytes).decode("utf-8")
vision_model_name = self.get_config("models.vision_model", "vlm") vision_model_name = self.get_config("models.vision_model", "vlm")