10000 [async] Include prediction id upload request by aron · Pull Request #1788 · replicate/cog · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[async] Include prediction id upload request #1788

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 3 commits into from
Jul 17, 2024
Merged

Conversation

aron
Copy link
Contributor
@aron aron commented Jul 4, 2024

Based on #1667

This PR introduces two small changes to the file upload interface.

  1. We now allow downstream services to include the destination of the asset in a Location header, rather than assuming that it's the same as the final upload url (either the one passed via --upload-url or the result of a 307 redirect response.

  2. We now include the X-Prediction-Id header in upload request, this allows the downstream client to potentially do configuration/routing based on the prediction ID. This ID should be considered unsafe and needs to be validated by the downstream service.

@aron aron changed the base branch from main to async July 4, 2024 20:10
@aron aron changed the title Include prediction id upload request [async] Include prediction id upload request Jul 4, 2024
@aron aron requested a review from a team July 4, 2024 20:10
Copy link
Contributor
@technillogue technillogue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks basically reasonable to me, though I'm not sure if there's anything I should watch out for. how come CI didn't pass?

@technillogue technillogue force-pushed the async-prediction-id branch from 2da3de0 to c337191 Compare July 8, 2024 16:56
@aron
Copy link
Contributor Author
aron commented Jul 8, 2024

how come CI didn't pass?

Something off with the go deps, I'll rebase and try again.

@aron
Copy link
Contributor Author
aron commented Jul 11, 2024

@technillogue fix for CI is here #1797

@aron aron force-pushed the async-prediction-id branch from c337191 to 62851fe Compare July 11, 2024 10:25
@technillogue technillogue force-pushed the async-prediction-id branch 2 times, most recently from 7d5160e to 5665632 Compare July 12, 2024 22:58
@aron aron force-pushed the async-prediction-id branch from 5665632 to c7fce45 Compare July 16, 2024 20:54
@aron
Copy link
Contributor Author
aron commented Jul 16, 2024

@technillogue would you mind reviewing this when you have a moment. I'd like to republish real-esrgan with a cut of a new alpha release that supports the new uploader tomorrow if possible.

@@ -62,7 +72,7 @@ def webhook_headers() -> "dict[str, str]":

async def on_request_trace_context_hook(request: httpx.Request) -> None:
ctx = current_trace_context() or {}
request.headers.update(ctx)
request.headers.update(cast(Mapping[str, str], ctx))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the linting issue on async.

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.
@aron aron force-pushed the async-prediction-id branch from c7fce45 to 97ce06c Compare July 16, 2024 21:54
Comment on lines 202 to 212
class ChunkFileReader:
async def __aiter__(self) -> AsyncIterator[bytes]:
fh.seek(0)
while 1:
chunk = fh.read(1024 * 1024)
if isinstance(chunk, str):
chunk = chunk.encode("utf-8")
if not chunk:
log.info("finished reading file")
break
yield chunk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation didn't reset the file handle on subsequent calls which resulted in an httpx.StreamConsumed exception. I added a test and implemented this fix which will ensure a new iterator is created for each request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I believe the function-based implementation would work with a fh.seek(0) at the top of the function, but this is great/cleaner

@aron aron requested review from a team and technillogue July 17, 2024 09:35
@aron
Copy link
Contributor Author
aron commented Jul 17, 2024

@mattt thanks! Looks great!

@technillogue technillogue merged commit b9df82a into async Jul 17, 2024
9 checks passed
@technillogue technillogue deleted the async-prediction-id branch July 17, 2024 17:27
technillogue pushed a commit that referenced this pull request Jul 18, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
technillogue pushed a commit that referenced this pull request Jul 18, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
mattt added a commit that referenced this pull request Jul 18, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
mattt added a commit that referenced this pull request Jul 19, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
technillogue pushed a commit that referenced this pull request Jul 24, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
technillogue pushed a commit that referenced this pull request Jul 25, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
technillogue pushed a commit that referenced this pull request Jul 25, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
as
6D40
set in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
technillogue pushed a commit that referenced this pull request Jul 26, 2024
* Cast TraceContext into Mapping[str, str] to fix linter

* Include prediction id upload request

Based on #1667

This PR introduces two small changes to the file upload interface.

1. We now allow downstream services to include the destination of the
asset in a `Location` header, rather than assuming that it's the same as
the final upload url (either the one passed via `--upload-url` or the
result of a 307 redirect response.

2. We now include the `X-Prediction-Id` header in upload request, this
allows the downstream client to potentially do configuration/routing
based on the prediction ID. This ID should be considered unsafe and
needs to be validated by the downstream service.

* Extract ChunkFileReader into top-level class

---------

Co-authored-by: Mattt Zmuda <mattt@replicate.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0