feat: restore core admin modules and harden ai model fallback

This commit is contained in:
2026-06-22 01:21:01 +08:00
parent f180fff020
commit 524c027a4a
15 changed files with 1896 additions and 21 deletions
@@ -10,7 +10,7 @@ from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from ai_platform.models import (
Agent, AgentConversation, AgentMessage, AIWorkflow, LLMModel,
Agent, AgentConversation, AgentMessage, AIWorkflow, LLMModel, LLMProvider,
)
from .llm_service import LLMService
@@ -212,10 +212,14 @@ class AgentService:
if agent.model_id:
result = await self._db.execute(
select(LLMModel).where(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.id == agent.model_id,
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
)
if result.scalar_one_or_none():
@@ -223,10 +227,13 @@ class AgentService:
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
@@ -44,14 +44,17 @@ class LLMService:
if not self._db:
raise ValueError("未找到可用的 chat 模型,请先在模型配置中启用一个模型")
from ai_platform.models import LLMModel
from ai_platform.models import LLMModel, LLMProvider
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_deleted == False,
LLMModel.is_active == True,
LLMModel.model_type == "chat",
LLMProvider.is_deleted == False,
LLMProvider.is_active == True,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)