diff --git a/backend/app/controller/model_controller.py b/backend/app/controller/model_controller.py index 692a7fb2a..db80dd9bf 100644 --- a/backend/app/controller/model_controller.py +++ b/backend/app/controller/model_controller.py @@ -1,6 +1,7 @@ from fastapi import APIRouter, HTTPException -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, field_validator from app.component.model_validation import create_agent +from app.model.chat import PLATFORM_MAPPING from camel.types import ModelType from app.component.error_format import normalize_error_to_openai_format from utils import traceroot_wrapper as traceroot @@ -19,6 +20,11 @@ class ValidateModelRequest(BaseModel): model_config_dict: dict | None = Field(None, description="Model config dict") extra_params: dict | None = Field(None, description="Extra model parameters") + @field_validator("model_platform") + @classmethod + def map_model_platform(cls, v: str) -> str: + return PLATFORM_MAPPING.get(v, v) + class ValidateModelResponse(BaseModel): is_valid: bool = Field(..., description="Is valid") diff --git a/backend/app/model/chat.py b/backend/app/model/chat.py index fc9010839..883cc522d 100644 --- a/backend/app/model/chat.py +++ b/backend/app/model/chat.py @@ -34,6 +34,9 @@ class QuestionAnalysisResult(BaseModel): McpServers = dict[Literal["mcpServers"], dict[str, dict]] +PLATFORM_MAPPING = { + "Z.ai": "openai-compatible-model", +} class Chat(BaseModel): task_id: str @@ -65,6 +68,11 @@ class Chat(BaseModel): extra_params: dict | None = None # For provider-specific parameters like Azure search_config: dict[str, str] | None = None # User-specific search engine configurations (e.g., GOOGLE_API_KEY, SEARCH_ENGINE_ID) + @field_validator("model_platform") + @classmethod + def map_model_platform(cls, v: str) -> str: + return PLATFORM_MAPPING.get(v, v) + @field_validator("model_type") @classmethod def check_model_type(cls, model_type: str):