feat: 补全模型能力选项(11种) + 按能力指定默认模型 + Auto自动模式

This commit is contained in:
qyyfw committed 2026-07-10 20:04:38 +08:00
1 parent 176cb35b54
commit 4c372746d5
6 files changed
+1408 -966

No files matched your search

+12 -5
View File
@@ -27,6 +27,7 @@ from ..models import (
)
from ..auth import get_current_user
from ..middleware.log_service import LogService
from ..capability_registry import resolve_auto_model
router = APIRouter()
@@ -981,9 +982,14 @@ async def send_message(
ai_model = None
skills = [] # 初始化避免UnboundLocalError
agents = [] # 初始化避免UnboundLocalError
if model_id:
# 解析模型:支持 Auto 模式(model_id='auto' 或未指定时,按能力自动匹配平台默认模型)
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)
if ai_model:
# ====== 图像/视频生成模型分支 ======
caps = [c.lower() for c in (ai_model.capabilities or [])] if ai_model else []
if ai_model and ("image" in caps or "video" in caps):
@@ -1137,7 +1143,7 @@ async def send_message(
else:
ai_content = "请选择一个已配置的AI模型进行对话。"
else:
ai_content = "请先在聊天设置中选择一个AI模型。"
ai_content = "请先在后台管理-大模型库配置默认对话模型(或聊天中选择模型),Auto 模式下将自动使用平台默认模型。"
ai_token_count = len(ai_content) // 2
ai_msg = Message(
@@ -1146,7 +1152,7 @@ async def send_message(
role="assistant",
content=ai_content,
token_used=ai_token_count,
model_id=req.model_id or conv.model_id,
model_id=ai_model.id if ai_model else (req.model_id or conv.model_id),
skill_ids=req.skill_ids if req.skill_ids else None,
agent_ids=req.agent_ids if req.agent_ids else None,
knowledge_ids=req.knowledge_base_ids if req.knowledge_base_ids else None,
@@ -1168,8 +1174,8 @@ async def send_message(
token_usage = TokenUsageLog(
id=gen_uuid(),
user_id=current_user.id,
model_id=req.model_id or conv.model_id,
model_name=ai_model.name if model_id and ai_model else None,
model_id=ai_model.id if ai_model else (req.model_id or conv.model_id),
model_name=ai_model.name if ai_model else None,
conversation_id=conv_id,
prompt_tokens=prompt_tokens or len(req.content) // 2,
completion_tokens=completion_tokens or ai_token_count,
@@ -1454,3 +1460,4 @@ def get_models(db: Session = Depends(get_db)):
})
result.sort(key=lambda x: (0 if x["is_default"] else 1, x["name"]))
return {"code": 0, "data": result, "message": "ok"}