Align user chat with agent model flow
This commit is contained in:
@@ -10,7 +10,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.models.ai_config import ModelConfig
|
||||
from app.models.ai_config import ModelConfig, SystemConfig
|
||||
from app.services.external_errors import ExternalServiceError
|
||||
from app.services.rag_service import NO_HIT_ANSWER, RagResult
|
||||
|
||||
@@ -27,17 +27,19 @@ class ModelCompletion:
|
||||
class ModelClientService:
|
||||
@staticmethod
|
||||
def complete(db: Session, rag_result: RagResult) -> ModelCompletion:
|
||||
mock_model_enabled = _system_config_bool(db, "mock_model_enabled", get_settings().mock_model_enabled)
|
||||
model = db.scalar(
|
||||
select(ModelConfig)
|
||||
.where(ModelConfig.enabled == 1)
|
||||
.order_by(ModelConfig.id.desc())
|
||||
.limit(1)
|
||||
)
|
||||
settings = get_settings()
|
||||
if settings.mock_model_enabled or model is None:
|
||||
if mock_model_enabled:
|
||||
model_name = model.model_name if model is not None else "mock-model"
|
||||
answer = _mock_answer(rag_result)
|
||||
else:
|
||||
if model is None:
|
||||
raise ExternalServiceError("未启用可用模型,请先在模型管理中启用一个模型。", provider="model")
|
||||
model_name = model.model_name
|
||||
answer = _call_configured_model(model, rag_result)
|
||||
|
||||
@@ -92,6 +94,13 @@ def _mock_answer(rag_result: RagResult) -> str:
|
||||
)
|
||||
|
||||
|
||||
def _system_config_bool(db: Session, key: str, default: bool) -> bool:
|
||||
config = db.scalar(select(SystemConfig).where(SystemConfig.config_key == key))
|
||||
if config is None or not config.config_value.strip():
|
||||
return default
|
||||
return config.config_value.strip().lower() in {"1", "true", "yes", "on", "启用"}
|
||||
|
||||
|
||||
def _copy_model_with_overrides(model: ModelConfig, overrides: dict[str, Any]) -> ModelConfig:
|
||||
debug_model = ModelConfig(
|
||||
provider=model.provider,
|
||||
|
||||
Reference in New Issue
Block a user