-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor(client): prepare for #1543 * feat(client): client now supports async input_fn
- Loading branch information
Showing
16 changed files
with
262 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
# Han Xiao owns CICD and README.md | ||
.github @hanxiao | ||
setup.py @hanxiao | ||
extra-requirements.txt @hanxiao |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
__copyright__ = "Copyright (c) 2020 Jina AI Limited. All rights reserved." | ||
__license__ = "Apache-2.0" | ||
|
||
from typing import Iterator, Union, Tuple, AsyncIterator | ||
|
||
from .helper import _new_request_from_batch | ||
from ... import Request | ||
from ...enums import RequestType, DataInputType | ||
from ...helper import batch_iterator | ||
from ...logging import default_logger | ||
from ...types.document import DocumentSourceType, DocumentContentType | ||
from ...types.sets.querylang import AcceptQueryLangType | ||
|
||
SingletonDataType = Union[DocumentContentType, | ||
DocumentSourceType, | ||
Tuple[DocumentContentType, DocumentContentType], | ||
Tuple[DocumentSourceType, DocumentSourceType]] | ||
|
||
GeneratorSourceType = Union[Iterator[SingletonDataType], AsyncIterator[SingletonDataType]] | ||
|
||
|
||
def request_generator(data: GeneratorSourceType, | ||
request_size: int = 0, | ||
mode: RequestType = RequestType.INDEX, | ||
mime_type: str = None, | ||
queryset: Union[AcceptQueryLangType, Iterator[AcceptQueryLangType]] = None, | ||
data_type: DataInputType = DataInputType.AUTO, | ||
**kwargs # do not remove this, add on purpose to suppress unknown kwargs | ||
) -> Iterator['Request']: | ||
""" | ||
:param data_type: if ``data`` is an iterator over self-contained document, i.e. :class:`DocumentSourceType`; | ||
or an interator over possible Document content (set to text, blob and buffer). | ||
:return: | ||
""" | ||
|
||
_kwargs = dict(mime_type=mime_type, length=request_size, weight=1.0) | ||
|
||
try: | ||
for batch in batch_iterator(data, request_size): | ||
yield _new_request_from_batch(_kwargs, batch, data_type, mode, queryset) | ||
|
||
except Exception as ex: | ||
# must be handled here, as grpc channel wont handle Python exception | ||
default_logger.critical(f'input_fn is not valid! {ex!r}', exc_info=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
__copyright__ = "Copyright (c) 2020 Jina AI Limited. All rights reserved." | ||
__license__ = "Apache-2.0" | ||
|
||
from typing import Iterator, Union, AsyncIterator | ||
|
||
from .helper import _new_request_from_batch | ||
from .. import GeneratorSourceType | ||
from ... import Request | ||
from ...enums import RequestType, DataInputType | ||
from ...importer import ImportExtensions | ||
from ...logging import default_logger | ||
from ...types.sets.querylang import AcceptQueryLangType | ||
|
||
|
||
async def request_generator(data: GeneratorSourceType, | ||
request_size: int = 0, | ||
mode: RequestType = RequestType.INDEX, | ||
mime_type: str = None, | ||
queryset: Union[AcceptQueryLangType, Iterator[AcceptQueryLangType]] = None, | ||
data_type: DataInputType = DataInputType.AUTO, | ||
**kwargs # do not remove this, add on purpose to suppress unknown kwargs | ||
) -> AsyncIterator['Request']: | ||
|
||
_kwargs = dict(mime_type=mime_type, length=request_size, weight=1.0) | ||
|
||
try: | ||
with ImportExtensions(required=True): | ||
import aiostream | ||
|
||
async for batch in aiostream.stream.chunks(data, request_size): | ||
yield _new_request_from_batch(_kwargs, batch, data_type, mode, queryset) | ||
except Exception as ex: | ||
# must be handled here, as grpc channel wont handle Python exception | ||
default_logger.critical(f'input_fn is not valid! {ex!r}', exc_info=True) |
Oops, something went wrong.