Skip to content

Commit 1d958be

Browse files
authored
Merge pull request #303 from VinciGit00/295-scrapegraph-ai接入oneapi模型qwen-turbo
add OneAPI integration
2 parents ecd98b2 + b6f1766 commit 1d958be

File tree

4 files changed

+75
-6
lines changed

4 files changed

+75
-6
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
12+
graph_config = {
13+
"llm": {
14+
"api_key": "***************************",
15+
"model": "oneapi/qwen-turbo",
16+
"base_url": "http://127.0.0.1:3000/v1", # 设置 OneAPI URL
17+
},
18+
"embeddings": {
19+
"model": "ollama/nomic-embed-text",
20+
"base_url": "http://127.0.0.1:11434", # 设置 Ollama URL
21+
}
22+
}
23+
24+
# ************************************************
25+
# Create the SmartScraperGraph instance and run it
26+
# ************************************************
27+
28+
smart_scraper_graph = SmartScraperGraph(
29+
prompt="该网站为XXXXX,请提取出标题、发布时间、发布来源以及内容摘要,并以中文回答。",
30+
# 也可以使用已下载的 HTML 代码的字符串
31+
source="http://XXXX",
32+
config=graph_config
33+
)
34+
35+
# ************************************************
36+
# Get graph execution info
37+
# ************************************************
38+
result = smart_scraper_graph.run()
39+
print(result)
40+
print(prettify_exec_info(result))

scrapegraphai/graphs/abstract_graph.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
HuggingFace,
2323
Ollama,
2424
OpenAI,
25+
OneApi
2526
)
2627
from ..utils.logging import set_verbosity_debug, set_verbosity_warning
2728

@@ -55,19 +56,20 @@ class AbstractGraph(ABC):
5556
... # Implementation of graph creation here
5657
... return graph
5758
...
58-
>>> my_graph = MyGraph("Example Graph", {"llm": {"model": "gpt-3.5-turbo"}}, "example_source")
59+
>>> my_graph = MyGraph("Example Graph",
60+
{"llm": {"model": "gpt-3.5-turbo"}}, "example_source")
5961
>>> result = my_graph.run()
6062
"""
6163

62-
def __init__(self, prompt: str, config: dict, source: Optional[str] = None, schema: Optional[str] = None):
64+
def __init__(self, prompt: str, config: dict,
65+
source: Optional[str] = None, schema: Optional[str] = None):
6366

6467
self.prompt = prompt
6568
self.source = source
6669
self.config = config
6770
self.schema = schema
6871
self.llm_model = self._create_llm(config["llm"], chat=True)
69-
self.embedder_model = self._create_default_embedder(llm_config=config["llm"]
70-
) if "embeddings" not in config else self._create_embedder(
72+
self.embedder_model = self._create_default_embedder(llm_config=config["llm"] ) if "embeddings" not in config else self._create_embedder(
7173
config["embeddings"])
7274
self.verbose = False if config is None else config.get(
7375
"verbose", False)
@@ -99,7 +101,7 @@ def __init__(self, prompt: str, config: dict, source: Optional[str] = None, sche
99101
"llm_model": self.llm_model,
100102
"embedder_model": self.embedder_model
101103
}
102-
104+
103105
self.set_common_params(common_params, overwrite=False)
104106

105107
# set burr config
@@ -174,7 +176,14 @@ def _create_llm(self, llm_config: dict, chat=False) -> object:
174176
except KeyError as exc:
175177
raise KeyError("Model not supported") from exc
176178
return OpenAI(llm_params)
177-
179+
elif "oneapi" in llm_params["model"]:
180+
# take the model after the last dash
181+
llm_params["model"] = llm_params["model"].split("/")[-1]
182+
try:
183+
self.model_token = models_tokens["oneapi"][llm_params["model"]]
184+
except KeyError as exc:
185+
raise KeyError("Model Model not supported") from exc
186+
return OneApi(llm_params)
178187
elif "azure" in llm_params["model"]:
179188
# take the model after the last dash
180189
llm_params["model"] = llm_params["model"].split("/")[-1]

scrapegraphai/helpers/models_tokens.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
"snowflake-arctic-embed:l": 8192,
8181
"mxbai-embed-large": 512,
8282
},
83+
"oneapi": {
84+
"qwen-turbo": 16380
85+
},
8386
"groq": {
8487
"llama3-8b-8192": 8192,
8588
"llama3-70b-8192": 8192,

scrapegraphai/models/oneapi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
OpenAI Module
3+
"""
4+
from langchain_openai import ChatOpenAI
5+
6+
7+
class OneApi(ChatOpenAI):
8+
"""
9+
A wrapper for the OneApi class that provides default configuration
10+
and could be extended with additional methods if needed.
11+
12+
Args:
13+
llm_config (dict): Configuration parameters for the language model.
14+
"""
15+
16+
def __init__(self, llm_config: dict):
17+
super().__init__(**llm_config)

0 commit comments

Comments
 (0)