Skip to content

Commit 6318591

Browse files
populate service_type and purpose on pre-completion availability records
1 parent 2717537 commit 6318591

4 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/mlpa/core/auth/authorize.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ async def authorize_chat_request(
129129
AvailabilityReason.INVALID_SERVICE_TYPE_FOR_MODEL,
130130
model=chat_request.model,
131131
service_type=service_type.value,
132-
# `purpose` is not yet resolved here
133-
# This serves as a placeholder until a validated purpose is available
134-
purpose="",
132+
purpose=(purpose or "").strip(),
135133
)
136134
raise HTTPException(
137135
status_code=400,

src/mlpa/core/middleware/request_size.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ async def check_request_size_middleware(request: Request, call_next):
2121
logger.warning(
2222
f"Request size {size} bytes exceeds maximum {env.MAX_REQUEST_SIZE_BYTES} bytes"
2323
)
24-
# Placeholders for `model`, `service_type`, and `purpose`
25-
# are used since values are not set until the body is parsed
26-
# and auth has run.
24+
# `model` is in the request body, which we don't read here.
25+
# We reject on the Content-Length header without parsing it.
2726
record_chat_availability_for(
2827
AvailabilityReason.PAYLOAD_TOO_LARGE,
2928
model="",
30-
service_type="",
31-
purpose="",
29+
service_type=(
30+
request.headers.get("service-type") or ""
31+
).strip(),
32+
purpose=(request.headers.get("purpose") or "").strip(),
3233
)
3334
return JSONResponse(
3435
status_code=413,

src/tests/integration/test_request_size_limit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def test_request_size_over_limit(mocked_client_integration, metrics_spy):
6767
outcome="excluded",
6868
reason="payload_too_large",
6969
model="",
70-
service_type="",
71-
purpose="",
70+
service_type="ai",
71+
purpose="chat",
7272
)
7373
== 1
7474
)

src/tests/unit/test_precompletion_availability.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def test_wrapper_invalid_service_type_records_excluded(metrics_spy):
119119
AvailabilityReason.INVALID_SERVICE_TYPE_FOR_MODEL,
120120
model="exa",
121121
service_type="ai",
122+
purpose="chat",
122123
)
123124
== 1
124125
)

0 commit comments

Comments
 (0)