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:
@@ -19,6 +19,7 @@ dependencies = [
|
||||
"faiss-cpu>=1.11.0",
|
||||
"fastapi>=0.116.0",
|
||||
"google>=3.0.0",
|
||||
"filetype>=1.2.0",
|
||||
"google-genai>=1.29.0",
|
||||
"httpx>=0.28.1",
|
||||
"json-repair>=0.47.6",
|
||||
|
||||
@@ -11,6 +11,7 @@ dotenv
|
||||
faiss-cpu
|
||||
fastapi
|
||||
fastmcp
|
||||
filetype
|
||||
rjieba
|
||||
jsonlines
|
||||
maim_message
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import datetime
|
||||
import imghdr
|
||||
import filetype
|
||||
from collections.abc import Callable
|
||||
|
||||
import aiohttp
|
||||
@@ -238,11 +238,11 @@ class ContentService:
|
||||
continue
|
||||
image_bytes = await resp.read()
|
||||
|
||||
image_format = imghdr.what(None, image_bytes)
|
||||
if not image_format:
|
||||
kind = filetype.guess(image_bytes)
|
||||
if kind is None:
|
||||
logger.error(f"无法识别图片格式: {image_url}")
|
||||
return None
|
||||
|
||||
image_format = kind.extension
|
||||
image_base64 = base64.b64encode(image_bytes).decode("utf-8")
|
||||
|
||||
vision_model_name = self.get_config("models.vision_model", "vlm")
|
||||
|
||||
Reference in New Issue
Block a user