feat: restore core chat and observability

This commit is contained in:
2026-06-22 02:24:10 +08:00
parent 524c027a4a
commit 705cfe47e8
43 changed files with 12301 additions and 11 deletions
@@ -8,7 +8,7 @@ from typing import AsyncGenerator, Dict, List, Optional
from sqlalchemy import select, func
from sqlalchemy.ext.asyncio import AsyncSession
from ai_platform.models import AIApp, Conversation, Message, LLMModel
from ai_platform.models import AIApp, Conversation, Message, LLMModel, LLMProvider
from utils.context import get_current_user_id_from_context
from .llm_service import LLMService
@@ -352,15 +352,33 @@ class ChatService:
async def _get_effective_model(self, conversation: Conversation, app: AIApp) -> Optional[LLMModel]:
"""获取有效的模型"""
model_id = conversation.model_override_id or app.model_id
if not model_id:
return None
result = await self._db.execute(
select(LLMModel).where(
LLMModel.id == model_id,
LLMModel.is_active == True,
LLMModel.is_deleted == False
if model_id:
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.id == model_id,
LLMModel.is_active == True,
LLMModel.is_deleted == False,
LLMProvider.is_active == True,
LLMProvider.is_deleted == False,
)
)
model = result.scalar_one_or_none()
if model:
return model
result = await self._db.execute(
select(LLMModel)
.join(LLMProvider, LLMProvider.id == LLMModel.provider_id)
.where(
LLMModel.is_active == True,
LLMModel.is_deleted == False,
LLMModel.model_type == "chat",
LLMProvider.is_active == True,
LLMProvider.is_deleted == False,
)
.order_by(LLMModel.sort.desc(), LLMModel.sys_create_datetime.desc())
)
return result.scalar_one_or_none()