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

Class CSVScraperGraph

scrapegraphai/graphs/csv_scraper_graph.py:14–103  ·  view source on GitHub ↗

A class representing a graph for extracting information from CSV files. Attributes: prompt (str): The prompt used to generate an answer. source (str): The source of the data, which can be either a CSV file or a directory containing multiple CSV files. config

Source from the content-addressed store, hash-verified

12
13
14class CSVScraperGraph(AbstractGraph):
15 """
16 A class representing a graph for extracting information from CSV files.
17
18 Attributes:
19 prompt (str): The prompt used to generate an answer.
20 source (str): The source of the data, which can be either a CSV
21 file or a directory containing multiple CSV files.
22 config (dict): Additional configuration parameters needed by some nodes in the graph.
23
24 Methods:
25 __init__ (prompt: str, source: str, config: dict, schema: Optional[Type[BaseModel]] = None):
26 Initializes the CSVScraperGraph with a prompt, source, and configuration.
27
28 __init__ initializes the CSVScraperGraph class. It requires the user's prompt as input,
29 along with the source of the data (which can be either a single CSV file or a directory
30 containing multiple CSV files), and any necessary configuration parameters.
31
32 Methods:
33 _create_graph (): Creates the graph of nodes representing the workflow for web scraping.
34
35 _create_graph generates the web scraping process workflow
36 represented by a directed acyclic graph.
37 This method is used internally to create the scraping pipeline
38 without having to execute it immediately. The result is a BaseGraph instance
39 containing nodes that fetch and process data from a source, and other helper functions.
40
41 Methods:
42 run () -> str: Executes the web scraping process and returns
43 the answer to the prompt as a string.
44 run runs the CSVScraperGraph class to extract information from a CSV file based
45 on the user's prompt. It requires no additional arguments since all necessary data
46 is stored within the class instance.
47 The method fetches the relevant chunks of text or speech,
48 generates an answer based on these chunks, and returns this answer as a string.
49 """
50
51 def __init__(
52 self,
53 prompt: str,
54 source: str,
55 config: dict,
56 schema: Optional[Type[BaseModel]] = None,
57 ):
58 """
59 Initializes the CSVScraperGraph with a prompt, source, and configuration.
60 """
61 super().__init__(prompt, config, source, schema)
62
63 self.input_key = "csv" if source.endswith("csv") else "csv_dir"
64
65 def _create_graph(self):
66 """
67 Creates the graph of nodes representing the workflow for web scraping.
68 """
69
70 fetch_node = FetchNode(
71 input="csv | csv_dir",

Callers 4

test_scrape_csv_fileMethod · 0.90
test_scrape_csv_urlMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_scrape_csv_fileMethod · 0.72
test_scrape_csv_urlMethod · 0.72