SearchGraph is a scraping pipeline that searches the internet for answers to a given prompt. It only requires a user prompt to search the internet and generate an answer. Attributes: prompt (str): The user prompt to search the internet. llm_model (dict): The configurati
| 15 | |
| 16 | |
| 17 | class SearchGraph(AbstractGraph): |
| 18 | """ |
| 19 | SearchGraph is a scraping pipeline that searches the internet for answers to a given prompt. |
| 20 | It only requires a user prompt to search the internet and generate an answer. |
| 21 | |
| 22 | Attributes: |
| 23 | prompt (str): The user prompt to search the internet. |
| 24 | llm_model (dict): The configuration for the language model. |
| 25 | embedder_model (dict): The configuration for the embedder model. |
| 26 | headless (bool): A flag to run the browser in headless mode. |
| 27 | verbose (bool): A flag to display the execution information. |
| 28 | model_token (int): The token limit for the language model. |
| 29 | considered_urls (List[str]): A list of URLs considered during the search. |
| 30 | |
| 31 | Args: |
| 32 | prompt (str): The user prompt to search the internet. |
| 33 | config (dict): Configuration parameters for the graph. |
| 34 | schema (Optional[BaseModel]): The schema for the graph output. |
| 35 | |
| 36 | Example: |
| 37 | >>> search_graph = SearchGraph( |
| 38 | ... "What is Chioggia famous for?", |
| 39 | ... {"llm": {"model": "openai/gpt-3.5-turbo"}} |
| 40 | ... ) |
| 41 | >>> result = search_graph.run() |
| 42 | >>> print(search_graph.get_considered_urls()) |
| 43 | """ |
| 44 | |
| 45 | def __init__( |
| 46 | self, prompt: str, config: dict, schema: Optional[Type[BaseModel]] = None |
| 47 | ): |
| 48 | self.max_results = config.get("max_results", 3) |
| 49 | |
| 50 | self.copy_config = safe_deepcopy(config) |
| 51 | self.copy_schema = deepcopy(schema) |
| 52 | self.considered_urls = [] # New attribute to store URLs |
| 53 | |
| 54 | super().__init__(prompt, config, schema) |
| 55 | |
| 56 | def _create_graph(self) -> BaseGraph: |
| 57 | """ |
| 58 | Creates the graph of nodes representing the workflow for web scraping and searching. |
| 59 | |
| 60 | Returns: |
| 61 | BaseGraph: A graph instance representing the web scraping and searching workflow. |
| 62 | """ |
| 63 | |
| 64 | search_internet_node = SearchInternetNode( |
| 65 | input="user_prompt", |
| 66 | output=["urls"], |
| 67 | node_config={ |
| 68 | "llm_model": self.llm_model, |
| 69 | "max_results": self.max_results, |
| 70 | "loader_kwargs": self.loader_kwargs, |
| 71 | "storage_state": self.copy_config.get("storage_state"), |
| 72 | "search_engine": self.copy_config.get("search_engine"), |
| 73 | "serper_api_key": self.copy_config.get("serper_api_key"), |
| 74 | }, |
no outgoing calls