mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-14 09:03:16 +00:00
feat(proxy): add GET /version endpoint
Per review: - Read the version directly from litellm._version instead of importing proxy_server (which re-exports it); the fallback test now patches _version accordingly. - Tag the route with ["public", "version"] so it groups with the other public endpoints in the OpenAPI docs.
This commit is contained in:
parent
88e03e5487
commit
f82ca8cded
5 changed files with 48 additions and 0 deletions
|
|
@ -655,6 +655,7 @@ class LiteLLMRoutes(enum.Enum):
|
|||
"/public/mcp_hub",
|
||||
"/public/skill_hub",
|
||||
"/public/litellm_model_cost_map",
|
||||
"/version",
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ from litellm.types.proxy.public_endpoints.public_endpoints import (
|
|||
ProviderCreateInfo,
|
||||
PublicModelHubInfo,
|
||||
SupportedEndpointsResponse,
|
||||
VersionResponse,
|
||||
)
|
||||
from litellm.types.utils import LlmProviders
|
||||
|
||||
|
|
@ -287,6 +288,13 @@ async def public_skill_hub():
|
|||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/version", tags=["public", "version"], response_model=VersionResponse)
|
||||
async def version_info() -> VersionResponse:
|
||||
from litellm._version import version
|
||||
|
||||
return VersionResponse(version=version)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/public/model_hub/info",
|
||||
tags=["public", "model management"],
|
||||
|
|
|
|||
|
|
@ -68,3 +68,7 @@ class SupportedEndpoint(BaseModel):
|
|||
|
||||
class SupportedEndpointsResponse(BaseModel):
|
||||
endpoints: List[SupportedEndpoint]
|
||||
|
||||
|
||||
class VersionResponse(BaseModel):
|
||||
version: str
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ def test_public_ai_hub_routes_remain_public():
|
|||
"/public/agent_hub",
|
||||
"/public/mcp_hub",
|
||||
"/public/skill_hub",
|
||||
"/version",
|
||||
):
|
||||
assert route in LiteLLMRoutes.public_routes.value
|
||||
assert _route_requires_auth_despite_public(route, {}) is False
|
||||
|
|
|
|||
|
|
@ -91,6 +91,40 @@ def test_get_litellm_model_cost_map_returns_cost_map():
|
|||
)
|
||||
|
||||
|
||||
def test_version_endpoint():
|
||||
import litellm._version as _ver
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
client = TestClient(app)
|
||||
|
||||
response = client.get("/version")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert isinstance(body, dict)
|
||||
assert "version" in body
|
||||
assert isinstance(body["version"], str)
|
||||
assert body["version"] == _ver.version
|
||||
|
||||
|
||||
@pytest.mark.parametrize("fake_version", ["unknown", "0.0.0"])
|
||||
def test_version_endpoint_fallback_strings_still_return_200(fake_version: str):
|
||||
import litellm._version as _ver
|
||||
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
client = TestClient(app)
|
||||
|
||||
with patch.object(_ver, "version", fake_version):
|
||||
response = client.get("/version")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["version"] == fake_version
|
||||
assert isinstance(body["version"], str)
|
||||
|
||||
|
||||
def test_public_ai_hub_info_is_public_by_default(monkeypatch):
|
||||
app = FastAPI()
|
||||
app.include_router(router)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue