hjxdl 0.1.31__py3-none-any.whl → 0.1.32__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hdl/_version.py +2 -2
- hdl/utils/database_tools/web.py +51 -0
- hdl/utils/desc/func_desc.py +18 -0
- {hjxdl-0.1.31.dist-info → hjxdl-0.1.32.dist-info}/METADATA +2 -1
- {hjxdl-0.1.31.dist-info → hjxdl-0.1.32.dist-info}/RECORD +7 -6
- {hjxdl-0.1.31.dist-info → hjxdl-0.1.32.dist-info}/WHEEL +0 -0
- {hjxdl-0.1.31.dist-info → hjxdl-0.1.32.dist-info}/top_level.txt +0 -0
hdl/_version.py
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
from duckduckgo_search import DDGS
|
2
|
+
import requests
|
3
|
+
from bs4 import BeautifulSoup
|
4
|
+
|
5
|
+
def web_search_text(
|
6
|
+
query_text: str,
|
7
|
+
max_results=3,
|
8
|
+
):
|
9
|
+
"""Searches the web for text related to the given query.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
query_text (str): The text to search for.
|
13
|
+
max_results (int, optional): The maximum number of results to retrieve. Defaults to 3.
|
14
|
+
|
15
|
+
Returns:
|
16
|
+
str: Text retrieved from the web search results.
|
17
|
+
"""
|
18
|
+
result_str = "联网搜索到的信息如下:\n"
|
19
|
+
try:
|
20
|
+
results = DDGS().text(
|
21
|
+
query_text,
|
22
|
+
max_results=max_results,
|
23
|
+
backend="html"
|
24
|
+
)
|
25
|
+
except Exception as e:
|
26
|
+
return f"{str(e)}: 未搜索(获取)到相关内容,可过一段时间再次尝试。"
|
27
|
+
for result in results:
|
28
|
+
if "wikipedia" not in result['href']:
|
29
|
+
|
30
|
+
headers = {
|
31
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
|
32
|
+
}
|
33
|
+
try:
|
34
|
+
# 发送请求
|
35
|
+
response = requests.get(result['href'], headers=headers)
|
36
|
+
|
37
|
+
# 检查请求状态码
|
38
|
+
if response.status_code == 200:
|
39
|
+
# 解析网页内容
|
40
|
+
soup = BeautifulSoup(response.content, 'html.parser')
|
41
|
+
text = soup.get_text()
|
42
|
+
|
43
|
+
# 删除空行
|
44
|
+
cleaned_text = "\n".join([line.strip() for line in text.splitlines() if line.strip()])
|
45
|
+
|
46
|
+
print(cleaned_text)
|
47
|
+
result_str += cleaned_text
|
48
|
+
result_str += "\n"
|
49
|
+
return result_str
|
50
|
+
except Exception as e:
|
51
|
+
return f"{str(e)}: 未搜索(获取)到相关内容。"
|
hdl/utils/desc/func_desc.py
CHANGED
@@ -30,6 +30,24 @@ FN_DESC = {
|
|
30
30
|
}
|
31
31
|
}
|
32
32
|
|
33
|
+
""",
|
34
|
+
"web_search_text": """
|
35
|
+
## 函数名:web_search_text
|
36
|
+
描述:在用户明确要联网查询回答他的问题时,调用此工具可以获得该问题联网搜索的相关内容
|
37
|
+
参数:
|
38
|
+
# query_text (str): 从用户提的问题中获取,用于在网络中搜索信息
|
39
|
+
# max_results (int, optional): 搜索条目的最大数目,若用户指定了数目,则使用用户指定的数目,若用户提问中没有指定,则设定此值为 3 。
|
40
|
+
返回值 (str):这个城市当前所在时区的日期和时间
|
41
|
+
需要返回的json
|
42
|
+
{
|
43
|
+
"function_name": "web_search_text",
|
44
|
+
"params":
|
45
|
+
{
|
46
|
+
"query_text": <query from user question>,
|
47
|
+
"max_results": <num of max results, default to 3>
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
33
51
|
""",
|
34
52
|
"default": None
|
35
53
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: hjxdl
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.32
|
4
4
|
Summary: A collection of functions for Jupyter notebooks
|
5
5
|
Home-page: https://github.com/huluxiaohuowa/hdl
|
6
6
|
Author: Jianxing Hu
|
@@ -17,6 +17,7 @@ Requires-Dist: sentence-transformers
|
|
17
17
|
Requires-Dist: geopy
|
18
18
|
Requires-Dist: timezonefinder
|
19
19
|
Requires-Dist: pytz
|
20
|
+
Requires-Dist: duckduckgo-search[lxml]
|
20
21
|
|
21
22
|
# DL framework by Jianxing
|
22
23
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
hdl/__init__.py,sha256=GffnD0jLJdhkd-vo989v40N90sQbofkayRBwxc6TVhQ,72
|
2
|
-
hdl/_version.py,sha256=
|
2
|
+
hdl/_version.py,sha256=NA9VwrV1Psl9VgGLwTXusny4jcXqQVe84OBjJLMEnkI,413
|
3
3
|
hdl/args/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
4
|
hdl/args/loss_args.py,sha256=s7YzSdd7IjD24rZvvOrxLLFqMZQb9YylxKeyelSdrTk,70
|
5
5
|
hdl/controllers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -120,8 +120,9 @@ hdl/utils/chemical_tools/sdf.py,sha256=71PEqU0H885L6IeGHEa6n7ZLZThvMsZOVLuFG2wno
|
|
120
120
|
hdl/utils/database_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
121
121
|
hdl/utils/database_tools/connect.py,sha256=KUnVG-8raifEJ_N0b3c8LkTTIfn9NIyw8LX6qvpA3YU,723
|
122
122
|
hdl/utils/database_tools/datetime.py,sha256=xqE2xNiOpADzX-R8_bM0bioJRF3Ay9Jp1CAG6dy6uVI,1202
|
123
|
+
hdl/utils/database_tools/web.py,sha256=saGh4gICB8yUylTVhSFBL-SzA9-8xxLln4rUFFHz4Eg,1805
|
123
124
|
hdl/utils/desc/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
124
|
-
hdl/utils/desc/func_desc.py,sha256=
|
125
|
+
hdl/utils/desc/func_desc.py,sha256=pTsqcozGsdO1gVXpN7_IaDv7fNfZ7elyI_ebyXvlsA8,1567
|
125
126
|
hdl/utils/desc/template.py,sha256=a3NcSihzZMm9Bk76iDVe54_xBDceGmLebS0XMONE3nk,1172
|
126
127
|
hdl/utils/general/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
127
128
|
hdl/utils/general/glob.py,sha256=8-RCnt6L297wMIfn34ZAMCsGCZUjHG3MGglGZI1cX0g,491
|
@@ -133,7 +134,7 @@ hdl/utils/schedulers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
133
134
|
hdl/utils/schedulers/norm_lr.py,sha256=bDwCmdEK-WkgxQMFBiMuchv8Mm7C0-GZJ6usm-PQk14,4461
|
134
135
|
hdl/utils/weather/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
135
136
|
hdl/utils/weather/weather.py,sha256=k11o6wM15kF8b9NMlEfrg68ak-SfSYLN3nOOflFUv-I,4381
|
136
|
-
hjxdl-0.1.
|
137
|
-
hjxdl-0.1.
|
138
|
-
hjxdl-0.1.
|
139
|
-
hjxdl-0.1.
|
137
|
+
hjxdl-0.1.32.dist-info/METADATA,sha256=XqDgEezXMtJ7slXIG1n0-2kjoz3jYFUcqO0_0WuYXYs,737
|
138
|
+
hjxdl-0.1.32.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
|
139
|
+
hjxdl-0.1.32.dist-info/top_level.txt,sha256=-kxwTM5JPhylp06z3zAVO3w6_h7wtBfBo2zgM6YZoTk,4
|
140
|
+
hjxdl-0.1.32.dist-info/RECORD,,
|
File without changes
|
File without changes
|