MCPcopy Create free account
hub / github.com/ScrapeGraphAI/Scrapegraph-ai / JSONScraperGraph

Class JSONScraperGraph

scrapegraphai/graphs/json_scraper_graph.py:14–99  ·  view source on GitHub ↗

JSONScraperGraph defines a scraping pipeline for JSON files. Attributes: prompt (str): The prompt for the graph. source (str): The source of the graph. config (dict): Configuration parameters for the graph. schema (BaseModel): The schema for the graph output

Source from the content-addressed store, hash-verified

12
13
14class JSONScraperGraph(AbstractGraph):
15 """
16 JSONScraperGraph defines a scraping pipeline for JSON files.
17
18 Attributes:
19 prompt (str): The prompt for the graph.
20 source (str): The source of the graph.
21 config (dict): Configuration parameters for the graph.
22 schema (BaseModel): The schema for the graph output.
23 llm_model: An instance of a language model client, configured for generating answers.
24 embedder_model: An instance of an embedding model client,
25 configured for generating embeddings.
26 verbose (bool): A flag indicating whether to show print statements during execution.
27 headless (bool): A flag indicating whether to run the graph in headless mode.
28
29 Args:
30 prompt (str): The prompt for the graph.
31 source (str): The source of the graph.
32 config (dict): Configuration parameters for the graph.
33 schema (BaseModel): The schema for the graph output.
34
35 Example:
36 >>> json_scraper = JSONScraperGraph(
37 ... "List me all the attractions in Chioggia.",
38 ... "data/chioggia.json",
39 ... {"llm": {"model": "openai/gpt-3.5-turbo"}}
40 ... )
41 >>> result = json_scraper.run()
42 """
43
44 def __init__(
45 self,
46 prompt: str,
47 source: str,
48 config: dict,
49 schema: Optional[Type[BaseModel]] = None,
50 ):
51 super().__init__(prompt, config, source, schema)
52
53 self.input_key = "json" if source.endswith("json") else "json_dir"
54
55 def _create_graph(self) -> BaseGraph:
56 """
57 Creates the graph of nodes representing the workflow for web scraping.
58
59 Returns:
60 BaseGraph: A graph instance representing the web scraping workflow.
61 """
62
63 fetch_node = FetchNode(
64 input="json | json_dir",
65 output=["doc"],
66 )
67
68 generate_answer_node = GenerateAnswerNode(
69 input="user_prompt & (relevant_chunks | parsed_doc | doc)",
70 output=["answer"],
71 node_config={

Calls

no outgoing calls