(
session: SessionDep,
id: int = Path(description="ID")
)
| 123 | description=f"{PLACEHOLDER_PREFIX}system_model_query") |
| 124 | @require_permissions(permission=SqlbotPermission(role=['admin'])) |
| 125 | async def get_model_by_id( |
| 126 | session: SessionDep, |
| 127 | id: int = Path(description="ID") |
| 128 | ): |
| 129 | db_model = session.get(AiModelDetail, id) |
| 130 | if not db_model: |
| 131 | raise ValueError(f"AiModelDetail with id {id} not found") |
| 132 | |
| 133 | config_list: List[AiModelConfigItem] = [] |
| 134 | if db_model.config: |
| 135 | try: |
| 136 | raw = json.loads(db_model.config) |
| 137 | config_list = [AiModelConfigItem(**item) for item in raw] |
| 138 | except Exception: |
| 139 | pass |
| 140 | try: |
| 141 | if db_model.api_key: |
| 142 | db_model.api_key = await sqlbot_decrypt(db_model.api_key) |
| 143 | if db_model.api_domain: |
| 144 | db_model.api_domain = await sqlbot_decrypt(db_model.api_domain) |
| 145 | except Exception: |
| 146 | pass |
| 147 | data = AiModelDetail.model_validate(db_model).model_dump(exclude_unset=True) |
| 148 | data.pop("config", None) |
| 149 | data["config_list"] = config_list |
| 150 | return AiModelEditor(**data) |
| 151 | |
| 152 | |
| 153 | @router.post("", summary=f"{PLACEHOLDER_PREFIX}system_model_create", |
nothing calls this directly
no test coverage detected