mirror of
https://github.com/VinciGit00/Scrapegraph-ai.git
synced 2026-07-12 21:01:56 +08:00
feat: add deep scraper implementation
Co-Authored-By: Matteo Vedovati <68272450+vedovati-matteo@users.noreply.github.com>
This commit is contained in:
parent
17c51457df
commit
4b371f4d94
@ -1,4 +1,6 @@
|
|||||||
|
"""
|
||||||
|
depth_search_graph_opeani example
|
||||||
|
"""
|
||||||
from scrapegraphai.graphs import DepthSearchGraph
|
from scrapegraphai.graphs import DepthSearchGraph
|
||||||
|
|
||||||
graph_config = {
|
graph_config = {
|
||||||
@ -9,13 +9,18 @@ from .abstract_graph import AbstractGraph
|
|||||||
from ..utils.save_code_to_file import save_code_to_file
|
from ..utils.save_code_to_file import save_code_to_file
|
||||||
from ..nodes import (
|
from ..nodes import (
|
||||||
FetchNodeLevelK,
|
FetchNodeLevelK,
|
||||||
ParseNodeDepthK
|
ParseNodeDepthK,
|
||||||
|
DescriptionNode,
|
||||||
|
RAGNode,
|
||||||
|
GenerateAnswerNodeKLevel
|
||||||
)
|
)
|
||||||
|
|
||||||
class DepthSearchGraph(AbstractGraph):
|
class DepthSearchGraph(AbstractGraph):
|
||||||
"""
|
"""
|
||||||
CodeGeneratorGraph is a script generator pipeline that generates the function extract_data(html: str) -> dict() for
|
CodeGeneratorGraph is a script generator pipeline that generates
|
||||||
extracting the wanted information from a HTML page. The code generated is in Python and uses the library BeautifulSoup.
|
the function extract_data(html: str) -> dict() for
|
||||||
|
extracting the wanted information from a HTML page. The
|
||||||
|
code generated is in Python and uses the library BeautifulSoup.
|
||||||
It requires a user prompt, a source URL, and an output schema.
|
It requires a user prompt, a source URL, and an output schema.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -60,7 +65,7 @@ class DepthSearchGraph(AbstractGraph):
|
|||||||
BaseGraph: A graph instance representing the web scraping workflow.
|
BaseGraph: A graph instance representing the web scraping workflow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
fetch_node = FetchNodeLevelK(
|
fetch_node_k = FetchNodeLevelK(
|
||||||
input="url| local_dir",
|
input="url| local_dir",
|
||||||
output=["docs"],
|
output=["docs"],
|
||||||
node_config={
|
node_config={
|
||||||
@ -73,7 +78,7 @@ class DepthSearchGraph(AbstractGraph):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
parse_node = ParseNodeDepthK(
|
parse_node_k = ParseNodeDepthK(
|
||||||
input="docs",
|
input="docs",
|
||||||
output=["docs"],
|
output=["docs"],
|
||||||
node_config={
|
node_config={
|
||||||
@ -81,15 +86,52 @@ class DepthSearchGraph(AbstractGraph):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
description_node = DescriptionNode(
|
||||||
|
input="docs",
|
||||||
|
output=["docs"],
|
||||||
|
node_config={
|
||||||
|
"llm_model": self.llm_model,
|
||||||
|
"verbose": self.config.get("verbose", False),
|
||||||
|
"cache_path": self.config.get("cache_path", False)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
rag_node = RAGNode (
|
||||||
|
input="docs",
|
||||||
|
output=["vectorial_db"],
|
||||||
|
node_config={
|
||||||
|
"llm_model": self.llm_model,
|
||||||
|
"embedder_model": self.config.get("embedder_model", False),
|
||||||
|
"verbose": self.config.get("verbose", False),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
generate_answer_k = GenerateAnswerNodeKLevel(
|
||||||
|
input="vectorial_db",
|
||||||
|
output=["answer"],
|
||||||
|
node_config={
|
||||||
|
"llm_model": self.llm_model,
|
||||||
|
"embedder_model": self.config.get("embedder_model", False),
|
||||||
|
"verbose": self.config.get("verbose", False),
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
return BaseGraph(
|
return BaseGraph(
|
||||||
nodes=[
|
nodes=[
|
||||||
fetch_node,
|
fetch_node_k,
|
||||||
parse_node
|
parse_node_k,
|
||||||
|
description_node,
|
||||||
|
rag_node,
|
||||||
|
generate_answer_k
|
||||||
],
|
],
|
||||||
edges=[
|
edges=[
|
||||||
(fetch_node, parse_node),
|
(fetch_node_k, parse_node_k),
|
||||||
|
(parse_node_k, description_node),
|
||||||
|
(description_node, rag_node),
|
||||||
|
(rag_node, generate_answer_k)
|
||||||
],
|
],
|
||||||
entry_point=fetch_node,
|
entry_point=fetch_node_k,
|
||||||
graph_name=self.__class__.__name__
|
graph_name=self.__class__.__name__
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -31,12 +31,11 @@ class DescriptionNode(BaseNode):
|
|||||||
input: str,
|
input: str,
|
||||||
output: List[str],
|
output: List[str],
|
||||||
node_config: Optional[dict] = None,
|
node_config: Optional[dict] = None,
|
||||||
node_name: str = "RAG",
|
node_name: str = "DESCRIPTION",
|
||||||
):
|
):
|
||||||
super().__init__(node_name, "node", input, output, 2, node_config)
|
super().__init__(node_name, "node", input, output, 2, node_config)
|
||||||
|
|
||||||
self.llm_model = node_config["llm_model"]
|
self.llm_model = node_config["llm_model"]
|
||||||
self.embedder_model = node_config.get("embedder_model", None)
|
|
||||||
self.verbose = (
|
self.verbose = (
|
||||||
False if node_config is None else node_config.get("verbose", False)
|
False if node_config is None else node_config.get("verbose", False)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user