Skip to content

Commit 8a52914

Browse files
authored
Merge pull request #429 from ScrapeGraphAI/421-default-prompt-template-customization
421 default prompt template customization
2 parents fd6142e + 3ee1743 commit 8a52914

17 files changed

+120
-20
lines changed

examples/extras/custom_prompt.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Basic example of scraping pipeline using SmartScraper
3+
"""
4+
import os
5+
import json
6+
from dotenv import load_dotenv
7+
from scrapegraphai.graphs import SmartScraperGraph
8+
from scrapegraphai.utils import prettify_exec_info
9+
10+
load_dotenv()
11+
12+
13+
# ************************************************
14+
# Define the configuration for the graph
15+
# ************************************************
16+
17+
openai_key = os.getenv("OPENAI_APIKEY")
18+
19+
prompt = "Some more info"
20+
21+
graph_config = {
22+
"llm": {
23+
"api_key": openai_key,
24+
"model": "gpt-3.5-turbo",
25+
},
26+
"additional_info": prompt,
27+
"verbose": True,
28+
"headless": False,
29+
}
30+
31+
# ************************************************
32+
# Create the SmartScraperGraph instance and run it
33+
# ************************************************
34+
35+
smart_scraper_graph = SmartScraperGraph(
36+
prompt="List me all the projects with their description",
37+
# also accepts a string with the already downloaded HTML code
38+
source="https://perinim.github.io/projects/",
39+
config=graph_config,
40+
)
41+
42+
result = smart_scraper_graph.run()
43+
print(json.dumps(result, indent=4))
44+
45+
# ************************************************
46+
# Get graph execution info
47+
# ************************************************
48+
49+
graph_exec_info = smart_scraper_graph.get_execution_info()
50+
print(prettify_exec_info(graph_exec_info))

scrapegraphai/graphs/csv_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def _create_graph(self):
5050
output=["answer"],
5151
node_config={
5252
"llm_model": self.llm_model,
53+
"additional_info": self.config.get("additional_info"),
5354
"schema": self.schema,
5455
}
5556
)

scrapegraphai/graphs/deep_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def _create_repeated_graph(self) -> BaseGraph:
9595
output=["answer"],
9696
node_config={
9797
"llm_model": self.llm_model,
98+
"additional_info": self.config.get("additional_info"),
9899
"schema": self.schema
99100
}
100101
)

scrapegraphai/graphs/json_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def _create_graph(self) -> BaseGraph:
7575
output=["answer"],
7676
node_config={
7777
"llm_model": self.llm_model,
78+
"additional_info": self.config.get("additional_info"),
7879
"schema": self.schema
7980
}
8081
)

scrapegraphai/graphs/markdown_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def _create_graph(self) -> BaseGraph:
7676
output=["answer"],
7777
node_config={
7878
"llm_model": self.llm_model,
79+
"additional_info": self.config.get("additional_info"),
7980
"schema": self.schema,
8081
}
8182
)

scrapegraphai/graphs/omni_scraper_graph.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from ..models import OpenAIImageToText
2020

21-
2221
class OmniScraperGraph(AbstractGraph):
2322
"""
2423
OmniScraper is a scraping pipeline that automates the process of
@@ -60,7 +59,6 @@ def __init__(self, prompt: str, source: str, config: dict, schema: Optional[Base
6059
super().__init__(prompt, config, source, schema)
6160

6261
self.input_key = "url" if source.startswith("http") else "local_dir"
63-
6462

6563
def _create_graph(self) -> BaseGraph:
6664
"""
@@ -104,6 +102,7 @@ def _create_graph(self) -> BaseGraph:
104102
output=["answer"],
105103
node_config={
106104
"llm_model": self.llm_model,
105+
"additional_info": self.config.get("additional_info"),
107106
"schema": self.schema
108107
}
109108
)

scrapegraphai/graphs/pdf_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _create_graph(self) -> BaseGraph:
8989
output=["answer"],
9090
node_config={
9191
"llm_model": self.llm_model,
92+
"additional_info": self.config.get("additional_info"),
9293
"schema": self.schema
9394
}
9495
)

scrapegraphai/graphs/script_creator_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _create_graph(self) -> BaseGraph:
8484
output=["answer"],
8585
node_config={
8686
"llm_model": self.llm_model,
87+
"additional_info": self.config.get("additional_info"),
8788
"schema": self.schema,
8889
},
8990
library=self.library,

scrapegraphai/graphs/smart_scraper_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def _create_graph(self) -> BaseGraph:
9191
output=["answer"],
9292
node_config={
9393
"llm_model": self.llm_model,
94+
"additional_info": self.config.get("additional_info"),
9495
"schema": self.schema,
9596
}
9697
)

scrapegraphai/graphs/speech_graph.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def _create_graph(self) -> BaseGraph:
8484
output=["answer"],
8585
node_config={
8686
"llm_model": self.llm_model,
87+
"additional_info": self.config.get("additional_info"),
8788
"schema": self.schema
8889
}
8990
)

0 commit comments

Comments
 (0)