Skip to content

Commit fb74a52

Browse files
committed
update one_api example with schema
1 parent 1d958be commit fb74a52

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

examples/local_models/smart_scraper_schema_ollama.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import json
55
from scrapegraphai.graphs import SmartScraperGraph
66
from scrapegraphai.utils import prettify_exec_info
7+
78
# ************************************************
89
# Define the configuration for the graph
910
# ************************************************
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"""
2+
Basic example of scraping pipeline using SmartScraper
3+
"""
4+
5+
from scrapegraphai.graphs import SmartScraperGraph
6+
from scrapegraphai.utils import prettify_exec_info
7+
8+
# ************************************************
9+
# Define the configuration for the graph
10+
# ************************************************
11+
schema= """
12+
{
13+
"Projects": [
14+
"Project #":
15+
{
16+
"title": "...",
17+
"description": "...",
18+
},
19+
"Project #":
20+
{
21+
"title": "...",
22+
"description": "...",
23+
}
24+
]
25+
}
26+
"""
27+
28+
# ************************************************
29+
# Define the configuration for the graph
30+
# *********************************************
31+
32+
graph_config = {
33+
"llm": {
34+
"api_key": "***************************",
35+
"model": "oneapi/qwen-turbo",
36+
"base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL
37+
},
38+
"embeddings": {
39+
"model": "ollama/nomic-embed-text",
40+
"base_url": "http://127.0.0.1:11434", # 设置 Ollama URL
41+
}
42+
}
43+
44+
# ************************************************
45+
# Create the SmartScraperGraph instance and run it
46+
# ************************************************
47+
48+
smart_scraper_graph = SmartScraperGraph(
49+
prompt="该网站为XXXXX,请提取出标题、发布时间、发布来源以及内容摘要,并以中文回答。",
50+
# 也可以使用已下载的 HTML 代码的字符串
51+
source="http://XXXX",
52+
schema=schema,
53+
config=graph_config
54+
)
55+
56+
# ************************************************
57+
# Get graph execution info
58+
# ************************************************
59+
result = smart_scraper_graph.run()
60+
print(result)
61+
print(prettify_exec_info(result))

0 commit comments

Comments
 (0)