Skip to content

Commit dc82f23

Browse files
committed
Llama Stack version in /info endpoint
1 parent 8bd3479 commit dc82f23

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/app/endpoints/info.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import logging
44
from typing import Annotated, Any
55

6-
from fastapi import APIRouter, Request
6+
from fastapi import APIRouter, HTTPException, Request, status
77
from fastapi import Depends
8+
from llama_stack_client import APIConnectionError
89

910
from auth.interface import AuthTuple
11+
from client import AsyncLlamaStackClientHolder
1012
from auth import get_auth_dependency
1113
from authorization.middleware import authorize
1214
from configuration import configuration
@@ -49,4 +51,24 @@ async def info_endpoint_handler(
4951
# Nothing interesting in the request
5052
_ = request
5153

52-
return InfoResponse(name=configuration.configuration.name, version=__version__)
54+
try:
55+
# try to get Llama Stack client
56+
client = AsyncLlamaStackClientHolder().get_client()
57+
# retrieve version
58+
llama_stack_version_object = await client.inspect.version()
59+
llama_stack_version = llama_stack_version_object.version
60+
return InfoResponse(
61+
name=configuration.configuration.name,
62+
service_version=__version__,
63+
llama_stack_version=llama_stack_version,
64+
)
65+
# connection to Llama Stack server
66+
except APIConnectionError as e:
67+
logger.error("Unable to connect to Llama Stack: %s", e)
68+
raise HTTPException(
69+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
70+
detail={
71+
"response": "Unable to connect to Llama Stack",
72+
"cause": str(e),
73+
},
74+
) from e

src/models/responses.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ class InfoResponse(BaseModel):
8484
8585
Attributes:
8686
name: Service name.
87-
version: Service version.
87+
service_version: Service version.
88+
llama_stack_version: Llama Stack version.
8889
8990
Example:
9091
```python
9192
info_response = InfoResponse(
9293
name="Lightspeed Stack",
93-
version="1.0.0",
94+
service_version="1.0.0",
95+
llama_stack_version="0.2.18",
9496
)
9597
```
9698
"""
@@ -100,18 +102,24 @@ class InfoResponse(BaseModel):
100102
examples=["Lightspeed Stack"],
101103
)
102104

103-
version: str = Field(
105+
service_version: str = Field(
104106
description="Service version",
105107
examples=["0.1.0", "0.2.0", "1.0.0"],
106108
)
107109

110+
llama_stack_version: str = Field(
111+
description="Llama Stack version",
112+
examples=["0.2.1", "0.2.2", "0.2.18"],
113+
)
114+
108115
# provides examples for /docs endpoint
109116
model_config = {
110117
"json_schema_extra": {
111118
"examples": [
112119
{
113120
"name": "Lightspeed Stack",
114-
"version": "1.0.0",
121+
"service_version": "1.0.0",
122+
"llama_stack_version": "1.0.0",
115123
}
116124
]
117125
}

0 commit comments

Comments
 (0)