Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
VinciGit00 committed Dec 11, 2024
1 parent bae92b0 commit d1b2104
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 38 deletions.
33 changes: 13 additions & 20 deletions scrapegraphai/graphs/base_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@ def __init__(self, nodes: list, edges: list, entry_point: str,
self.callback_manager = CustomLLMCallbackManager()

if nodes[0].node_name != entry_point.node_name:
# raise a warning if the entry point is not the first node in the list
warnings.warn(
"Careful! The entry point node is different from the first node in the graph.")

self._set_conditional_node_edges()

# Burr configuration
self.use_burr = use_burr
self.burr_config = burr_config or {}

Expand Down Expand Up @@ -91,7 +89,8 @@ def _set_conditional_node_edges(self):
if node.node_type == 'conditional_node':
outgoing_edges = [(from_node, to_node) for from_node, to_node in self.raw_edges if from_node.node_name == node.node_name]
if len(outgoing_edges) != 2:
raise ValueError(f"ConditionalNode '{node.node_name}' must have exactly two outgoing edges.")
raise ValueError(f"""ConditionalNode '{node.node_name}'
must have exactly two outgoing edges.""")
node.true_node_name = outgoing_edges[0][1].node_name
try:
node.false_node_name = outgoing_edges[1][1].node_name
Expand Down Expand Up @@ -151,14 +150,14 @@ def _get_schema(self, current_node):
"""Extracts schema information from the node configuration."""
if not hasattr(current_node, "node_config"):
return None

if not isinstance(current_node.node_config, dict):
return None

schema_config = current_node.node_config.get("schema")
if not schema_config or isinstance(schema_config, dict):
return None

try:
return schema_config.schema()
except Exception:
Expand All @@ -167,7 +166,7 @@ def _get_schema(self, current_node):
def _execute_node(self, current_node, state, llm_model, llm_model_name):
"""Executes a single node and returns execution information."""
curr_time = time.time()

with self.callback_manager.exclusive_get_callback(llm_model, llm_model_name) as cb:
result = current_node.execute(state)
node_exec_time = time.time() - curr_time
Expand Down Expand Up @@ -197,17 +196,17 @@ def _get_next_node(self, current_node, result):
raise ValueError(
f"Conditional Node returned a node name '{result}' that does not exist in the graph"
)

return self.edges.get(current_node.node_name)

def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:
"""
Executes the graph by traversing nodes starting from the entry point using the standard method.
Executes the graph by traversing nodes
starting from the entry point using the standard method.
"""
current_node_name = self.entry_point
state = initial_state

# Tracking variables

total_exec_time = 0.0
exec_info = []
cb_total = {
Expand All @@ -230,16 +229,13 @@ def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:

while current_node_name:
current_node = self._get_node_by_name(current_node_name)

# Update source information if needed

if source_type is None:
source_type, source, prompt = self._update_source_info(current_node, state)

# Get model information if needed

if llm_model is None:
llm_model, llm_model_name, embedder_model = self._get_model_info(current_node)

# Get schema if needed

if schema is None:
schema = self._get_schema(current_node)

Expand Down Expand Up @@ -273,7 +269,6 @@ def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:
)
raise e

# Add total results to execution info
exec_info.append({
"node_name": "TOTAL RESULT",
"total_tokens": cb_total["total_tokens"],
Expand All @@ -284,7 +279,6 @@ def _execute_standard(self, initial_state: dict) -> Tuple[dict, list]:
"exec_time": total_exec_time,
})

# Log final execution results
graph_execution_time = time.time() - start_time
response = state.get("answer", None) if source_type == "url" else None
content = state.get("parsed_doc", None) if response is not None else None
Expand Down Expand Up @@ -343,4 +337,3 @@ def append_node(self, node):
self.raw_edges.append((last_node, node))
self.nodes.append(node)
self.edges = self._create_edges({e for e in self.raw_edges})

1 change: 0 additions & 1 deletion scrapegraphai/graphs/code_generator_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
GenerateCodeNode,
)


class CodeGeneratorGraph(AbstractGraph):
"""
CodeGeneratorGraph is a script generator pipeline that generates
Expand Down
2 changes: 1 addition & 1 deletion scrapegraphai/graphs/csv_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _create_graph(self):
"""
Creates the graph of nodes representing the workflow for web scraping.
"""

fetch_node = FetchNode(
input="csv | csv_dir",
output=["doc"],
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/graphs/depth_search_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
GenerateAnswerNodeKLevel,
)


class DepthSearchGraph(AbstractGraph):
"""
CodeGeneratorGraph is a script generator pipeline that generates
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/graphs/document_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from .abstract_graph import AbstractGraph
from ..nodes import FetchNode, ParseNode, GenerateAnswerNode


class DocumentScraperGraph(AbstractGraph):
"""
DocumentScraperGraph is a scraping pipeline that automates the process of
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/graphs/omni_scraper_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..nodes import FetchNode, ParseNode, ImageToTextNode, GenerateAnswerOmniNode
from ..models import OpenAIImageToText


class OmniScraperGraph(AbstractGraph):
"""
OmniScraper is a scraping pipeline that automates the process of
Expand Down
2 changes: 0 additions & 2 deletions scrapegraphai/graphs/script_creator_graph.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
"""
ScriptCreatorGraph Module
"""

from typing import Optional
from pydantic import BaseModel
from .base_graph import BaseGraph
from .abstract_graph import AbstractGraph
from ..nodes import FetchNode, ParseNode, GenerateScraperNode


class ScriptCreatorGraph(AbstractGraph):
"""
ScriptCreatorGraph defines a scraping pipeline for generating web scraping scripts.
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/graphs/search_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SearchGraph Module
"""

from copy import deepcopy
from typing import Optional, List
from pydantic import BaseModel
Expand Down
2 changes: 0 additions & 2 deletions scrapegraphai/graphs/search_link_graph.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""
SearchLinkGraph Module
"""

from typing import Optional
import logging
from pydantic import BaseModel
from .base_graph import BaseGraph
from .abstract_graph import AbstractGraph
from ..nodes import FetchNode, SearchLinkNode, SearchLinksWithContext


class SearchLinkGraph(AbstractGraph):
"""
SearchLinkGraph is a scraping pipeline that automates the process of
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/graphs/smart_scraper_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SmartScraperGraph Module
"""

from typing import Optional
from pydantic import BaseModel
from scrapegraph_py import Client
Expand Down
2 changes: 0 additions & 2 deletions scrapegraphai/graphs/smart_scraper_lite_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SmartScraperGraph Module
"""

from typing import Optional
from pydantic import BaseModel
from .base_graph import BaseGraph
Expand All @@ -11,7 +10,6 @@
ParseNode,
)


class SmartScraperLiteGraph(AbstractGraph):
"""
SmartScraperLiteGraph is a scraping pipeline that automates the process of
Expand Down
2 changes: 0 additions & 2 deletions scrapegraphai/graphs/speech_graph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
SpeechGraph Module
"""

from typing import Optional
from pydantic import BaseModel
from .base_graph import BaseGraph
Expand All @@ -15,7 +14,6 @@
from ..utils.save_audio_from_bytes import save_audio_from_bytes
from ..models import OpenAITextToSpeech


class SpeechGraph(AbstractGraph):
"""
SpeechyGraph is a scraping pipeline that scrapes the web, provide an answer
Expand Down
2 changes: 0 additions & 2 deletions scrapegraphai/nodes/fetch_node.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
FetchNode Module
"""

import json
from typing import List, Optional
from langchain_openai import ChatOpenAI, AzureChatOpenAI
Expand All @@ -15,7 +14,6 @@
from ..utils.logging import get_logger
from .base_node import BaseNode


class FetchNode(BaseNode):
"""
A node responsible for fetching the HTML content of a specified URL and updating
Expand Down
1 change: 0 additions & 1 deletion scrapegraphai/nodes/fetch_node_level_k.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
fetch_node_level_k module
"""

from typing import List, Optional
from urllib.parse import urljoin
from langchain_core.documents import Document
Expand Down

0 comments on commit d1b2104

Please sign in to comment.