Skip to content

Commit

Permalink
tweak names and style
Browse files Browse the repository at this point in the history
Signed-off-by: technillogue <technillogue@gmail.com>
  • Loading branch information
technillogue committed Jun 19, 2024
1 parent ee57d1e commit 35167b9
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions python/cog/server/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ async def predict(
respond_async = prefer == "respond-async"

with trace_context(make_trace_context(traceparent, tracestate)):
return _predict(
request=request,
respond_async=respond_async
)
return await shared_predict(request=request, respond_async=respond_async)

@limited
@app.put(
Expand All @@ -309,16 +306,8 @@ async def predict_idempotent(
Run a single prediction on the model (idempotent creation).
"""
if request.id is not None and request.id != prediction_id:
raise RequestValidationError(
[
ErrorWrapper(
ValueError(
"prediction ID must match the ID supplied in the URL"
),
("body", "id"),
)
]
)
err = ValueError("prediction ID must match the ID supplied in the URL")
raise RequestValidationError([ErrorWrapper(err, ("body", "id"))])

# We've already checked that the IDs match, now ensure that an ID is
# set on the prediction object
Expand All @@ -328,13 +317,12 @@ async def predict_idempotent(
respond_async = prefer == "respond-async"

with trace_context(make_trace_context(traceparent, tracestate)):
return _predict(
return shared_predict(
request=request,
respond_async=respond_async,
)


async def _predict(
async def shared_predict(
*, request: Optional[PredictionRequest], respond_async: bool = False
) -> Response:
# [compat] If no body is supplied, assume that this model can be run
Expand Down

0 comments on commit 35167b9

Please sign in to comment.