Skip to content

Python scraper based on AI

test:add moonshot example

smith penga8ca1fc9102b
diff --git a/examples/model_instance/smart_scraper_with_moonlight_model_instace.py b/examples/model_instance/smart_scraper_with_model_instace.py
similarity index 100%
rename from examples/model_instance/smart_scraper_with_moonlight_model_instace.py
rename to examples/model_instance/smart_scraper_with_model_instace.py
diff --git a/examples/moonshot/.env.example b/examples/moonshot/.env.example
new file mode 100644
index 00000000..c5a7ed85
--- /dev/null
+++ b/examples/moonshot/.env.example
@@ -0,0 +1 @@
+MOONLIGHT_API_KEY="YOUR MOONLIGHT API KEY"
\ No newline at end of file
diff --git a/examples/moonshot/readme.md b/examples/moonshot/readme.md
new file mode 100644
index 00000000..6b9b2f21
--- /dev/null
+++ b/examples/moonshot/readme.md
@@ -0,0 +1 @@
+This folder offer an example of how to use ScrapeGraph-AI with Moonshot and SmartScraperGraph. More usage examples can refer to openai exapmles.
\ No newline at end of file
diff --git a/examples/moonshot/smart_scraper_with_moonshot.py b/examples/moonshot/smart_scraper_with_moonshot.py
new file mode 100644
index 00000000..b362414f
--- /dev/null
+++ b/examples/moonshot/smart_scraper_with_moonshot.py
@@ -0,0 +1,53 @@
+"""
+Basic example of scraping pipeline using SmartScraper and model_instace
+"""
+
+import os, json
+from scrapegraphai.graphs import SmartScraperGraph
+from scrapegraphai.utils import prettify_exec_info
+from langchain_community.chat_models.moonshot import MoonshotChat
+from dotenv import load_dotenv
+load_dotenv()
+
+# ************************************************
+# Define the configuration for the graph
+# ************************************************
+
+
+llm_instance_config = {
+ "model": "moonshot-v1-8k",
+ "base_url": "https://api.moonshot.cn/v1",
+ "moonshot_api_key": os.getenv("MOONLIGHT_API_KEY"),
+}
+
+
+llm_model_instance = MoonshotChat(**llm_instance_config)
+
+graph_config = {
+ "llm": {
+ "model_instance": llm_model_instance,
+ "model_tokens": 10000
+ },
+ "verbose": True,
+ "headless": True,
+}
+
+# ************************************************
+# Create the SmartScraperGraph instance and run it
+# ************************************************
+
+smart_scraper_graph = SmartScraperGraph(
+ prompt="List me what does the company do, the name and a contact email.",
+ source="https://scrapegraphai.com/",
+ config=graph_config
+)
+
+result = smart_scraper_graph.run()
+print(json.dumps(result, indent=4))
+
+# ************************************************
+# Get graph execution info
+# ************************************************
+
+graph_exec_info = smart_scraper_graph.get_execution_info()
+print(prettify_exec_info(graph_exec_info))