Skip to content

Commit 1e51daa

Browse files
authored
Merge pull request lightspeed-core#375 from tisnik/docstrings-for-endpoints-1
Docstrings for endpoints handlers
2 parents 920f071 + 61f917e commit 1e51daa

5 files changed

Lines changed: 55 additions & 8 deletions

File tree

src/app/endpoints/authorized.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@
3333
async def authorized_endpoint_handler(
3434
auth: Any = Depends(auth_dependency),
3535
) -> AuthorizedResponse:
36-
"""Handle request to the /authorized endpoint."""
36+
"""
37+
Handle request to the /authorized endpoint.
38+
39+
Process POST requests to the /authorized endpoint, returning
40+
the authenticated user's ID and username.
41+
42+
Returns:
43+
AuthorizedResponse: Contains the user ID and username of the authenticated user.
44+
"""
3745
# Ignore the user token, we should not return it in the response
3846
user_id, user_name, _ = auth
3947
return AuthorizedResponse(user_id=user_id, username=user_name)

src/app/endpoints/config.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@
5757

5858
@router.get("/config", responses=get_config_responses)
5959
def config_endpoint_handler(_request: Request) -> Configuration:
60-
"""Handle requests to the /config endpoint."""
60+
"""
61+
Handle requests to the /config endpoint.
62+
63+
Process GET requests to the /config endpoint and returns the
64+
current service configuration.
65+
66+
Returns:
67+
Configuration: The loaded service configuration object.
68+
"""
6169
# ensure that configuration is loaded
6270
check_configuration_loaded(configuration)
6371

src/app/endpoints/health.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323

2424

2525
async def get_providers_health_statuses() -> list[ProviderHealthStatus]:
26-
"""Check health of all providers.
26+
"""
27+
Retrieve the health status of all configured providers.
2728
2829
Returns:
29-
List of provider health statuses.
30+
list[ProviderHealthStatus]: A list containing the health
31+
status of each provider. If provider health cannot be
32+
determined, returns a single entry indicating an error.
3033
"""
3134
try:
3235
client = AsyncLlamaStackClientHolder().get_client()
@@ -70,7 +73,13 @@ async def get_providers_health_statuses() -> list[ProviderHealthStatus]:
7073

7174
@router.get("/readiness", responses=get_readiness_responses)
7275
async def readiness_probe_get_method(response: Response) -> ReadinessResponse:
73-
"""Ready status of service with provider health details."""
76+
"""
77+
Handle the readiness probe endpoint, returning service readiness.
78+
79+
If any provider reports an error status, responds with HTTP 503
80+
and details of unhealthy providers; otherwise, indicates the
81+
service is ready.
82+
"""
7483
provider_statuses = await get_providers_health_statuses()
7584

7685
# Check if any provider is unhealthy (not counting not_implemented as unhealthy)
@@ -104,5 +113,10 @@ async def readiness_probe_get_method(response: Response) -> ReadinessResponse:
104113

105114
@router.get("/liveness", responses=get_liveness_responses)
106115
def liveness_probe_get_method() -> LivenessResponse:
107-
"""Live status of service."""
116+
"""
117+
Return the liveness status of the service.
118+
119+
Returns:
120+
LivenessResponse: Indicates that the service is alive.
121+
"""
108122
return LivenessResponse(alive=True)

src/app/endpoints/info.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,13 @@
2323

2424
@router.get("/info", responses=get_info_responses)
2525
def info_endpoint_handler(_request: Request) -> InfoResponse:
26-
"""Handle request to the /info endpoint."""
26+
"""
27+
Handle request to the /info endpoint.
28+
29+
Process GET requests to the /info endpoint, returning the
30+
service name and version.
31+
32+
Returns:
33+
InfoResponse: An object containing the service's name and version.
34+
"""
2735
return InfoResponse(name=configuration.configuration.name, version=__version__)

src/app/endpoints/metrics.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
@router.get("/metrics", response_class=PlainTextResponse)
1616
async def metrics_endpoint_handler(_request: Request) -> PlainTextResponse:
17-
"""Handle request to the /metrics endpoint."""
17+
"""
18+
Handle request to the /metrics endpoint.
19+
20+
Process GET requests to the /metrics endpoint, returning the
21+
latest Prometheus metrics in form of a plain text.
22+
23+
Initializes model metrics on the first request if not already
24+
set up, then responds with the current metrics snapshot in
25+
Prometheus format.
26+
"""
1827
# Setup the model metrics if not already done. This is a one-time setup
1928
# and will not be run again on subsequent calls to this endpoint
2029
await setup_model_metrics()

0 commit comments

Comments
 (0)