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

Class AbstractGraph

scrapegraphai/graphs/abstract_graph.py:27–341  ·  view source on GitHub ↗

Scaffolding class for creating a graph representation and executing it. 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

25
26
27class AbstractGraph(ABC):
28 """
29 Scaffolding class for creating a graph representation and executing it.
30
31 prompt (str): The prompt for the graph.
32 source (str): The source of the graph.
33 config (dict): Configuration parameters for the graph.
34 schema (BaseModel): The schema for the graph output.
35 llm_model: An instance of a language model client, configured for generating answers.
36 verbose (bool): A flag indicating whether to show print statements during execution.
37 headless (bool): A flag indicating whether to run the graph in headless mode.
38
39 Args:
40 prompt (str): The prompt for the graph.
41 config (dict): Configuration parameters for the graph.
42 source (str, optional): The source of the graph.
43 schema (str, optional): The schema for the graph output.
44
45 Example:
46 >>> class MyGraph(AbstractGraph):
47 ... def _create_graph(self):
48 ... # Implementation of graph creation here
49 ... return graph
50 ...
51 >>> my_graph = MyGraph("Example Graph",
52 {"llm": {"model": "gpt-3.5-turbo"}}, "example_source")
53 >>> result = my_graph.run()
54 """
55
56 def __init__(
57 self,
58 prompt: str,
59 config: dict,
60 source: Optional[str] = None,
61 schema: Optional[Type[BaseModel]] = None,
62 ):
63 self.prompt = prompt
64 self.source = source
65 self.config = config
66 self.schema = schema
67 self.llm_model = self._create_llm(config["llm"])
68 self.verbose = False if config is None else config.get("verbose", False)
69 self.headless = True if self.config is None else config.get("headless", True)
70 self.loader_kwargs = self.config.get("loader_kwargs", {})
71 self.cache_path = self.config.get("cache_path", False)
72 self.browser_base = self.config.get("browser_base")
73 self.scrape_do = self.config.get("scrape_do")
74 self.storage_state = self.config.get("storage_state")
75 self.timeout = self.config.get("timeout", 480)
76
77 self.graph = self._create_graph()
78 self.final_state = None
79 self.execution_info = None
80
81 verbose = bool(config and config.get("verbose"))
82
83 if verbose:
84 set_verbosity_info()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected