From 8737002ce625e921badd137155c176d9379d99c6 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 3 Oct 2026 17:34:13 -0700 Subject: [PATCH] perf(lens): strip reviews and run attributes from the lens list and serve reviews separately --- litellm/proxy/lens/endpoints.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/lens/endpoints.py b/litellm/proxy/lens/endpoints.py index 0d27da6e361..107ece46488 100644 --- a/litellm/proxy/lens/endpoints.py +++ b/litellm/proxy/lens/endpoints.py @@ -34,6 +34,7 @@ from litellm.proxy.lens.models import ( ModelResult, Progress, Result, + Review, RunRequest, Sample, Scope, @@ -55,8 +56,10 @@ from litellm.proxy.lens.state import ( next_scan_start, queue_job, replace_job, + reviews_after, scheduled_window, snapshot_finding, + summarized, ) from litellm.proxy.tracing_runtime import provide_storage @@ -199,7 +202,7 @@ async def validate_workers(settings: LensSettings, scope: Scope) -> None: async def list_lenses(auth: Auth, storage: StorageDep) -> LensList: scope: Final = user_scope(auth) return LensList( - lenses=tuple(e for e in await repository().lenses() if can_access(scope, e.scope)), + lenses=tuple(summarized(e) for e in await repository().lenses() if can_access(scope, e.scope)), workers=tuple(w for w in await repository().workers() if can_access(scope, w.scope)), tracing_enabled=storage is not None, ) @@ -329,7 +332,7 @@ async def run_lens(lens_id: str, body: RunRequest, auth: Auth) -> Lens: @router.get("/{lens_id}", response_model=Lens) async def read_lens(lens_id: str, auth: Auth) -> Lens: - return await get_lens(lens_id, user_scope(auth)) + return summarized(await get_lens(lens_id, user_scope(auth))) @router.get("/{lens_id}/runs", response_model=tuple[Job, ...]) @@ -350,6 +353,13 @@ async def read_run(lens_id: str, job_id: str, auth: Auth) -> Job: return job +@router.get("/{lens_id}/runs/{job_id}/reviews", response_model=tuple[Review, ...]) +async def read_reviews( + lens_id: str, job_id: str, auth: Auth, after: Annotated[AwareDatetime | None, Query()] = None +) -> tuple[Review, ...]: + return reviews_after(await read_run(lens_id, job_id, auth), after) + + @router.post("/{lens_id}/cancel", response_model=Lens) async def cancel_lens(lens_id: str, auth: Auth) -> Lens: await get_lens(lens_id, user_scope(auth, write=True))