From f5968d0f61f1fd608930133142a55bff0eef69c6 Mon Sep 17 00:00:00 2001 From: qyyfw Date: Fri, 10 Jul 2026 22:04:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Auto=E6=A8=A1=E5=BC=8F=E6=8C=89?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=E6=84=8F=E5=9B=BE=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E8=B7=AF=E7=94=B1=E8=A7=86=E9=A2=91/=E5=9B=BE?= =?UTF-8?q?=E5=83=8F/=E8=AF=AD=E9=9F=B3=E7=94=9F=E6=88=90=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/python/app/api/chat.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/backend/python/app/api/chat.py b/backend/python/app/api/chat.py index 5977c40..5df16c5 100644 --- a/backend/python/app/api/chat.py +++ b/backend/python/app/api/chat.py @@ -33,6 +33,30 @@ router = APIRouter() logger = logging.getLogger(__name__) + +def detect_media_intent(text: str) -> str | None: + """根据用户输入判断是否为 图像/视频/语音 生成请求,返回对应能力或 None。 + + 用于 Auto 模式:用户未指定具体模型时,依据意图自动匹配平台各类能力的默认模型。 + 疑问句(含「吗/呢/怎么/能否」或结尾问号)不触发,避免「你能生成视频吗」被误判。 + """ + if not text: + return None + t = text.lower().strip() + # 疑问句不触发媒体生成 + if t.endswith(("?", "?")) or any(q in t for q in ("吗", "呢", "怎么", "如何", "能否", "是否可以", "可以吗", "会不会", "why", "how")): + return None + video_kw = ("视频", "短片", "影片", "vide", "动画视频", "一段视频", "做个视频", "生成视频") + image_kw = ("图片", "图像", "插画", "海报", "照片", "imag", "画一张", "画个", "生成图片", "一张图", "一幅画", "生成一幅") + audio_kw = ("语音", "配音", "朗读", "播报", "念一段", "有声", "tts", "音频", "生成语音") + if any(k in t for k in video_kw): + return "video" + if any(k in t for k in image_kw): + return "image" + if any(k in t for k in audio_kw): + return "audio" + return None + # CST timezone (UTC+8) for consistent time display CST_TZ = timezone(timedelta(hours=8)) @@ -986,8 +1010,10 @@ async def send_message( if model_id and model_id != "auto": ai_model = db.query(AIModel).filter(AIModel.id == model_id).first() if not ai_model: - # Auto / 未指定 → 使用平台默认对话模型(文本能力默认) - ai_model = resolve_auto_model("text", db) + # Auto / 未指定 → 按用户输入意图匹配对应能力的默认模型,否则回退文本对话 + intent = detect_media_intent(req.content) + resolved = resolve_auto_model(intent, db) if intent else None + ai_model = resolved or resolve_auto_model("text", db) if ai_model: # ====== 图像/视频生成模型分支 ======