jina-ai / jina

☁️ Build multimodal AI applications with cloud-native stack
https://docs.jina.ai
Apache License 2.0
20.63k stars 2.21k forks source link

feat: add return_type parameter to gateway streamer methods to allow … #6027

Closed alaeddine-13 closed 10 months ago

alaeddine-13 commented 11 months ago

closes: https://github.com/jina-ai/jina/issues/6012

GatewayStreamer by default will fetch executor input and output schemas and reconstruct docarray models dynamically. The output schemas will be used to cast the responses at the gateway level. Although the casted responses are nearly identical to the original schemas defined at executor level, they might fail some checks, for instance, if the user defines a doc schema MyDoc, the following check will fail: assert isinstance(doc, MyDoc) similarly, adding doc to a DocList[MyDoc] will fail the type checking.

This PR allows the user of a GatewayStreamer to specify the return_type that will be used for casting and the output responses received from methods of the gateway streamer will match exactly the specified return_type.

codecov[bot] commented 11 months ago

Codecov Report

Patch coverage: 57.14% and project coverage change: -1.06% :warning:

Comparison is base (35b1067) 77.59% compared to head (3b0000d) 76.53%. Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #6027 +/- ## ========================================== - Coverage 77.59% 76.53% -1.06% ========================================== Files 144 144 Lines 13789 13797 +8 ========================================== - Hits 10700 10560 -140 - Misses 3089 3237 +148 ``` | [Flag](https://app.codecov.io/gh/jina-ai/jina/pull/6027/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai) | Coverage Δ | | |---|---|---| | [jina](https://app.codecov.io/gh/jina-ai/jina/pull/6027/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai) | `76.53% <57.14%> (-1.06%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files Changed](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai) | Coverage Δ | | |---|---|---| | [jina/clients/base/unary\_rpc.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9jbGllbnRzL2Jhc2UvdW5hcnlfcnBjLnB5) | `96.15% <ø> (ø)` | | | [jina/clients/base/websocket.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9jbGllbnRzL2Jhc2Uvd2Vic29ja2V0LnB5) | `84.76% <ø> (-5.72%)` | :arrow_down: | | [...ina/serve/runtimes/gateway/graph/topology\_graph.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9zZXJ2ZS9ydW50aW1lcy9nYXRld2F5L2dyYXBoL3RvcG9sb2d5X2dyYXBoLnB5) | `71.81% <16.66%> (-1.39%)` | :arrow_down: | | [jina/clients/base/http.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9jbGllbnRzL2Jhc2UvaHR0cC5weQ==) | `93.16% <50.00%> (ø)` | | | [jina/serve/runtimes/gateway/streamer.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9zZXJ2ZS9ydW50aW1lcy9nYXRld2F5L3N0cmVhbWVyLnB5) | `58.33% <50.00%> (-0.28%)` | :arrow_down: | | [...untimes/gateway/async\_request\_response\_handling.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9zZXJ2ZS9ydW50aW1lcy9nYXRld2F5L2FzeW5jX3JlcXVlc3RfcmVzcG9uc2VfaGFuZGxpbmcucHk=) | `93.07% <100.00%> (-0.06%)` | :arrow_down: | | [jina/serve/stream/\_\_init\_\_.py](https://app.codecov.io/gh/jina-ai/jina/pull/6027?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai#diff-amluYS9zZXJ2ZS9zdHJlYW0vX19pbml0X18ucHk=) | `85.11% <100.00%> (-2.31%)` | :arrow_down: | ... and [18 files with indirect coverage changes](https://app.codecov.io/gh/jina-ai/jina/pull/6027/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=jina-ai)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

alaeddine-13 commented 11 months ago

Currently this PR depends on an issue with @docarray: @docarray's UpdateMixin, only updates a document if the other document is exactly the same type. However, there are cases where 2 documents are generated from dynamic schemas that are exactly the same. Even though the fields are exactly the same, the update operation will fail because in docarray checks that the schemas belong to the same reference

alaeddine-13 commented 11 months ago

depends on https://github.com/docarray/docarray/pull/1755

github-actions[bot] commented 10 months ago

:memo: Docs are deployed on https://feat-add-return-type-streamer--jina-docs.netlify.app :tada: