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

Class GenerateCodeNode

scrapegraphai/nodes/generate_code_node.py:37–489  ·  view source on GitHub ↗

A node that generates Python code for a function that extracts data from HTML based on a output schema. Attributes: llm_model: An instance of a language model client, configured for generating answers. verbose (bool): A flag indicating whether to show print statements d

Source from the content-addressed store, hash-verified

35
36
37class GenerateCodeNode(BaseNode):
38 """
39 A node that generates Python code for a function that extracts data
40 from HTML based on a output schema.
41
42 Attributes:
43 llm_model: An instance of a language model client, configured for generating answers.
44 verbose (bool): A flag indicating whether to show print statements during execution.
45
46 Args:
47 input (str): Boolean expression defining the input keys needed from the state.
48 output (List[str]): List of output keys to be updated in the state.
49 node_config (dict): Additional configuration for the node.
50 node_name (str): The unique identifier name for the node, defaulting to "GenerateAnswer".
51 """
52
53 def __init__(
54 self,
55 input: str,
56 output: List[str],
57 node_config: Optional[dict] = None,
58 node_name: str = "GenerateCode",
59 ):
60 super().__init__(node_name, "node", input, output, 2, node_config)
61
62 self.llm_model = node_config["llm_model"]
63
64 if isinstance(node_config["llm_model"], ChatOllama):
65 self.llm_model.format = "json"
66
67 self.verbose = (
68 True if node_config is None else node_config.get("verbose", False)
69 )
70 self.force = False if node_config is None else node_config.get("force", False)
71 self.script_creator = (
72 False if node_config is None else node_config.get("script_creator", False)
73 )
74 self.is_md_scraper = (
75 False if node_config is None else node_config.get("is_md_scraper", False)
76 )
77
78 self.additional_info = node_config.get("additional_info")
79
80 self.max_iterations = node_config.get(
81 "max_iterations",
82 {
83 "overall": 10,
84 "syntax": 3,
85 "execution": 3,
86 "validation": 3,
87 "semantic": 3,
88 },
89 )
90
91 self.output_schema = node_config.get("schema")
92
93 def execute(self, state: dict) -> dict:
94 """

Callers 1

_create_graphMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected