Skip to content

Commit

Permalink
Fixes up error messages to be clearer for missing keys in state expre…
Browse files Browse the repository at this point in the history
…ssion
  • Loading branch information
elijahbenizzy committed Aug 29, 2024
1 parent ceb522f commit 3df15ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions examples/openai/omni_scraper_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"""

import os, json
import uuid

from dotenv import load_dotenv
from scrapegraphai.graphs import OmniScraperGraph
from scrapegraphai.utils import prettify_exec_info

load_dotenv()


# ************************************************
# Define the configuration for the graph
# ************************************************
Expand All @@ -23,17 +24,22 @@
},
"verbose": True,
"headless": True,
"max_images": 5
"max_images": 5,
"burr_kwargs": {
"project_name": "test-scraper",
"app_instance_id": "1234",
}
}

# ************************************************
# Create the OmniScraperGraph instance and run it
# ************************************************

omni_scraper_graph = OmniScraperGraph(
prompt="List me all the projects with their titles and image links and descriptions.",
prompt="List me all the projects with their titles and image links and descriptions." + str(uuid.uuid4()),
# also accepts a string with the already downloaded HTML code
source="https://perinim.github.io/projects/",
# source="https://perinim.github.io/projects/",
source="https://github.com/orgs/DAGWorks-Inc/repositories",
config=graph_config
)

Expand Down
4 changes: 2 additions & 2 deletions scrapegraphai/nodes/base_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_input_keys(self, state: dict) -> List[str]:
self._validate_input_keys(input_keys)
return input_keys
except ValueError as e:
raise ValueError(f"Error parsing input keys for {self.node_name}: {str(e)}")
raise ValueError(f"Error parsing input keys for {self.node_name}") from e

def _validate_input_keys(self, input_keys):
"""
Expand Down Expand Up @@ -233,7 +233,7 @@ def evaluate_expression(expression: str) -> List[str]:
result = evaluate_expression(expression)

if not result:
raise ValueError("No state keys matched the expression.")
raise ValueError(f"No state keys matched the expression. Expression was {expression}. State contains keys: {', '.join(state.keys())}")

# Remove redundant state keys from the result, without changing their order
final_result = []
Expand Down
2 changes: 2 additions & 0 deletions scrapegraphai/nodes/fetch_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ def update_state(self, state, compressed_document):
Returns:
dict: The updated state with the output data.
"""
import pdb
pdb.set_trace()

state.update({self.output[0]: compressed_document,})
return state

0 comments on commit 3df15ac

Please sign in to comment.