Skip to content
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

add a "quiet" flag to the HTTP API #1984

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions python/cog/command/ast_openapi_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"default": ["start", "output", "logs", "completed"],
"items": { "$ref": "#/components/schemas/WebhookEvent" },
"type": "array"
},
"quiet": {
"title": "Quiet",
"type": "boolean",
"default": false
}
},
"title": "PredictionRequest",
Expand Down
8 changes: 6 additions & 2 deletions python/cog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ def default_events(cls) -> List["WebhookEvent"]:


class PredictionBaseModel(pydantic.BaseModel):
input: Dict[str, Any]

if PYDANTIC_V2:
model_config = pydantic.ConfigDict(use_enum_values=True) # type: ignore
else:
Expand All @@ -66,6 +64,8 @@ class Config:


class PredictionRequest(PredictionBaseModel):
input: Dict[str, Any]

id: Optional[str] = None
created_at: Optional[datetime] = None

Expand All @@ -77,6 +77,8 @@ class PredictionRequest(PredictionBaseModel):
default=WebhookEvent.default_events(),
)

quiet: bool = False

@classmethod
def with_types(cls, input_type: Type[Any]) -> Any:
# [compat] Input is implicitly optional -- previous versions of the
Expand All @@ -88,6 +90,8 @@ def with_types(cls, input_type: Type[Any]) -> Any:


class PredictionResponse(PredictionBaseModel):
input: Optional[Dict[str, Any]] = None

output: Any = None

id: Optional[str] = None
Expand Down
3 changes: 3 additions & 0 deletions python/cog/server/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ def __init__(
else:
request_dict = prediction_request.dict()

if prediction_request.quiet:
request_dict.pop("input", None)

self._p = schema.PredictionResponse(**request_dict)
self._p.status = schema.Status.PROCESSING
self._output_type_multi = None
Expand Down
40 changes: 40 additions & 0 deletions python/tests/server/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,43 @@ def test_predict_task_file_uploads_multi():
"http://example.com/hello.jpg",
"http://example.com/world.jpg",
]


def test_predict_quiet():
p = PredictionRequest(
input={"hello": "there"},
id=None,
created_at=None,
output_file_prefix=None,
webhook=None,
quiet=False,
)
t = PredictTask(p)

assert t.result.status == Status.PROCESSING
assert t.result.output is None
assert t.result.logs == ""
assert isinstance(t.result.started_at, datetime)
t.set_output_type(multi=False)
t.append_output("giraffes")
assert t.result.output == "giraffes"
assert t.result.input == {"hello": "there"}

p = PredictionRequest(
input={"hello": "there"},
id=None,
created_at=None,
output_file_prefix=None,
webhook=None,
quiet=True,
)
t = PredictTask(p)

assert t.result.status == Status.PROCESSING
assert t.result.output is None
assert t.result.logs == ""
assert isinstance(t.result.started_at, datetime)
t.set_output_type(multi=False)
t.append_output("giraffes")
assert t.result.output == "giraffes"
assert t.result.input == None