Repository navigation
feat(serve): GET /v1/models reports certified thresholds and context - #64
Conversation
Reviewer's GuideThe PR extends GET /v1/models with optional certified calibration thresholds and context-management metadata, using the existing certification logic and suppressing certification for mismatched calibrations. It preserves models_payload compatibility, documents the response contract, and adds focused unit and HTTP coverage. Sequence diagram for GET /v1/models metadata enrichmentsequenceDiagram
participant Client
participant Server
participant Calibration
Client->>Server: GET /v1/models
Server->>Calibration: certified_table(cal)
Calibration-->>Server: certified thresholds by target and question type
Server-->>Client: models_payload(..., certified, context)
Note over Server,Client: Response includes context limit, overflow, and truncate_head
Flow diagram for certification metadata eligibilityflowchart TD
A[GET /v1/models] --> B{Calibration matches served model?}
B -->|No| C[Omit certified]
B -->|Yes| D["certified_table(cal)"]
D --> E[Report thresholds by max_error and question type]
C --> F[Report context metadata]
E --> F
F --> G[Return model metadata]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="basal/server.py" line_range="321" />
<code_context>
+ what a client needs to tell automatable decisions from those to review."""
+ table = {}
+ for target in (cal.get("thresholds") or {}):
+ row = {t: c for t in ("choice", "noul", "score") if (c := certified(cal, float(target), t)) is not None}
+ if row:
+ table[target] = row
</code_context>
<issue_to_address>
**Model metadata requests fail**
When a loaded calibration contains a nonnumeric key under `thresholds`, `check_calibration` does not validate threshold keys, so `certified_table` calls `float(target)` and raises `ValueError`; `GET /v1/models` returns 500 instead of model metadata.
Validate threshold keys when loading the calibration or handle nonnumeric keys in `certified_table` without raising.
</issue_to_address>
### Comment 2
<location path="basal/server.py" line_range="1657" />
<code_context>
- getattr(srv, "layout", None)))
+ getattr(srv, "layout", None),
+ certified=None if getattr(srv, "cal_mismatch", None) else
+ certified_table(srv.cal),
+ context={"limit": srv.context[0] if srv.context else None,
+ "overflow": srv.overflow, "truncate_head": srv.trunc_head}))
</code_context>
<issue_to_address>
**Invalid calibration appears empty**
When the calibration has mismatched layout or option orders but no model or revision mismatch, `load_calibration` strips the thresholds and sets `cal_unvalidated`, but `models()` checks only `cal_mismatch` before calling `certified_table`; the response includes `"certified": {}` instead of omitting the field, so clients cannot distinguish an invalid calibration from a matching calibration with no thresholds.
Have `models()` omit `certified` when the calibration is marked `cal_unvalidated`, as well as when it has a `cal_mismatch`.
</issue_to_address>| what a client needs to tell automatable decisions from those to review.""" | ||
| table = {} | ||
| for target in (cal.get("thresholds") or {}): | ||
| row = {t: c for t in ("choice", "noul", "score") if (c := certified(cal, float(target), t)) is not None} |
There was a problem hiding this comment.
🟡 Medium · Model metadata requests fail
When a loaded calibration contains a nonnumeric key under thresholds, check_calibration does not validate threshold keys, so certified_table calls float(target) and raises ValueError; GET /v1/models returns 500 instead of model metadata.
Validate threshold keys when loading the calibration or handle nonnumeric keys in certified_table without raising.
Prompt for AI agents
In `basal/server.py` at line 321:
**Model metadata requests fail**
When a loaded calibration contains a nonnumeric key under `thresholds`, `check_calibration` does not validate threshold keys, so `certified_table` calls `float(target)` and raises `ValueError`; `GET /v1/models` returns 500 instead of model metadata.
Validate threshold keys when loading the calibration or handle nonnumeric keys in `certified_table` without raising.| getattr(srv, "layout", None))) | ||
| getattr(srv, "layout", None), | ||
| certified=None if getattr(srv, "cal_mismatch", None) else | ||
| certified_table(srv.cal), |
There was a problem hiding this comment.
🟡 Medium · Invalid calibration appears empty
When the calibration has mismatched layout or option orders but no model or revision mismatch, load_calibration strips the thresholds and sets cal_unvalidated, but models() checks only cal_mismatch before calling certified_table; the response includes "certified": {} instead of omitting the field, so clients cannot distinguish an invalid calibration from a matching calibration with no thresholds.
Have models() omit certified when the calibration is marked cal_unvalidated, as well as when it has a cal_mismatch.
Prompt for AI agents
In `basal/server.py` at line 1657:
**Invalid calibration appears empty**
When the calibration has mismatched layout or option orders but no model or revision mismatch, `load_calibration` strips the thresholds and sets `cal_unvalidated`, but `models()` checks only `cal_mismatch` before calling `certified_table`; the response includes `"certified": {}` instead of omitting the field, so clients cannot distinguish an invalid calibration from a matching calibration with no thresholds.
Have `models()` omit `certified` when the calibration is marked `cal_unvalidated`, as well as when it has a `cal_mismatch`.|
Thank you, Paweł! Planned for basal 2.5: we are merging this into the 2.5 release branch now, after our checks (full CPU suite; |
… version CONTRIBUTING.md credits the 2.5 pull requests as the release notes' community line lists them (Paweł Kiszczak #52, #62, #64, #66, #68, #71, #73, #75; Marcin Brzeżański #56; Grzegorz Brzezinka #76, #78) and adds Dariusz Koryto (#53, #58, #59, #60 and #55); the README's list names him too. docs/changes/README.md and the changelog.py help use 2.5.1, the next release, as the example.
Closes #63
What
Adds
certified_table(cal)using the existingcertifiedhelper./v1/modelsreports certified thresholds for matching calibrations and the server's context limit, overflow policy, and truncation head share.Why
Clients can make informed automation and prompt-sizing decisions from the serving metadata alone.
Compatibility
Existing
models_payloadcallers remain compatible; the new optional fields are absent unless supplied. The endpoint addscertifiedandcontextfields. All existing model metadata remains unchanged. A mismatched calibration omitscertified; a server with no thresholds reports an empty table.Tests run
uv run --no-sync pytest -q tests/test_server.py tests/test_http_status.py: 79 passed.uv run --no-sync pytest -q -x: 763 passed, 53 skipped, 1 warning.uvx [email protected] check --select E9,F63,F7,F82 --target-version py310 .: failed on existingbasal/gemma4.py:471undefined namekpos, outside this change.Summary by Sourcery
Publish calibration confidence thresholds and context limits through the model-serving metadata endpoint.
New Features:
Enhancements:
Documentation:
Tests: