jarvis-ai-assistant 0.1.8__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.8"
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,12 +1,12 @@
1
1
  import os
2
- import requests
3
2
  from typing import Dict, Any, List
4
3
  from ..utils import PrettyOutput, OutputType
5
4
  from .webpage import WebpageTool
5
+ from .bing_search import bing_search
6
6
 
7
7
  class SearchTool:
8
8
  name = "search"
9
- description = "使用搜索引擎搜索信息,并根据问题提取关键信息"
9
+ description = "使用Bing搜索引擎搜索信息,并根据问题提取关键信息"
10
10
  parameters = {
11
11
  "type": "object",
12
12
  "properties": {
@@ -31,35 +31,23 @@ class SearchTool:
31
31
  """初始化搜索工具,需要传入语言模型用于信息提取"""
32
32
  self.model = model
33
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
34
 
39
35
  def _search(self, query: str, max_results: int) -> List[Dict]:
40
36
  """执行搜索请求"""
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
37
  try:
49
- response = requests.get(url, params=params)
50
- response.raise_for_status()
51
- data = response.json()
38
+ results = bing_search(query)
39
+ if not results:
40
+ return []
52
41
 
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
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
63
51
  except Exception as e:
64
52
  PrettyOutput.print(f"搜索请求失败: {str(e)}", OutputType.ERROR)
65
53
  return []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.8
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=QIcBZBFMcOFbIudbA0VykyqY4RphA3fWQlRP_kUMcPM,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=lGXFfeYKcGsFZjgHY8y4zLca1xBIkr2zKSQv06rhoBY,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,26 +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=HJQ1_-CXB9M4wiq4wbLYdI-Vz92JiA6LGnog3b1dDd4,5293
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
22
  jarvis/tools/__pycache__/__init__.cpython-313.pyc,sha256=1d1eUI0FlaydGB8TFBln6s7cBKd6gcPdER2_DIfX2Aw,443
22
23
  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
24
+ jarvis/tools/__pycache__/bing_search.cpython-313.pyc,sha256=1G_wPbk5wcQYh7H0drLIS2Aw0XOG2ZM8ztgfQaqu3P8,2031
24
25
  jarvis/tools/__pycache__/file_ops.cpython-313.pyc,sha256=LbOp31JUzoRp5XVazy1VBqCQhpFg0qQYmVftFVY90V4,3628
25
26
  jarvis/tools/__pycache__/python_script.cpython-313.pyc,sha256=8JpryqTovEiTvBlWAK1KjZmPvHUuPc9GT9rTXBEQoJc,6693
26
27
  jarvis/tools/__pycache__/rag.cpython-313.pyc,sha256=JH6-PSZRMKAvTZqCwlRXJGClxYXNMs-vetU0q7hBLz0,6064
27
- jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=7lS5jDmClpHJXKnbBaUCys8CmW1YBJtZAa4c64JGO6I,6624
28
+ jarvis/tools/__pycache__/search.cpython-313.pyc,sha256=wLMIkFwT-h4NGHgssytT4xme7sGO6ZhEnex7kjcy0-k,5990
28
29
  jarvis/tools/__pycache__/shell.cpython-313.pyc,sha256=QMaLUc1MtZXWod3msv_x7iMq2IybwMwz1OoaKsbm6U4,3271
29
30
  jarvis/tools/__pycache__/sub_agent.cpython-313.pyc,sha256=qzNLnQxqFZoAiYOPH4GrCGxaQVs-QWfTLspW5a1Xa6c,3144
30
31
  jarvis/tools/__pycache__/user_confirmation.cpython-313.pyc,sha256=wK3Ev10lHSUSRvoYmi7A0GzxYkzU-C4Wfhs5qW_HBqs,2271
31
32
  jarvis/tools/__pycache__/user_input.cpython-313.pyc,sha256=JjTFOhObKsKF4Pn8KBRuKfV1_Ssj083fjU7Mfc_5z7c,2531
32
33
  jarvis/tools/__pycache__/user_interaction.cpython-313.pyc,sha256=RuVZ-pmiPBDywY3efgXSfohMAciC1avMGPmBK5qlnew,3305
33
34
  jarvis/tools/__pycache__/webpage.cpython-313.pyc,sha256=BjzSfnNzsKCrLETCcWjt32lNDLzwnjqcVGg4JfWd9OM,3008
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,,
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,,