Skip to content

Commit 389b52a

Browse files
committed
removed examples
1 parent 8c5397f commit 389b52a

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

scrapegraphai/graphs/search_graph.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,11 @@ def _create_graph(self) -> BaseGraph:
100100
def run(self) -> str:
101101
"""
102102
Executes the web scraping and searching process.
103-
103+
104104
Returns:
105105
str: The answer to the prompt.
106106
"""
107-
108107
inputs = {"user_prompt": self.prompt}
109108
self.final_state, self.execution_info = self.graph.execute(inputs)
110109

111-
return self.final_state.get("answer", "No answer found.")
110+
return self.final_state.get("answer", "No answer found.")

scrapegraphai/nodes/search_internet_node.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ class SearchInternetNode(BaseNode):
2727
node_name (str): The unique identifier name for the node, defaulting to "SearchInternet".
2828
"""
2929

30-
def __init__(self, input: str, output: List[str], node_config: dict,
30+
def __init__(self, input: str, output: List[str], node_config: Optional[dict] = None,
3131
node_name: str = "SearchInternet"):
3232
super().__init__(node_name, "node", input, output, 1, node_config)
3333

3434
self.llm_model = node_config["llm_model"]
35-
self.verbose = True if node_config is None else node_config.get("verbose", False)
35+
self.verbose = True if node_config is None else node_config.get(
36+
"verbose", False)
37+
self.max_results = node_config.get("max_results", 3)
3638

3739
def execute(self, state: dict) -> dict:
3840
"""
@@ -84,9 +86,12 @@ def execute(self, state: dict) -> dict:
8486

8587
if self.verbose:
8688
print(f"Search Query: {search_query}")
87-
88-
# TODO: handle multiple URLs
89-
answer = search_on_web(query=search_query, max_results=1)[0]
89+
answer = search_on_web(
90+
query=search_query, max_results=self.max_results)
91+
92+
if len(answer) == 0:
93+
# raise an exception if no answer is found
94+
raise ValueError("Zero results found for the search query.")
9095

9196
# Update the state with the generated answer
9297
state.update({self.output[0]: answer})

scrapegraphai/nodes/search_link_node.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ class SearchLinkNode(BaseNode):
3333
node_name (str): The unique identifier name for the node, defaulting to "GenerateAnswer".
3434
"""
3535

36-
def __init__(self, input: str, output: List[str], node_config: dict,
36+
def __init__(self, input: str, output: List[str], node_config: Optional[dict] = None,
3737
node_name: str = "GenerateLinks"):
3838
super().__init__(node_name, "node", input, output, 1, node_config)
3939

4040
self.llm_model = node_config["llm_model"]
41-
self.verbose = True if node_config is None else node_config.get("verbose", False)
41+
self.verbose = True if node_config is None else node_config.get(
42+
"verbose", False)
4243

4344
def execute(self, state: dict) -> dict:
4445
"""
@@ -73,10 +74,11 @@ def execute(self, state: dict) -> dict:
7374
links.append(soup.find_all("a"))
7475
state.update({self.output[0]: {elem for elem in links}})
7576

76-
except Exception as e:
77+
except Exception:
7778
if self.verbose:
78-
print("Error extracting links using classical methods. Using LLM to extract links.")
79-
79+
print(
80+
"Error extracting links using classical methods. Using LLM to extract links.")
81+
8082
output_parser = JsonOutputParser()
8183

8284
template_chunks = """

0 commit comments

Comments
 (0)