jarvis-ai-assistant 0.1.7__py3-none-any.whl → 0.1.8__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.
Potentially problematic release.
This version of jarvis-ai-assistant might be problematic. Click here for more details.
- jarvis/__init__.py +1 -1
- jarvis/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/__init__.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/base.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/bing_search.cpython-313.pyc +0 -0
- jarvis/tools/__pycache__/search.cpython-313.pyc +0 -0
- jarvis/tools/search.py +42 -9
- {jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/RECORD +12 -11
- {jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
jarvis/tools/search.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import requests
|
|
1
3
|
from typing import Dict, Any, List
|
|
2
|
-
from duckduckgo_search import DDGS
|
|
3
4
|
from ..utils import PrettyOutput, OutputType
|
|
4
5
|
from .webpage import WebpageTool
|
|
5
6
|
|
|
6
7
|
class SearchTool:
|
|
7
8
|
name = "search"
|
|
8
|
-
description = "
|
|
9
|
+
description = "使用搜索引擎搜索信息,并根据问题提取关键信息"
|
|
9
10
|
parameters = {
|
|
10
11
|
"type": "object",
|
|
11
12
|
"properties": {
|
|
@@ -30,6 +31,38 @@ class SearchTool:
|
|
|
30
31
|
"""初始化搜索工具,需要传入语言模型用于信息提取"""
|
|
31
32
|
self.model = model
|
|
32
33
|
self.webpage_tool = WebpageTool()
|
|
34
|
+
self.api_key = os.getenv("SEARCH_API_KEY")
|
|
35
|
+
self.engine = os.getenv("SEARCH_ENGINE", "bing")
|
|
36
|
+
if not self.api_key:
|
|
37
|
+
raise ValueError("未设置SEARCH_API_KEY环境变量")
|
|
38
|
+
|
|
39
|
+
def _search(self, query: str, max_results: int) -> List[Dict]:
|
|
40
|
+
"""执行搜索请求"""
|
|
41
|
+
url = "https://serpapi.webscrapingapi.com/v2"
|
|
42
|
+
params = {
|
|
43
|
+
"engine": self.engine,
|
|
44
|
+
"api_key": self.api_key,
|
|
45
|
+
"q": query
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
response = requests.get(url, params=params)
|
|
50
|
+
response.raise_for_status()
|
|
51
|
+
data = response.json()
|
|
52
|
+
|
|
53
|
+
# 从搜索结果中提取有机结果
|
|
54
|
+
results = []
|
|
55
|
+
if "organic" in data:
|
|
56
|
+
for result in data["organic"][:max_results]:
|
|
57
|
+
results.append({
|
|
58
|
+
"title": result.get("title", ""),
|
|
59
|
+
"href": result.get("link", ""),
|
|
60
|
+
"body": result.get("description", "")
|
|
61
|
+
})
|
|
62
|
+
return results
|
|
63
|
+
except Exception as e:
|
|
64
|
+
PrettyOutput.print(f"搜索请求失败: {str(e)}", OutputType.ERROR)
|
|
65
|
+
return []
|
|
33
66
|
|
|
34
67
|
def _extract_info(self, contents: List[str], question: str) -> str:
|
|
35
68
|
"""使用语言模型从网页内容中提取关键信息"""
|
|
@@ -68,18 +101,18 @@ class SearchTool:
|
|
|
68
101
|
PrettyOutput.print(f"相关问题: {question}", OutputType.INFO)
|
|
69
102
|
|
|
70
103
|
# 获取搜索结果
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
results = self._search(query, max_results)
|
|
105
|
+
if not results:
|
|
106
|
+
return {
|
|
107
|
+
"success": False,
|
|
108
|
+
"error": "未能获取任何搜索结果"
|
|
109
|
+
}
|
|
77
110
|
|
|
78
111
|
# 收集网页内容
|
|
79
112
|
contents = []
|
|
80
113
|
for i, result in enumerate(results, 1):
|
|
81
114
|
try:
|
|
82
|
-
PrettyOutput.print(f"正在读取第 {i}/{len(results)} 个结果... {result['title']} - {result['href']}
|
|
115
|
+
PrettyOutput.print(f"正在读取第 {i}/{len(results)} 个结果... {result['title']} - {result['href']}", OutputType.PROGRESS)
|
|
83
116
|
webpage_result = self.webpage_tool.execute({"url": result["href"]})
|
|
84
117
|
if webpage_result["success"]:
|
|
85
118
|
contents.append(f"\n来源 {i}:{result['href']}\n")
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
jarvis/__init__.py,sha256=
|
|
1
|
+
jarvis/__init__.py,sha256=QIcBZBFMcOFbIudbA0VykyqY4RphA3fWQlRP_kUMcPM,49
|
|
2
2
|
jarvis/agent.py,sha256=ePgdOCWdkw35KITvZOqcrJOGl-F4wzvrltHTw7N4p88,11014
|
|
3
3
|
jarvis/main.py,sha256=4IqebMKGoBGJMSNFE6E6GQ_Ay-uuOT-BLsQPnQVW47k,6705
|
|
4
4
|
jarvis/models.py,sha256=G9QkUqoyOyUx6eSqwbn3hCSwHguN0bUm7Nbd6Ql0IQs,3771
|
|
5
5
|
jarvis/utils.py,sha256=3hLtv-HcBL8Ngw69cowhARuIFrjcQ6yRP3Y1o9CvtsI,5992
|
|
6
6
|
jarvis/zte_llm.py,sha256=Us5D6zMdZT6SoSnUgKWQbxthGadXkulLs_oSmW5MPDo,4666
|
|
7
|
-
jarvis/__pycache__/__init__.cpython-313.pyc,sha256=
|
|
7
|
+
jarvis/__pycache__/__init__.cpython-313.pyc,sha256=lGXFfeYKcGsFZjgHY8y4zLca1xBIkr2zKSQv06rhoBY,208
|
|
8
8
|
jarvis/__pycache__/agent.cpython-313.pyc,sha256=itbFLk6qJ9FTjbiyj6DsQhu5NbdxVaP4g-SygRguvSc,11625
|
|
9
9
|
jarvis/__pycache__/main.cpython-313.pyc,sha256=6hWRW-RG_bZrqwhSQXyhKaJBXexgLqKa-_SZzAk6_eo,8479
|
|
10
10
|
jarvis/__pycache__/models.cpython-313.pyc,sha256=uWuRIjGrY4YDB3dGW5PGDLWaS03et8g11O725TjY_eU,5960
|
|
@@ -14,24 +14,25 @@ jarvis/__pycache__/zte_llm.cpython-313.pyc,sha256=R_HT_Gc6OQelxRLRQ-yB8Tf0sYHcb1
|
|
|
14
14
|
jarvis/tools/__init__.py,sha256=tH6YaApKpqs1YSjEllRzOZZUd-OTFKSZ5oA0zs7HdSE,297
|
|
15
15
|
jarvis/tools/base.py,sha256=zK-JteBwj9d2BD_7BSAp-zD7wgJbVBppAWyfFxaPObI,4114
|
|
16
16
|
jarvis/tools/file_ops.py,sha256=zTksx45NZm3iz9itN5iQGZ8DoxnSeTHdrnF08_ix7PU,3770
|
|
17
|
-
jarvis/tools/search.py,sha256=
|
|
17
|
+
jarvis/tools/search.py,sha256=HJQ1_-CXB9M4wiq4wbLYdI-Vz92JiA6LGnog3b1dDd4,5293
|
|
18
18
|
jarvis/tools/shell.py,sha256=7q52lA3slf0TdjBjP1bkwugoO5pB0eqh6cYjAzAXNtI,2547
|
|
19
19
|
jarvis/tools/sub_agent.py,sha256=QJYWdil1goZfo95CQkuhkjZBl-Rx6UvyeFMiGnDyjOA,2832
|
|
20
20
|
jarvis/tools/webpage.py,sha256=DBnh9gye6oL2nVjzU2SU4Jupsck8x9g9On-rbjV6d8Y,2386
|
|
21
|
-
jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=
|
|
22
|
-
jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=
|
|
21
|
+
jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=1d1eUI0FlaydGB8TFBln6s7cBKd6gcPdER2_DIfX2Aw,443
|
|
22
|
+
jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=2OJWYNsGJjKJs6Vdj9NcN_Snjd2bA_OLlB-zr2j4wfs,6462
|
|
23
|
+
jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=t4OZJrEgP35xdidDjVypxsDN07JAlh5PcpTkauFyllA,7029
|
|
23
24
|
jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=LbOp31JUzoRp5XVazy1VBqCQhpFg0qQYmVftFVY90V4,3628
|
|
24
25
|
jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
|
|
25
26
|
jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
|
|
26
|
-
jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=
|
|
27
|
+
jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=7lS5jDmClpHJXKnbBaUCys8CmW1YBJtZAa4c64JGO6I,6624
|
|
27
28
|
jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=QMaLUc1MtZXWod3msv_x7iMq2IybwMwz1OoaKsbm6U4,3271
|
|
28
29
|
jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=qzNLnQxqFZoAiYOPH4GrCGxaQVs-QWfTLspW5a1Xa6c,3144
|
|
29
30
|
jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
|
|
30
31
|
jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
|
|
31
32
|
jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
|
|
32
33
|
jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
|
|
33
|
-
jarvis_ai_assistant-0.1.
|
|
34
|
-
jarvis_ai_assistant-0.1.
|
|
35
|
-
jarvis_ai_assistant-0.1.
|
|
36
|
-
jarvis_ai_assistant-0.1.
|
|
37
|
-
jarvis_ai_assistant-0.1.
|
|
34
|
+
jarvis_ai_assistant-0.1.8.dist-info/METADATA,sha256=3zrOu0XJCW5EO4UbCeRIK0xNw6JcW60tFr6b6VdWET4,3719
|
|
35
|
+
jarvis_ai_assistant-0.1.8.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
36
|
+
jarvis_ai_assistant-0.1.8.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
|
|
37
|
+
jarvis_ai_assistant-0.1.8.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
|
38
|
+
jarvis_ai_assistant-0.1.8.dist-info/RECORD,,
|
|
File without changes
|
{jarvis_ai_assistant-0.1.7.dist-info → jarvis_ai_assistant-0.1.8.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|