jarvis-ai-assistant 0.1.7__py3-none-any.whl → 0.1.9__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 CHANGED
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.7"
3
+ __version__ = "0.1.9"
Binary file
@@ -0,0 +1,38 @@
1
+ from playwright.sync_api import sync_playwright
2
+ from urllib.parse import quote
3
+
4
+ def bing_search(query):
5
+ try:
6
+ with sync_playwright() as p:
7
+ browser = p.chromium.launch()
8
+ page = browser.new_page()
9
+ page.goto(
10
+ f"https://www.bing.com/search?form=QBRE&q={quote(query)}&cc=US"
11
+ )
12
+
13
+ page.wait_for_selector("#b_results", timeout=10000)
14
+
15
+ summaries = page.evaluate("""() => {
16
+ const liElements = Array.from(
17
+ document.querySelectorAll("#b_results > .b_algo")
18
+ );
19
+ return liElements.map((li) => {
20
+ const abstractElement = li.querySelector(".b_caption > p");
21
+ const linkElement = li.querySelector("a");
22
+ const href = linkElement.getAttribute("href");
23
+ const title = linkElement.textContent;
24
+ const abstract = abstractElement ? abstractElement.textContent : "";
25
+ return { href, title, abstract };
26
+ });
27
+ }""")
28
+
29
+ browser.close()
30
+ print(summaries)
31
+ return summaries
32
+ except Exception as error:
33
+ print("An error occurred:", error)
34
+
35
+ if __name__ == "__main__":
36
+ # results = bing_search("北京到西雅图的距离")
37
+ results = bing_search("北京到西雅图的距离")
38
+ print(results)
jarvis/tools/search.py CHANGED
@@ -1,11 +1,12 @@
1
+ import os
1
2
  from typing import Dict, Any, List
2
- from duckduckgo_search import DDGS
3
3
  from ..utils import PrettyOutput, OutputType
4
4
  from .webpage import WebpageTool
5
+ from .bing_search import bing_search
5
6
 
6
7
  class SearchTool:
7
8
  name = "search"
