main
py 63 lines 1.7 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5 import asyncio
6 import functools
7 from typing import Annotated, Literal
8
9 import pydantic
10 from fastapi import APIRouter, FastAPI, Query, Request
11 from fastapi.responses import JSONResponse
12
13 import vllm.envs as envs
14 from vllm.collect_env import get_env_info
15 from vllm.config import VllmConfig
16 from vllm.logger import init_logger
17
18 logger = init_logger(__name__)
19
20
21 router = APIRouter()
22 PydanticVllmConfig = pydantic.TypeAdapter(VllmConfig)
23
24
25 def _get_vllm_env_vars():
26 from vllm.config.utils import normalize_value
27
28 vllm_envs = {}
29 for key in dir(envs):
30 if key.startswith("VLLM_") and "KEY" not in key:
31 value = getattr(envs, key, None)
32 if value is not None:
33 value = normalize_value(value)
34 vllm_envs[key] = value
35 return vllm_envs
36
37
38 @functools.lru_cache(maxsize=1)
39 def _get_system_env_info_cached():
40 return get_env_info()._asdict()
41
42
43 @router.get("/server_info")
44 async def show_server_info(
45 raw_request: Request,
46 config_format: Annotated[Literal["text", "json"], Query()] = "text",
47 ):
48 vllm_config: VllmConfig = raw_request.app.state.vllm_config
49 server_info = {
50 "vllm_config": (
51 str(vllm_config)
52 if config_format == "text"
53 else PydanticVllmConfig.dump_python(vllm_config, mode="json", fallback=str)
54 ),
55 # fallback=str is needed to handle e.g. torch.dtype
56 "vllm_env": _get_vllm_env_vars(),
57 "system_env": await asyncio.to_thread(_get_system_env_info_cached),
58 }
59 return JSONResponse(content=server_info)
60
61
62 def attach_router(app: FastAPI):
63 app.include_router(router)