MCPcopy Create free account
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / GraphIteratorNode

Class GraphIteratorNode

scrapegraphai/nodes/graph_iterator_node.py:16–147  ·  view source on GitHub ↗

A node responsible for instantiating and running multiple graph instances in parallel. It creates as many graph instances as the number of elements in the input list. Attributes: verbose (bool): A flag indicating whether to show print statements during execution. Args:

Source from the content-addressed store, hash-verified

14
15
16class GraphIteratorNode(BaseNode):
17 """
18 A node responsible for instantiating and running multiple graph instances in parallel.
19 It creates as many graph instances as the number of elements in the input list.
20
21 Attributes:
22 verbose (bool): A flag indicating whether to show print statements during execution.
23
24 Args:
25 input (str): Boolean expression defining the input keys needed from the state.
26 output (List[str]): List of output keys to be updated in the state.
27 node_config (dict): Additional configuration for the node.
28 node_name (str): The unique identifier name for the node, defaulting to "Parse".
29 """
30
31 def __init__(
32 self,
33 input: str,
34 output: List[str],
35 node_config: Optional[dict] = None,
36 node_name: str = "GraphIterator",
37 schema: Optional[Type[BaseModel]] = None,
38 ):
39 super().__init__(node_name, "node", input, output, 2, node_config)
40
41 self.verbose = (
42 False if node_config is None else node_config.get("verbose", False)
43 )
44 self.schema = schema
45
46 def execute(self, state: dict) -> dict:
47 """
48 Executes the node's logic to instantiate and run multiple graph instances in parallel.
49
50 Args:
51 state (dict): The current state of the graph. The input keys will be used to fetch
52 the correct data from the state.
53
54 Returns:
55 dict: The updated state with the output key c
56 ontaining the results of the graph instances.
57
58 Raises:
59 KeyError: If the input keys are not found in the state,
60 indicating that thenecessary information for running
61 the graph instances is missing.
62 """
63 batchsize = self.node_config.get("batchsize", DEFAULT_BATCHSIZE)
64
65 self.logger.info(
66 f"--- Executing {self.node_name} Node with batchsize {batchsize} ---"
67 )
68
69 try:
70 eventloop = asyncio.get_event_loop()
71 except RuntimeError:
72 eventloop = None
73

Callers 11

_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85
_create_graphMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected