返回当前服务支持的模型列表。
()
| 86 | |
| 87 | @router.get("/v1/models") |
| 88 | async def list_models(): |
| 89 | """返回当前服务支持的模型列表。""" |
| 90 | try: |
| 91 | client = get_upstream_client() |
| 92 | current_time = int(time.time()) |
| 93 | response = ModelsResponse( |
| 94 | data=[ |
| 95 | Model(id=model_id, created=current_time, owned_by=settings.SERVICE_NAME) |
| 96 | for model_id in client.get_supported_models() |
| 97 | ] |
| 98 | ) |
| 99 | return JSONResponse(content=response.model_dump(exclude_none=True)) |
| 100 | except Exception as exc: |
| 101 | logger.error(f"❌ 获取模型列表失败: {exc}") |
| 102 | raise HTTPException(status_code=500, detail=f"Failed to list models: {exc}") |
| 103 | |
| 104 | |
| 105 | @router.post("/v1/chat/completions") |
nothing calls this directly
no test coverage detected