33from collections import OrderedDict , defaultdict
44from contextlib import ExitStack
55from functools import wraps
6- from typing import Union , Tuple , List , Optional , Generator
6+ from typing import Union , Tuple , List , Optional , Iterator
77
88from ..cli .parser import set_router_parser , set_indexer_parser , \
99 set_frontend_parser , set_preprocessor_parser , \
@@ -78,9 +78,10 @@ class Flow:
7878 flow.index()
7979 ...
8080
81- You can also use the shortcuts, e.g. :py:meth:add_encoder , :py:meth:add_preprocessor
81+ You can also use the shortcuts, e.g. :py:meth:` add_encoder` , :py:meth:` add_preprocessor`.
8282
8383 It is recommend to use flow in the context manner as showed above.
84+
8485 Note the different default copy behaviors in :py:meth:`.add()` and :py:meth:`.build()`:
8586 :py:meth:`.add()` always copy the flow by default, whereas :py:meth:`.build()` modify the flow in place.
8687 You can change this behavior by giving an argument `copy_flow=False`.
@@ -169,18 +170,38 @@ def to_mermaid(self, left_right: bool = True):
169170 'copy-paste the output and visualize it with: https://mermaidjs.github.io/mermaid-live-editor/' )
170171 return mermaid_str
171172
172- def train (self , bytes_gen : Generator [bytes , None , None ] = None , ** kwargs ):
173+ def train (self , bytes_gen : Iterator [bytes ] = None , ** kwargs ):
174+ """Do training on the current flow
175+
176+ It will start a :py:class:`CLIClient` and call :py:func:`train`.
177+
178+ :param bytes_gen: An iterator of bytes. If not given, then you have to specify it in `kwargs`.
179+ :param kwargs: accepts all keyword arguments of `gnes client` CLI
180+ """
173181 self ._call_client (bytes_gen , mode = 'train' , ** kwargs )
174182
175- def index (self , bytes_gen : Generator [bytes , None , None ] = None , ** kwargs ):
183+ def index (self , bytes_gen : Iterator [bytes ] = None , ** kwargs ):
184+ """Do indexing on the current flow
185+
186+ It will start a :py:class:`CLIClient` and call :py:func:`index`.
187+
188+ :param bytes_gen: An iterator of bytes. If not given, then you have to specify it in `kwargs`.
189+ :param kwargs: accepts all keyword arguments of `gnes client` CLI
190+ """
176191 self ._call_client (bytes_gen , mode = 'index' , ** kwargs )
177192
178- def query (self , bytes_gen : Generator [bytes , None , None ] = None , ** kwargs ):
193+ def query (self , bytes_gen : Iterator [bytes ] = None , ** kwargs ):
194+ """Do indexing on the current flow
195+
196+ It will start a :py:class:`CLIClient` and call :py:func:`query`.
197+
198+ :param bytes_gen: An iterator of bytes. If not given, then you have to specify it in `kwargs`.
199+ :param kwargs: accepts all keyword arguments of `gnes client` CLI
200+ """
179201 self ._call_client (bytes_gen , mode = 'query' , ** kwargs )
180202
181203 @_build_level (BuildLevel .RUNTIME )
182- def _call_client (self , bytes_gen : Generator [bytes , None , None ] = None , ** kwargs ):
183-
204+ def _call_client (self , bytes_gen : Iterator [bytes ] = None , ** kwargs ):
184205 os .unsetenv ('http_proxy' )
185206 os .unsetenv ('https_proxy' )
186207 args , p_args = self ._get_parsed_args (self , set_client_cli_parser , kwargs )
@@ -192,26 +213,26 @@ def _call_client(self, bytes_gen: Generator[bytes, None, None] = None, **kwargs)
192213 c .start ()
193214
194215 def add_frontend (self , * args , ** kwargs ) -> 'Flow' :
195- """Add a frontend to the current flow, a shortcut of add(Service.Frontend)
216+ """Add a frontend to the current flow, a shortcut of :py:meth:` add(Service.Frontend)`.
196217 Usually you dont need to call this function explicitly, a flow object contains a frontend service by default.
197218 This function is useful when you build a flow without the frontend and want to customize the frontend later.
198219 """
199220 return self .add (Service .Frontend , * args , ** kwargs )
200221
201222 def add_encoder (self , * args , ** kwargs ) -> 'Flow' :
202- """Add an encoder to the current flow, a shortcut of add(Service.Encoder)"""
223+ """Add an encoder to the current flow, a shortcut of :py:meth:` add(Service.Encoder)` """
203224 return self .add (Service .Encoder , * args , ** kwargs )
204225
205226 def add_indexer (self , * args , ** kwargs ) -> 'Flow' :
206- """Add an indexer to the current flow, a shortcut of add(Service.Indexer)"""
227+ """Add an indexer to the current flow, a shortcut of :py:meth:` add(Service.Indexer)` """
207228 return self .add (Service .Indexer , * args , ** kwargs )
208229
209230 def add_preprocessor (self , * args , ** kwargs ) -> 'Flow' :
210- """Add a router to the current flow, a shortcut of add(Service.Preprocessor)"""
231+ """Add a preprocessor to the current flow, a shortcut of :py:meth:` add(Service.Preprocessor)` """
211232 return self .add (Service .Preprocessor , * args , ** kwargs )
212233
213234 def add_router (self , * args , ** kwargs ) -> 'Flow' :
214- """Add a preprocessor to the current flow, a shortcut of add(Service.Router)"""
235+ """Add a router to the current flow, a shortcut of :py:meth:` add(Service.Router)` """
215236 return self .add (Service .Router , * args , ** kwargs )
216237
217238 def add (self , service : 'Service' ,
@@ -416,7 +437,8 @@ def _build_graph(self, copy_flow: bool) -> 'Flow':
416437 def build (self , backend : Optional [str ] = 'thread' , copy_flow : bool = False , * args , ** kwargs ) -> 'Flow' :
417438 """
418439 Build the current flow and make it ready to use
419- :param backend: supported 'thread', 'process', 'swarm', 'k8s', 'shell'
440+
441+ :param backend: supported 'thread', 'process', 'swarm', 'k8s', 'shell', if None then only build graph only
420442 :param copy_flow: return the copy of the current flow
421443 :return: the current flow (by default)
422444 """
0 commit comments