A node that generates an analysis of the provided HTML code based on the wanted infromations to be extracted. Attributes: llm_model: An instance of a language model client, configured for generating answers. verbose (bool): A flag indicating whether to show print statements
| 14 | |
| 15 | |
| 16 | class HtmlAnalyzerNode(BaseNode): |
| 17 | """ |
| 18 | A node that generates an analysis of the provided HTML code based on the wanted infromations to be extracted. |
| 19 | |
| 20 | Attributes: |
| 21 | llm_model: An instance of a language model client, configured for generating answers. |
| 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 "GenerateAnswer". |
| 29 | """ |
| 30 | |
| 31 | def __init__( |
| 32 | self, |
| 33 | input: str, |
| 34 | output: List[str], |
| 35 | node_config: Optional[dict] = None, |
| 36 | node_name: str = "HtmlAnalyzer", |
| 37 | ): |
| 38 | super().__init__(node_name, "node", input, output, 2, node_config) |
| 39 | |
| 40 | self.llm_model = node_config["llm_model"] |
| 41 | |
| 42 | if isinstance(node_config["llm_model"], ChatOllama): |
| 43 | self.llm_model.format = "json" |
| 44 | |
| 45 | self.verbose = ( |
| 46 | True if node_config is None else node_config.get("verbose", False) |
| 47 | ) |
| 48 | self.force = False if node_config is None else node_config.get("force", False) |
| 49 | self.script_creator = ( |
| 50 | False if node_config is None else node_config.get("script_creator", False) |
| 51 | ) |
| 52 | self.is_md_scraper = ( |
| 53 | False if node_config is None else node_config.get("is_md_scraper", False) |
| 54 | ) |
| 55 | |
| 56 | self.additional_info = node_config.get("additional_info") |
| 57 | |
| 58 | def execute(self, state: dict) -> dict: |
| 59 | """ |
| 60 | Generates an analysis of the provided HTML code based on the wanted infromations to be extracted. |
| 61 | |
| 62 | Args: |
| 63 | state (dict): The current state of the graph. The input keys will be used |
| 64 | to fetch the correct data from the state. |
| 65 | |
| 66 | Returns: |
| 67 | dict: The updated state with the output key containing the generated answer. |
| 68 | |
| 69 | Raises: |
| 70 | KeyError: If the input keys are not found in the state, indicating |
| 71 | that the necessary information for generating an answer is missing. |
| 72 | """ |
| 73 | self.logger.info(f"--- Executing {self.node_name} Node ---") |