Skip to content

Python scraper based on AI

Update smart_scraper_graph.py

Marco Vinciguerrac93dbe0a949a
diff --git a/scrapegraphai/graphs/smart_scraper_graph.py b/scrapegraphai/graphs/smart_scraper_graph.py
index 4093e49f..ee230695 100644
--- a/scrapegraphai/graphs/smart_scraper_graph.py
+++ b/scrapegraphai/graphs/smart_scraper_graph.py
@@ -2,14 +2,17 @@
SmartScraperGraph Module
"""
+from typing import Optional
+
from .base_graph import BaseGraph
+from .abstract_graph import AbstractGraph
+
from ..nodes import (
FetchNode,
ParseNode,
RAGNode,
GenerateAnswerNode
)
-from .abstract_graph import AbstractGraph
class SmartScraperGraph(AbstractGraph):
@@ -22,6 +25,7 @@ class SmartScraperGraph(AbstractGraph):
prompt (str): The prompt for the graph.
source (str): The source of the graph.
config (dict): Configuration parameters for the graph.
+ schema (str): The schema for the graph output.
llm_model: An instance of a language model client, configured for generating answers.
embedder_model: An instance of an embedding model client,
configured for generating embeddings.
@@ -32,6 +36,7 @@ class SmartScraperGraph(AbstractGraph):
prompt (str): The prompt for the graph.
source (str): The source of the graph.
config (dict): Configuration parameters for the graph.
+ schema (str): The schema for the graph output.
Example:
>>> smart_scraper = SmartScraperGraph(
@@ -43,8 +48,8 @@ class SmartScraperGraph(AbstractGraph):
)
"""
- def __init__(self, prompt: str, source: str, config: dict):
- super().__init__(prompt, config, source)
+ def __init__(self, prompt: str, source: str, config: dict, schema: Optional[str] = None):
+ super().__init__(prompt, config, source, schema)
self.input_key = "url" if source.startswith("http") else "local_dir"
@@ -81,7 +86,8 @@ class SmartScraperGraph(AbstractGraph):
input="user_prompt & (relevant_chunks | parsed_doc | doc)",
output=["answer"],
node_config={
- "llm_model": self.llm_model
+ "llm_model": self.llm_model,
+ "schema": self.schema,
}
)