|
11 | 11 | from api.deps import get_system_config_service |
12 | 12 | from api.v1.schemas.common import ErrorResponse |
13 | 13 | from api.v1.schemas.system_config import ( |
| 14 | + DiscoverLLMChannelModelsRequest, |
| 15 | + DiscoverLLMChannelModelsResponse, |
14 | 16 | ExportSystemConfigResponse, |
15 | 17 | ImportSystemConfigRequest, |
16 | 18 | SystemConfigConflictResponse, |
@@ -313,6 +315,50 @@ def test_llm_channel( |
313 | 315 | ) |
314 | 316 |
|
315 | 317 |
|
| 318 | +@router.post( |
| 319 | + "/config/llm/discover-models", |
| 320 | + response_model=DiscoverLLMChannelModelsResponse, |
| 321 | + responses={ |
| 322 | + 200: {"description": "Model discovery completed"}, |
| 323 | + 500: {"description": "Internal server error", "model": ErrorResponse}, |
| 324 | + }, |
| 325 | + summary="Discover models for one LLM channel", |
| 326 | + description="Call one unsaved or saved channel's `/models` endpoint and return discovered model IDs.", |
| 327 | +) |
| 328 | +def discover_llm_channel_models( |
| 329 | + request: DiscoverLLMChannelModelsRequest, |
| 330 | + service: SystemConfigService = Depends(get_system_config_service), |
| 331 | +) -> DiscoverLLMChannelModelsResponse: |
| 332 | + """Discover models for one channel definition without writing `.env`.""" |
| 333 | + try: |
| 334 | + payload = service.discover_llm_channel_models( |
| 335 | + name=request.name, |
| 336 | + protocol=request.protocol, |
| 337 | + base_url=request.base_url, |
| 338 | + api_key=request.api_key, |
| 339 | + models=request.models, |
| 340 | + timeout_seconds=request.timeout_seconds, |
| 341 | + ) |
| 342 | + return DiscoverLLMChannelModelsResponse.model_validate(payload) |
| 343 | + except (ValueError, TypeError) as exc: |
| 344 | + raise HTTPException( |
| 345 | + status_code=422, |
| 346 | + detail={ |
| 347 | + "error": "validation_error", |
| 348 | + "message": str(exc), |
| 349 | + }, |
| 350 | + ) |
| 351 | + except Exception as exc: |
| 352 | + logger.error("Failed to discover LLM channel models: %s", exc, exc_info=True) |
| 353 | + raise HTTPException( |
| 354 | + status_code=500, |
| 355 | + detail={ |
| 356 | + "error": "internal_error", |
| 357 | + "message": "Failed to discover LLM channel models", |
| 358 | + }, |
| 359 | + ) |
| 360 | + |
| 361 | + |
316 | 362 | @router.get( |
317 | 363 | "/config/schema", |
318 | 364 | response_model=SystemConfigSchemaResponse, |
|
0 commit comments