|
1 | 1 | """ |
2 | | -Module for generating the answer node |
| 2 | +GenerateScraperNode Module |
3 | 3 | """ |
| 4 | + |
4 | 5 | # Imports from standard library |
5 | 6 | from typing import List |
6 | 7 | from tqdm import tqdm |
|
16 | 17 |
|
17 | 18 | class GenerateScraperNode(BaseNode): |
18 | 19 | """ |
19 | | - A node that generates an answer using a language model (LLM) based on the user's input |
20 | | - and the content extracted from a webpage. It constructs a prompt from the user's input |
21 | | - and the scraped content, feeds it to the LLM, and parses the LLM's response to produce |
22 | | - an answer. |
| 20 | + Generates a python script for scraping a website using the specified library. |
| 21 | + It takes the user's prompt and the scraped content as input and generates a python script |
| 22 | + that extracts the information requested by the user. |
23 | 23 |
|
24 | 24 | Attributes: |
25 | | - llm: An instance of a language model client, configured for generating answers. |
26 | | - node_name (str): The unique identifier name for the node, defaulting |
27 | | - to "GenerateScraperNode". |
28 | | - node_type (str): The type of the node, set to "node" indicating a |
29 | | - standard operational node. |
| 25 | + llm_model: An instance of a language model client, configured for generating answers. |
| 26 | + library (str): The python library to use for scraping the website. |
| 27 | + source (str): The website to scrape. |
30 | 28 |
|
31 | 29 | Args: |
32 | | - llm: An instance of the language model client (e.g., ChatOpenAI) used |
33 | | - for generating answers. |
34 | | - node_name (str, optional): The unique identifier name for the node. |
35 | | - Defaults to "GenerateScraperNode". |
36 | | -
|
37 | | - Methods: |
38 | | - execute(state): Processes the input and document from the state to generate an answer, |
39 | | - updating the state with the generated answer under the 'answer' key. |
| 30 | + input (str): Boolean expression defining the input keys needed from the state. |
| 31 | + output (List[str]): List of output keys to be updated in the state. |
| 32 | + node_config (dict): Additional configuration for the node. |
| 33 | + library (str): The python library to use for scraping the website. |
| 34 | + website (str): The website to scrape. |
| 35 | + node_name (str): The unique identifier name for the node, defaulting to "GenerateAnswer". |
| 36 | +
|
40 | 37 | """ |
41 | 38 |
|
42 | 39 | def __init__(self, input: str, output: List[str], node_config: dict, |
43 | 40 | library: str, website: str, node_name: str = "GenerateAnswer"): |
44 | | - """ |
45 | | - Initializes the GenerateScraperNode with a language model client and a node name. |
46 | | - Args: |
47 | | - llm (OpenAIImageToText): An instance of the OpenAIImageToText class. |
48 | | - node_name (str): name of the node |
49 | | - """ |
50 | 41 | super().__init__(node_name, "node", input, output, 2, node_config) |
| 42 | + |
51 | 43 | self.llm_model = node_config["llm"] |
52 | 44 | self.library = library |
53 | 45 | self.source = website |
54 | 46 |
|
55 | | - def execute(self, state): |
| 47 | + def execute(self, state: dict) -> dict: |
56 | 48 | """ |
57 | | - Generates an answer by constructing a prompt from the user's input and the scraped |
58 | | - content, querying the language model, and parsing its response. |
59 | | -
|
60 | | - The method updates the state with the generated answer under the 'answer' key. |
| 49 | + Generates a python script for scraping a website using the specified library. |
61 | 50 |
|
62 | 51 | Args: |
63 | | - state (dict): The current state of the graph, expected to contain 'user_input', |
64 | | - and optionally 'parsed_document' or 'relevant_chunks' within 'keys'. |
| 52 | + state (dict): The current state of the graph. The input keys will be used |
| 53 | + to fetch the correct data from the state. |
65 | 54 |
|
66 | 55 | Returns: |
67 | | - dict: The updated state with the 'answer' key containing the generated answer. |
| 56 | + dict: The updated state with the output key containing the generated answer. |
68 | 57 |
|
69 | 58 | Raises: |
70 | | - KeyError: If 'user_input' or 'document' is not found in the state, indicating |
| 59 | + KeyError: If input keys are not found in the state, indicating |
71 | 60 | that the necessary information for generating an answer is missing. |
72 | 61 | """ |
73 | 62 |
|
|
0 commit comments