Skip to content

Add type annotation to Prediction and Training status fields #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions replicate/prediction.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
import time
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Literal, Optional, Union

from typing_extensions import NotRequired, TypedDict, Unpack

Expand Down Expand Up @@ -37,7 +37,7 @@ class Prediction(Resource):
version: str
"""An identifier for the version of the model used to create the prediction."""

status: str
status: Literal["starting", "processing", "succeeded", "failed", "canceled"]
"""The status of the prediction."""

input: Optional[Dict[str, Any]]
Expand Down
3 changes: 2 additions & 1 deletion replicate/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Any,
Dict,
List,
Literal,
Optional,
Tuple,
TypedDict,
Expand Down Expand Up @@ -48,7 +49,7 @@ class Training(Resource):
destination: Optional[str]
"""The model destination of the training."""

status: str
status: Literal["starting", "processing", "succeeded", "failed", "canceled"]
"""The status of the training."""

input: Optional[Dict[str, Any]]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def prediction_with_status(status: str) -> dict:
router.route(method="POST", path="/predictions").mock(
return_value=httpx.Response(
201,
json=prediction_with_status("running"),
json=prediction_with_status("processing"),
)
)
router.route(method="GET", path="/predictions/p1").mock(
Expand Down