Python scraper based on AI
Python ai-crawlerai-scrapingai-searchcrawlerdata-extractionfirecrawl-alternativelarge-language-modelllmmarkdownragscrapingscraping-pythonweb-crawlerweb-crawlersweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
add examples
Marco Vinciguerraf42d47e2c36d
diff --git a/examples/anthropic/search_link_graph_haiku.py b/examples/anthropic/search_link_graph_haiku.pynew file mode 100644index 00000000..ccfbc1d2--- /dev/null+++ b/examples/anthropic/search_link_graph_haiku.py@@ -0,0 +1,57 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_openai import AzureChatOpenAI+from langchain_openai import AzureOpenAIEmbeddings++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++llm_model_instance = AzureChatOpenAI(+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+ azure_deployment=os.environ["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"]+)++embedder_model_instance = AzureOpenAIEmbeddings(+ azure_deployment=os.environ["AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME"],+ openai_api_version=os.environ["AZURE_OPENAI_API_VERSION"],+)++# ************************************************+# Create the SmartScraperGraph instance and run it+# ************************************************++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/azure/search_link_graph_azure.py b/examples/azure/search_link_graph_azure.pynew file mode 100644index 00000000..f940c2a4--- /dev/null+++ b/examples/azure/search_link_graph_azure.py@@ -0,0 +1,52 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++groq_key = os.getenv("GROQ_APIKEY")++graph_config = {+ "llm": {+ "model": "groq/gemma-7b-it",+ "api_key": groq_key,+ "temperature": 0+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "headless": False+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/bedrock/search_link_graph_bedrock.py b/examples/bedrock/search_link_graph_bedrock.pynew file mode 100644index 00000000..116dea01--- /dev/null+++ b/examples/bedrock/search_link_graph_bedrock.py@@ -0,0 +1,45 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "client": "client_name",+ "model": "bedrock/anthropic.claude-3-sonnet-20240229-v1:0",+ "temperature": 0.0+ },+ "embeddings": {+ "model": "bedrock/cohere.embed-multilingual-v3"+ }+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/deepseek/search_link_graph_deepseek.py b/examples/deepseek/search_link_graph_deepseek.pynew file mode 100644index 00000000..30e4a9b3--- /dev/null+++ b/examples/deepseek/search_link_graph_deepseek.py@@ -0,0 +1,52 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++deepseek_key = os.getenv("DEEPSEEK_APIKEY")++graph_config = {+ "llm": {+ "model": "deepseek-chat",+ "openai_api_key": deepseek_key,+ "openai_api_base": 'https://api.deepseek.com/v1',+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "verbose": True,+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/ernie/search_graph_ernie.py b/examples/ernie/search_graph_ernie.pyindex 22802c6e..c04d9f9b 100644--- a/examples/ernie/search_graph_ernie.py+++ b/examples/ernie/search_graph_ernie.py@@ -12,15 +12,18 @@ load_dotenv()# Define the configuration for the graph# ************************************************-openai_key = os.getenv("OPENAI_APIKEY")-graph_config = {"llm": {- "api_key": openai_key,- "model": "gpt-3.5-turbo",- },- "max_results": 2,- "verbose": True,+ "model": "ernie-bot-turbo",+ "ernie_client_id": "<ernie_client_id>",+ "ernie_client_secret": "<ernie_client_secret>",+ "temperature": 0.1+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "base_url": "http://localhost:11434"},+ "library": "beautifulsoup"}# ************************************************diff --git a/examples/ernie/search_link_graph_ernie.py b/examples/ernie/search_link_graph_ernie.pynew file mode 100644index 00000000..466b230c--- /dev/null+++ b/examples/ernie/search_link_graph_ernie.py@@ -0,0 +1,46 @@+"""+Example of Search Graph+"""+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++graph_config = {+ "llm": {+ "model": "ernie-bot-turbo",+ "ernie_client_id": "<ernie_client_id>",+ "ernie_client_secret": "<ernie_client_secret>",+ "temperature": 0.1+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ "base_url": "http://localhost:11434"},+ "library": "beautifulsoup"+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/fireworks/search_link_graph_fireworks.py b/examples/fireworks/search_link_graph_fireworks.pynew file mode 100644index 00000000..a1d3a979--- /dev/null+++ b/examples/fireworks/search_link_graph_fireworks.py@@ -0,0 +1,52 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++fireworks_api_key = os.getenv("FIREWORKS_APIKEY")++graph_config = {+ "llm": {+ "api_key": fireworks_api_key,+ "model": "fireworks/accounts/fireworks/models/mixtral-8x7b-instruct"+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "max_results": 2,+ "verbose": True,+ "headless": False,+}+# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/gemini/search_link_graph_gemini.py b/examples/gemini/search_link_graph_gemini.pynew file mode 100644index 00000000..937038bd--- /dev/null+++ b/examples/gemini/search_link_graph_gemini.py@@ -0,0 +1,44 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++gemini_key = os.getenv("GOOGLE_APIKEY")++graph_config = {+ "llm": {+ "api_key": gemini_key,+ "model": "gemini-pro",+ },+}+# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/groq/search_link_graph_groq.py b/examples/groq/search_link_graph_groq.pynew file mode 100644index 00000000..f940c2a4--- /dev/null+++ b/examples/groq/search_link_graph_groq.py@@ -0,0 +1,52 @@+"""+Example of Search Graph+"""+import os+from dotenv import load_dotenv+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info++# ************************************************+# Define the configuration for the graph+# ************************************************++load_dotenv()++groq_key = os.getenv("GROQ_APIKEY")++graph_config = {+ "llm": {+ "model": "groq/gemma-7b-it",+ "api_key": groq_key,+ "temperature": 0+ },+ "embeddings": {+ "model": "ollama/nomic-embed-text",+ "temperature": 0,+ # "base_url": "http://localhost:11434", # set ollama URL arbitrarily+ },+ "headless": False+}++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")diff --git a/examples/groq/smart_scraper_groq.py b/examples/groq/smart_scraper_groq.pyindex c1a5d319..f828cdec 100644--- a/examples/groq/smart_scraper_groq.py+++ b/examples/groq/smart_scraper_groq.py@@ -9,7 +9,6 @@ from scrapegraphai.utils import prettify_exec_infoload_dotenv()-# ************************************************# Define the configuration for the graph# ************************************************diff --git a/examples/huggingfacehub/search_link_graph_huggingfacehub.py b/examples/huggingfacehub/search_link_graph_huggingfacehub.pynew file mode 100644index 00000000..a49fb3b9--- /dev/null+++ b/examples/huggingfacehub/search_link_graph_huggingfacehub.py@@ -0,0 +1,54 @@+"""+Example of Search Graph+"""+import os+from scrapegraphai.graphs import SearchGraph+from scrapegraphai.utils import convert_to_csv, convert_to_json, prettify_exec_info+from langchain_community.llms import HuggingFaceEndpoint+from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings++# ************************************************+# Define the configuration for the graph+# ************************************************+# ************************************************++HUGGINGFACEHUB_API_TOKEN = os.getenv('HUGGINGFACEHUB_API_TOKEN')++repo_id = "mistralai/Mistral-7B-Instruct-v0.2"++llm_model_instance = HuggingFaceEndpoint(+ repo_id=repo_id, max_length=128, temperature=0.5, token=HUGGINGFACEHUB_API_TOKEN+)++embedder_model_instance = HuggingFaceInferenceAPIEmbeddings(+ api_key=HUGGINGFACEHUB_API_TOKEN, model_name="sentence-transformers/all-MiniLM-l6-v2"+)++graph_config = {+ "llm": {"model_instance": llm_model_instance},+ "embeddings": {"model_instance": embedder_model_instance}+}+++# ************************************************+# Create the SearchGraph instance and run it+# ************************************************++search_graph = SearchGraph(+ prompt="List me the best escursions near Trento",+ config=graph_config+)++result = search_graph.run()+print(result)++# ************************************************+# Get graph execution info+# ************************************************++graph_exec_info = search_graph.get_execution_info()+print(prettify_exec_info(graph_exec_info))++# Save to json and csv+convert_to_csv(result, "result")+convert_to_json(result, "result")