Skip to content

Commit a73496d

Browse files
committed
refactoring of nodes
1 parent e68b707 commit a73496d

File tree

15 files changed

+115
-5
lines changed

15 files changed

+115
-5
lines changed

examples/openai/custom_graph_openai.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dotenv import load_dotenv
77
from scrapegraphai.models import OpenAI
88
from scrapegraphai.graphs import BaseGraph
9-
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode
9+
from scrapegraphai.nodes import FetchNode, ParseNode, RAGNode, GenerateAnswerNode, RobotsNode
1010
load_dotenv()
1111

1212
# ************************************************
@@ -31,6 +31,12 @@
3131
llm_model = OpenAI(graph_config["llm"])
3232

3333
# define the nodes for the graph
34+
robot_node = RobotsNode(
35+
input="url",
36+
output=["is_scrapable"],
37+
node_config={"llm": llm_model}
38+
)
39+
3440
fetch_node = FetchNode(
3541
input="url | local_dir",
3642
output=["doc"],
@@ -57,12 +63,14 @@
5763

5864
graph = BaseGraph(
5965
nodes={
66+
robot_node,
6067
fetch_node,
6168
parse_node,
6269
rag_node,
6370
generate_answer_node,
6471
},
6572
edges={
73+
(robot_node, fetch_node),
6674
(fetch_node, parse_node),
6775
(parse_node, rag_node),
6876
(rag_node, generate_answer_node)
File renamed without changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
if [ $# -eq 0 ]; then
2+
echo "Usage: $0 <commit_message>"
3+
exit 1
4+
fi
5+
6+
cd ..
7+
8+
# Extract the commit message from the argument
9+
commit_message="$1"
10+
11+
# Run Pylint on the specified Python files
12+
pylint pylint scrapegraphai/**/*.py scrapegraphai/*.py tests/**/*.py
13+
14+
cd tests
15+
16+
# Run pytest
17+
if ! pytest; then
18+
echo "Pytest failed. Aborting commit and push."
19+
exit 1
20+
fi
21+
22+
cd ..
23+
24+
# Make the pull
25+
git pull
26+
27+
# Add the modified files to the Git repository
28+
git add .
29+
30+
# Commit the changes with the provided message
31+
git commit -m "$commit_message"
32+
33+
# Push the changes to the remote repository
34+
git push

scrapegraphai/graphs/base_graph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def execute(self, initial_state: dict) -> dict:
8282

8383
with get_openai_callback() as cb:
8484
result = current_node.execute(state)
85-
# ADd the check for the node RObots
86-
8785
node_exec_time = time.time() - curr_time
8886
total_exec_time += node_exec_time
8987

scrapegraphai/nodes/robots_node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def execute(self, state):
137137
if "no" in is_scrapable:
138138
print("\033[33mScraping this website is not allowed\033[0m")
139139
if not self.force_scraping:
140-
return {"update": "block the scraping phase"}
140+
raise ValueError(
141+
'The website you selected is not scrapable')
141142
else:
142143
print("\033[92mThe path is scrapable\033[0m")
143144

tests/Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Remember to activating Ollama and having installed the LLM on your pc
66

77
For running the tests run the command:
88
```python
9-
pytests
9+
pytest
1010
```
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)