beswarm 0.1.43__py3-none-any.whl → 0.1.45__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.
beswarm/aient/setup.py CHANGED
@@ -4,7 +4,7 @@ from setuptools import setup, find_packages
4
4
 
5
5
  setup(
6
6
  name="aient",
7
- version="1.0.98",
7
+ version="1.1.0",
8
8
  description="Aient: The Awakening of Agent.",
9
9
  long_description=Path.open(Path("README.md"), encoding="utf-8").read(),
10
10
  long_description_content_type="text/markdown",
@@ -322,6 +322,9 @@ async def get_vertex_gemini_payload(request, engine, provider, api_key=None):
322
322
  MODEL_ID=original_model,
323
323
  stream=gemini_stream
324
324
  )
325
+ elif api_key is not None and api_key[2] == ".":
326
+ url = f"https://aiplatform.googleapis.com/v1/publishers/google/models/{original_model}:{gemini_stream}?key={api_key}"
327
+ headers.pop("Authorization", None)
325
328
  else:
326
329
  url = "https://{LOCATION}-aiplatform.googleapis.com/v1/projects/{PROJECT_ID}/locations/{LOCATION}/publishers/google/models/{MODEL_ID}:{stream}".format(
327
330
  LOCATION=await location.next(),
@@ -1675,4 +1678,4 @@ async def prepare_request_payload(provider, request_data):
1675
1678
 
1676
1679
  url, headers, payload = await get_payload(request, engine, provider, api_key=provider['api'])
1677
1680
 
1678
- return url, headers, payload, engine
1681
+ return url, headers, payload, engine
@@ -439,8 +439,6 @@ class chatgpt(BaseLLM):
439
439
  if function_parameter:
440
440
  invalid_tools = [tool_dict for tool_dict in function_parameter if tool_dict.get("function_name", "") not in self.plugins.keys()]
441
441
  function_parameter = [tool_dict for tool_dict in function_parameter if tool_dict.get("function_name", "") in self.plugins.keys()]
442
- for tool_dict in invalid_tools:
443
- full_response = full_response + f"\n\nFunction: {tool_dict.get('function_name', '')} does not exist! I must use existing functions. I need to try again."
444
442
  if self.print_log and invalid_tools:
445
443
  print("invalid_tools", invalid_tools)
446
444
  print("function_parameter", function_parameter)
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import json
3
+ import chardet
3
4
  from pdfminer.high_level import extract_text
4
5
 
5
6
  from .registry import register_tool
@@ -99,9 +100,66 @@ Examples:
99
100
  except Exception as e:
100
101
  return f"<read_file error>处理IPython Notebook文件 '{file_path}' 时发生错误: {e}</read_file error>"
101
102
  else:
102
- # 读取文件内容
103
- with open(file_path, 'r', encoding='utf-8') as file:
104
- text_content = file.read()
103
+ # 更新:修改通用文件读取逻辑以支持多种编码
104
+ # 这部分替换了原有的 else 块内容
105
+ try:
106
+ with open(file_path, 'rb') as file: # 以二进制模式读取
107
+ raw_data = file.read()
108
+
109
+ if not raw_data: # 处理空文件
110
+ text_content = ""
111
+ else:
112
+ detected_info = chardet.detect(raw_data)
113
+ primary_encoding_to_try = detected_info['encoding']
114
+ confidence = detected_info['confidence']
115
+
116
+ decoded_successfully = False
117
+
118
+ # 尝试1: 使用检测到的编码 (如果置信度高且编码有效)
119
+ if primary_encoding_to_try and confidence > 0.7: # 您可以根据需要调整置信度阈值
120
+ try:
121
+ text_content = raw_data.decode(primary_encoding_to_try)
122
+ decoded_successfully = True
123
+ except (UnicodeDecodeError, LookupError): # LookupError 用于处理无效的编码名称
124
+ # 解码失败,将尝试后备编码
125
+ pass
126
+
127
+ # 尝试2: UTF-8 (如果第一次尝试失败或未进行)
128
+ if not decoded_successfully:
129
+ try:
130
+ text_content = raw_data.decode('utf-8')
131
+ decoded_successfully = True
132
+ except UnicodeDecodeError:
133
+ # 解码失败,将尝试下一个后备编码
134
+ pass
135
+
136
+ # 尝试3: UTF-16 (如果之前的尝试都失败)
137
+ # 'utf-16' 会处理带BOM的LE/BE编码。若无BOM,则假定为本机字节序。
138
+ # chardet 通常能更准确地检测具体的 utf-16le 或 utf-16be。
139
+ if not decoded_successfully:
140
+ try:
141
+ text_content = raw_data.decode('utf-16')
142
+ decoded_successfully = True
143
+ except UnicodeDecodeError:
144
+ # 所有主要尝试都失败
145
+ pass
146
+
147
+ if not decoded_successfully:
148
+ # 所有尝试均失败后的错误信息
149
+ detected_str_part = ""
150
+ if primary_encoding_to_try and confidence > 0.7: # 如果有高置信度的检测结果
151
+ detected_str_part = f"检测到的编码 '{primary_encoding_to_try}' (置信度 {confidence:.2f}), "
152
+ elif primary_encoding_to_try: # 如果有检测结果但置信度低
153
+ detected_str_part = f"低置信度检测编码 '{primary_encoding_to_try}' (置信度 {confidence:.2f}), "
154
+
155
+ return f"<read_file error>文件 '{file_path}' 无法解码。已尝试: {detected_str_part}UTF-8, UTF-16。</read_file error>"
156
+
157
+ except FileNotFoundError:
158
+ # 此处不太可能触发 FileNotFoundError,因为函数开头已有 os.path.exists 检查
159
+ return f"<read_file error>文件 '{file_path}' 在读取过程中未找到。</read_file error>"
160
+ except Exception as e:
161
+ # 捕获在此块中可能发生的其他错误,例如未被早期检查捕获的文件读取问题
162
+ return f"<read_file error>处理通用文件 '{file_path}' 时发生错误: {e}</read_file error>"
105
163
 
106
164
  # 返回文件内容
107
165
  return text_content
@@ -109,7 +167,8 @@ Examples:
109
167
  except PermissionError:
110
168
  return f"<read_file error>没有权限访问文件 '{file_path}'</read_file error>"
111
169
  except UnicodeDecodeError:
112
- return f"<read_file error>文件 '{file_path}' 不是文本文件或编码不是UTF-8</read_file error>"
170
+ # 更新:修改全局 UnicodeDecodeError 错误信息使其更通用
171
+ return f"<read_file error>文件 '{file_path}' 包含无法解码的字符 (UnicodeDecodeError)。</read_file error>"
113
172
  except Exception as e:
114
173
  return f"<read_file error>读取文件时发生错误: {e}</read_file error>"
115
174
 
@@ -413,13 +413,15 @@ class XmlMatcher(Generic[R]):
413
413
  self._update(chunk)
414
414
  return self._pop()
415
415
 
416
- def parse_function_xml(xml_content: str) -> List[Dict[str, Any]]:
416
+ def parse_function_xml(xml_content: str, check_line_start: bool = True) -> List[Dict[str, Any]]:
417
417
  """
418
418
  解析XML格式的函数调用信息,转换为字典数组格式
419
419
  只解析倒数两层XML标签,忽略更高层级的XML标签
420
+ 当 check_line_start 为 True 时,只解析行首的XML标签。
420
421
 
421
422
  参数:
422
423
  xml_content: 包含一个或多个函数调用的XML字符串
424
+ check_line_start: 布尔值,指示是否只解析行首的XML标签
423
425
 
424
426
  返回:
425
427
  包含所有函数调用信息的字典数组,每个字典包含函数名和参数
@@ -434,6 +436,14 @@ def parse_function_xml(xml_content: str) -> List[Dict[str, Any]]:
434
436
  if tag_start == -1:
435
437
  break # 没有找到更多的标签
436
438
 
439
+ # 新增:如果 check_line_start 为 True,检查标签是否在行首
440
+ # 如果 '<' 不在行首 (即 tag_start > 0 且其前一个字符不是换行符),
441
+ # 则将其视为普通文本的一部分,移动 position 并继续搜索
442
+ if check_line_start:
443
+ if tag_start > 0 and xml_content[tag_start - 1] != '\n':
444
+ position = tag_start + 1 # 从 '<' 之后继续搜索
445
+ continue
446
+
437
447
  # 检查是否是XML标签的开始(不是闭合标签)
438
448
  if tag_start + 1 < len(xml_content) and xml_content[tag_start + 1] == '/':
439
449
  # 这是一个结束标签,跳过
@@ -476,8 +486,8 @@ def parse_function_xml(xml_content: str) -> List[Dict[str, Any]]:
476
486
 
477
487
  # 如果是普通辅助标签(如tool_call),则在其内部寻找函数调用
478
488
  if tag_name in ["tool_call", "function_call", "tool", "function"]:
479
- # 递归处理内部内容
480
- nested_functions = parse_function_xml(tag_inner_content)
489
+ # 递归处理内部内容,此时不再检查行首条件
490
+ nested_functions = parse_function_xml(tag_inner_content, check_line_start=False)
481
491
  result_functions.extend(nested_functions)
482
492
  else:
483
493
  # 将当前标签作为函数名,解析其内部标签作为参数
@@ -646,7 +656,7 @@ def convert_functions_to_xml(functions_list):
646
656
 
647
657
  if __name__ == "__main__":
648
658
 
649
- # 运行本文件:python -m aient.utils.scripts
659
+ # 运行本文件:python -m beswarm.aient.src.aient.utils.scripts
650
660
  os.system("clear")
651
661
  test_xml = """
652
662
  ✅ 好的,我现在读取 `README.md` 文件。
@@ -656,6 +666,7 @@ if __name__ == "__main__":
656
666
  </read_file>
657
667
  </tool_call>好的,我现在读取 `README.md` 文件。
658
668
  """
669
+ test_xml = """首先使用read_file工具读取论文内容,然后使用excute_command工具克隆代码仓库到本地。\n```xml\n<read_file>\n<file_path>/Users/yanyuming/Downloads/GitHub/OceanSynthesis/papers/2412.06410v1.pdf</file_path>\n</read_file>\n\n<excute_command>\n<command>git clone https://github.com/bartbussmann/BatchTopK.git</command>\n</excute_command>\n```"""
659
670
  test_xml = """
660
671
  ✅ 好的,我现在读取 `README.md` 文件。
661
672
  <read_file>
@@ -670,8 +681,7 @@ if __name__ == "__main__":
670
681
  <file_path>README.md</file_path>
671
682
  </read_file>
672
683
  </tool_call>
673
- 好的,我现在读取 `README.md` 文件。
684
+ 好的,我现在读取 `README.md` 文件。`<answer> </answer>`
674
685
  """
675
686
 
676
- test_xml = """首先使用read_file工具读取论文内容,然后使用excute_command工具克隆代码仓库到本地。\n```xml\n<read_file>\n<file_path>/Users/yanyuming/Downloads/GitHub/OceanSynthesis/papers/2412.06410v1.pdf</file_path>\n</read_file>\n\n<excute_command>\n<command>git clone https://github.com/bartbussmann/BatchTopK.git</command>\n</excute_command>\n```"""
677
687
  print(parse_function_xml(test_xml))
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: beswarm
3
- Version: 0.1.43
3
+ Version: 0.1.45
4
4
  Summary: MAS
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
7
+ Requires-Dist: chardet>=5.2.0
7
8
  Requires-Dist: diskcache>=5.6.3
8
9
  Requires-Dist: fake-useragent>=2.2.0
9
10
  Requires-Dist: fastapi>=0.115.12
@@ -12,6 +13,7 @@ Requires-Dist: httpx>=0.28.1
12
13
  Requires-Dist: httpx-socks>=0.10.0
13
14
  Requires-Dist: msgspec>=0.19.0
14
15
  Requires-Dist: networkx>=3.4.2
16
+ Requires-Dist: numpy>=2.2.5
15
17
  Requires-Dist: pdfminer-six==20240706
16
18
  Requires-Dist: pillow>=11.2.1
17
19
  Requires-Dist: pyautogui>=0.9.54
@@ -19,6 +21,7 @@ Requires-Dist: pygments>=2.19.1
19
21
  Requires-Dist: pyperclip>=1.9.0
20
22
  Requires-Dist: pytz>=2025.2
21
23
  Requires-Dist: requests>=2.32.3
24
+ Requires-Dist: scipy>=1.15.3
22
25
  Requires-Dist: tqdm>=4.67.1
23
26
  Provides-Extra: search
24
27
  Requires-Dist: beautifulsoup4>=4.13.4; extra == "search"
@@ -57,6 +60,7 @@ arXiv:2502.14831v2 和 arXiv:2503.10618v2 的 渐进式 VAE 训练方法有一
57
60
 
58
61
  ```
59
62
  docker buildx build --platform linux/amd64,linux/arm64 -t yym68686/beswarm:latest --push .
63
+ docker pull yym68686/beswarm
60
64
  ```
61
65
 
62
66
  ```
@@ -1,12 +1,12 @@
1
1
  beswarm/__init__.py,sha256=HZjUOJtZR5QhMuDbq-wukQQn1VrBusNWai_ysGo-VVI,20
2
2
  beswarm/utils.py,sha256=AdDCcqAIIKQEMl7PfryVgeT9G5sHe7QNsZnrvmTGA8E,283
3
3
  beswarm/aient/main.py,sha256=SiYAIgQlLJqYusnTVEJOx1WNkSJKMImhgn5aWjfroxg,3814
4
- beswarm/aient/setup.py,sha256=TKEL3DSEtW3DVTaQSlRa7IUEWUW9JBUBlRA47kggOzw,487
4
+ beswarm/aient/setup.py,sha256=APcZyef3JE7vQFb0qmEjya3Yrr2oHL-FEDbl6W9EkLI,486
5
5
  beswarm/aient/src/aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
6
6
  beswarm/aient/src/aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
7
7
  beswarm/aient/src/aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
8
8
  beswarm/aient/src/aient/core/models.py,sha256=_1wYZg_n9kb2A3C8xCboyqleH2iHc9scwOvtx9DPeok,7582
9
- beswarm/aient/src/aient/core/request.py,sha256=RChzDuH49gaJE-o5g65h3nCh-OsuHPwLkq8yuyYEcbo,61431
9
+ beswarm/aient/src/aient/core/request.py,sha256=eGoGL8muYGvPbamUjcnyI8qH28uZBSG4Sc6Eko5LeJw,61653
10
10
  beswarm/aient/src/aient/core/response.py,sha256=8bS1nAoP6QOMDeDvJvZDVAt34kZ1DpWBI3PUGyza0ZU,31447
11
11
  beswarm/aient/src/aient/core/utils.py,sha256=CAFqWzICaKVysH9GLHBcp-VeOShisLjWGhEsh6-beWo,26365
12
12
  beswarm/aient/src/aient/core/test/test_base_api.py,sha256=pWnycRJbuPSXKKU9AQjWrMAX1wiLC_014Qc9hh5C2Pw,524
@@ -16,7 +16,7 @@ beswarm/aient/src/aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6U
16
16
  beswarm/aient/src/aient/models/__init__.py,sha256=ouNDNvoBBpIFrLsk09Q_sq23HR0GbLAKfGLIFmfEuXE,219
17
17
  beswarm/aient/src/aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
18
18
  beswarm/aient/src/aient/models/base.py,sha256=z-Z0pJfTN2x0cuwfvu0BdMRY9O-RmLwHEnBIJN1x4Fg,6719
19
- beswarm/aient/src/aient/models/chatgpt.py,sha256=q8dx4PD57m4a3gJHrzJr7v_Pl8X0RKDBCZHZEtIMxkk,45480
19
+ beswarm/aient/src/aient/models/chatgpt.py,sha256=vjmMELVO96NWsptrwoqcvyDS_YQfvE_piA-4G_hQR0I,45258
20
20
  beswarm/aient/src/aient/models/claude.py,sha256=JezghW7y0brl4Y5qiSHvnYR5prQCFywX4RViHt39pGI,26037
21
21
  beswarm/aient/src/aient/models/duckduckgo.py,sha256=1l7vYCs9SG5SWPCbcl7q6pCcB5AUF_r-a4l9frz3Ogo,8115
22
22
  beswarm/aient/src/aient/models/gemini.py,sha256=chGLc-8G_DAOxr10HPoOhvVFW1RvMgHd6mt--VyAW98,14730
@@ -29,7 +29,7 @@ beswarm/aient/src/aient/plugins/excute_command.py,sha256=u-JOZ21dDcDx1j3O0KVIHAs
29
29
  beswarm/aient/src/aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
30
30
  beswarm/aient/src/aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
31
31
  beswarm/aient/src/aient/plugins/list_directory.py,sha256=5ubm-mfrj-tanGSDp4M_Tmb6vQb3dx2-XVfQ2yL2G8A,1394
32
- beswarm/aient/src/aient/plugins/read_file.py,sha256=cJxGnhcz1_gjkgeemVyixLUiCvf-dWm-UtDfrbFdlLE,4857
32
+ beswarm/aient/src/aient/plugins/read_file.py,sha256=-RRmaj-rSl8y--5VKnxCsZ1YQHe75OhnqvsDRLJyujM,8412
33
33
  beswarm/aient/src/aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
34
34
  beswarm/aient/src/aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
35
35
  beswarm/aient/src/aient/plugins/websearch.py,sha256=I4tYU7CGLdyG6Hd3yK19V-PoG5IbFI9FEEVggyrshRg,15227
@@ -38,7 +38,7 @@ beswarm/aient/src/aient/prompt/__init__.py,sha256=GBtn6-JDT8KHFCcuPpfSNE_aGddg5p
38
38
  beswarm/aient/src/aient/prompt/agent.py,sha256=6f5ZB66Rb8y0iQScHMRhvXZ1qMM3YsKpCBPCTAAw2rg,24917
39
39
  beswarm/aient/src/aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
40
  beswarm/aient/src/aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
41
- beswarm/aient/src/aient/utils/scripts.py,sha256=JbYHsU3LLtxBcuO_2MWbSgpHpCgtVQe9FGEFJpUyejc,25926
41
+ beswarm/aient/src/aient/utils/scripts.py,sha256=NXmTxcZqHoRv3S13isLsv7kvqktXnA5ej7uMsxCJUe0,26656
42
42
  beswarm/aient/test/chatgpt.py,sha256=Hvl7FuDt1c74N5TVBmhErOPvJbJJzA7FNp5VoZM4u30,4957
43
43
  beswarm/aient/test/claude.py,sha256=IyB4qI1eJLwlSfDNSnt2FhbQWYyBighHUjJxEXc3osQ,1095
44
44
  beswarm/aient/test/test.py,sha256=rldnoLQdtRR8IKFSIzTti7eIK2MpPMoi9gL5qD8_K44,29
@@ -127,7 +127,7 @@ beswarm/tools/repomap.py,sha256=CwvwoN5Swr42EzrORTTeV8MMb7mPviy4a4b0fxBu50k,4082
127
127
  beswarm/tools/search_arxiv.py,sha256=9slwBemXjEqrd7-YgVmyMijPXlkhZCybEDRVhWVQ9B0,7937
128
128
  beswarm/tools/think.py,sha256=WLw-7jNIsnS6n8MMSYUin_f-BGLENFmnKM2LISEp0co,1760
129
129
  beswarm/tools/worker.py,sha256=FfKCx7KFNbMRoAXtjU1_nJQjx9WHny7KBq8OXSYICJs,5334
130
- beswarm-0.1.43.dist-info/METADATA,sha256=CsOvxleUywW3WrTQKyrZnqAYmZ-fTOGRytqMQ-vPPwA,3421
131
- beswarm-0.1.43.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
132
- beswarm-0.1.43.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
133
- beswarm-0.1.43.dist-info/RECORD,,
130
+ beswarm-0.1.45.dist-info/METADATA,sha256=rZ2mp_VwHkzsFSi3d4IivWKhhgpF7CykC92ow1LDTh8,3537
131
+ beswarm-0.1.45.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
132
+ beswarm-0.1.45.dist-info/top_level.txt,sha256=pJw4O87wvt5882smuSO6DfByJz7FJ8SxxT8h9fHCmpo,8
133
+ beswarm-0.1.45.dist-info/RECORD,,