8
- description = "使用DuckDuckGo搜索引擎搜索信息,并根据问题提取关键信息"
9
+ description = "使用Bing搜索引擎搜索信息,并根据问题提取关键信息"
9
10
  parameters = {
10
11
  "type": "object",
11
12
  "properties": {
@@ -31,6 +32,26 @@ class SearchTool:
31
32
  self.model = model
32
33
  self.webpage_tool = WebpageTool()
33
34
 
35
+ def _search(self, query: str, max_results: int) -> List[Dict]:
36
+ """执行搜索请求"""
37
+ try:
38
+ results = bing_search(query)
39
+ if not results:
40
+ return []
41
+
42
+ # 格式化搜索结果
43
+ formatted_results = []
44
+ for result in results[:max_results]:
45
+ formatted_results.append({
46
+ "title": result.get("title", ""),
47
+ "href": result.get("href", ""),
48
+ "body": result.get("abstract", "")
49
+ })
50
+ return formatted_results
51
+ except Exception as e:
52
+ PrettyOutput.print(f"搜索请求失败: {str(e)}", OutputType.ERROR)
53
+ return []
54
+
34
55
  def _extract_info(self, contents: List[str], question: str) -> str:
35
56
  """使用语言模型从网页内容中提取关键信息"""
36
57
  prompt = {
@@ -68,18 +89,18 @@ class SearchTool:
68
89
  PrettyOutput.print(f"相关问题: {question}", OutputType.INFO)
69
90
 
70
91
  # 获取搜索结果
71
- search_results = []
72
- with DDGS() as ddgs:
73
- results = list(ddgs.text(
74
- keywords=query,
75
- max_results=max_results
76
- ))
92
+ results = self._search(query, max_results)
93
+ if not results:
94
+ return {
95
+ "success": False,
96
+ "error": "未能获取任何搜索结果"
97
+ }
77
98
 
78
99
  # 收集网页内容
79
100
  contents = []
80
101
  for i, result in enumerate(results, 1):
81
102
  try:
82
- PrettyOutput.print(f"正在读取第 {i}/{len(results)} 个结果... {result['title']} - {result['href']} - {result['body']}", OutputType.PROGRESS)
103
+ PrettyOutput.print(f"正在读取第 {i}/{len(results)} 个结果... {result['title']} - {result['href']}", OutputType.PROGRESS)
83
104
  webpage_result = self.webpage_tool.execute({"url": result["href"]})
84
105
  if webpage_result["success"]:
85
106
  contents.append(f"\n来源 {i}:{result['href']}\n")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
5
  Home-page: https://github.com/skyfireitdiy/Jarvis
6
6
  Author: skyfire
@@ -23,6 +23,7 @@ Requires-Dist: pyyaml>=5.1
23
23
  Requires-Dist: ollama>=0.1.6
24
24
  Requires-Dist: colorama>=0.4.6
25
25
  Requires-Dist: openai>=1.2.0
26
+ Requires-Dist: playwright>=1.41.1
26
27
  Provides-Extra: dev
27
28
  Requires-Dist: pytest; extra == "dev"
28
29
  Requires-Dist: black; extra == "dev"
@@ -1,10 +1,10 @@
1
- jarvis/__init__.py,sha256=fleVIl0YBOVXirR9uC8oSuNk3RTpt-l5ZVRcbWcxLBM,49
1
+ jarvis/__init__.py,sha256=-pqI_MJPVrCN3BBcW2YIg8KbW5B7vfbpb-ESMyNKpVg,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=jMAaM43iGZiD_4ucOm9YelgcuhOjzcVv3vPtym1ePIU,208
7
+ jarvis/__pycache__/__init__.cpython-313.pyc,sha256=GF-b9JNTGgyKROLNqZojLYFIrgPShHKlZADEFHP_YfE,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
@@ -13,25 +13,27 @@ jarvis/__pycache__/utils.cpython-313.pyc,sha256=k4jyAlx4tlW0MKLMLzV7OOH9zsKrK0H9
13
13
  jarvis/__pycache__/zte_llm.cpython-313.pyc,sha256=R_HT_Gc6OQelxRLRQ-yB8Tf0sYHcb18dh9E4RF6ivbE,5662
14
14
  jarvis/tools/__init__.py,sha256=tH6YaApKpqs1YSjEllRzOZZUd-OTFKSZ5oA0zs7HdSE,297
15
15
  jarvis/tools/base.py,sha256=zK-JteBwj9d2BD_7BSAp-zD7wgJbVBppAWyfFxaPObI,4114
16
+ jarvis/tools/bing_search.py,sha256=SvYeXM83eP9qREDcWguh0_r0m0npbcwXIyzEwwfreKU,1444
16
17
  jarvis/tools/file_ops.py,sha256=zTksx45NZm3iz9itN5iQGZ8DoxnSeTHdrnF08_ix7PU,3770
17
- jarvis/tools/search.py,sha256=XTFMGVKLkRLQhu668Gqn69jPdTEP0mEibbMR9lpbFyE,4092
18
+ jarvis/tools/search.py,sha256=P4vEbwcXTP6gpc4nwLEuERX0vVszGaer9xvaLfFI0Uc,4836
18
19
  jarvis/tools/shell.py,sha256=7q52lA3slf0TdjBjP1bkwugoO5pB0eqh6cYjAzAXNtI,2547
19
20
  jarvis/tools/sub_agent.py,sha256=QJYWdil1goZfo95CQkuhkjZBl-Rx6UvyeFMiGnDyjOA,2832
20
21
  jarvis/tools/webpage.py,sha256=DBnh9gye6oL2nVjzU2SU4Jupsck8x9g9On-rbjV6d8Y,2386
21
- jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=2NrOP5yRdPF8hk3i8lT7pxn7IkHGfolP3m0g9BjJYMs,443
22
- jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=A5jYC0Yfptk31eLbRrauPi49ymP0v-Hq9Swbaqq1IwA,6462
22
+ jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=1d1eUI0FlaydGB8TFBln6s7cBKd6gcPdER2_DIfX2Aw,443
23
+ jarvis/tools/__pycache__/base.cpython-313.pyc,sha256=2OJWYNsGJjKJs6Vdj9NcN_Snjd2bA_OLlB-zr2j4wfs,6462
24
+ jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLIS2Aw0XOG2ZM8ztgfQaqu3P8,2031
23
25
  jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=LbOp31JUzoRp5XVazy1VBqCQhpFg0qQYmVftFVY90V4,3628
24
26
  jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
25
27
  jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
26
- jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=WGNyExgaC3N_QixCzpcRBCKU2c52rkavaKtGWC3x_28,5254
28
+ jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
27
29
  jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=QMaLUc1MtZXWod3msv_x7iMq2IybwMwz1OoaKsbm6U4,3271
28
30
  jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=qzNLnQxqFZoAiYOPH4GrCGxaQVs-QWfTLspW5a1Xa6c,3144
29
31
  jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
30
32
  jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
31
33
  jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
32
34
  jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
33
- jarvis_ai_assistant-0.1.7.dist-info/METADATA,sha256=6nDJNmJ6WSnu12NTX58R4X4EHvQeE3wtoOpg4BkypbU,3719
34
- jarvis_ai_assistant-0.1.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
35
- jarvis_ai_assistant-0.1.7.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
36
- jarvis_ai_assistant-0.1.7.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
37
- jarvis_ai_assistant-0.1.7.dist-info/RECORD,,
35
+ jarvis_ai_assistant-0.1.9.dist-info/METADATA,sha256=d5LRsaxuZB6V0m8klCq07sxghlARFo7K8VM36TyCnvk,3753
36
+ jarvis_ai_assistant-0.1.9.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
37
+ jarvis_ai_assistant-0.1.9.dist-info/entry_points.txt,sha256=iKu7OMfew9dtfGhW71gIMTg4wvafuPqKb4wyQOnMAGU,44
38
+ jarvis_ai_assistant-0.1.9.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
39
+ jarvis_ai_assistant-0.1.9.dist-info/RECORD,,