aient 1.0.98__py3-none-any.whl → 1.1.0__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.
- aient/core/request.py +4 -1
- aient/models/chatgpt.py +0 -2
- aient/plugins/read_file.py +63 -4
- aient/utils/scripts.py +16 -6
- {aient-1.0.98.dist-info → aient-1.1.0.dist-info}/METADATA +1 -1
- {aient-1.0.98.dist-info → aient-1.1.0.dist-info}/RECORD +9 -9
- {aient-1.0.98.dist-info → aient-1.1.0.dist-info}/WHEEL +0 -0
- {aient-1.0.98.dist-info → aient-1.1.0.dist-info}/licenses/LICENSE +0 -0
- {aient-1.0.98.dist-info → aient-1.1.0.dist-info}/top_level.txt +0 -0
aient/core/request.py
CHANGED
@@ -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
|
aient/models/chatgpt.py
CHANGED
@@ -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)
|
aient/plugins/read_file.py
CHANGED
@@ -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
|
-
|
104
|
-
|
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
|
-
|
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
|
|
aient/utils/scripts.py
CHANGED
@@ -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))
|
@@ -4,7 +4,7 @@ aient/core/.gitignore,sha256=5JRRlYYsqt_yt6iFvvzhbqh2FTUQMqwo6WwIuFzlGR8,13
|
|
4
4
|
aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
|
5
5
|
aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
|
6
6
|
aient/core/models.py,sha256=_1wYZg_n9kb2A3C8xCboyqleH2iHc9scwOvtx9DPeok,7582
|
7
|
-
aient/core/request.py,sha256=
|
7
|
+
aient/core/request.py,sha256=eGoGL8muYGvPbamUjcnyI8qH28uZBSG4Sc6Eko5LeJw,61653
|
8
8
|
aient/core/response.py,sha256=8bS1nAoP6QOMDeDvJvZDVAt34kZ1DpWBI3PUGyza0ZU,31447
|
9
9
|
aient/core/utils.py,sha256=CAFqWzICaKVysH9GLHBcp-VeOShisLjWGhEsh6-beWo,26365
|
10
10
|
aient/core/test/test_base_api.py,sha256=pWnycRJbuPSXKKU9AQjWrMAX1wiLC_014Qc9hh5C2Pw,524
|
@@ -14,7 +14,7 @@ aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9XkdsuuKFGrwFhF
|
|
14
14
|
aient/models/__init__.py,sha256=ouNDNvoBBpIFrLsk09Q_sq23HR0GbLAKfGLIFmfEuXE,219
|
15
15
|
aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
|
16
16
|
aient/models/base.py,sha256=z-Z0pJfTN2x0cuwfvu0BdMRY9O-RmLwHEnBIJN1x4Fg,6719
|
17
|
-
aient/models/chatgpt.py,sha256=
|
17
|
+
aient/models/chatgpt.py,sha256=vjmMELVO96NWsptrwoqcvyDS_YQfvE_piA-4G_hQR0I,45258
|
18
18
|
aient/models/claude.py,sha256=JezghW7y0brl4Y5qiSHvnYR5prQCFywX4RViHt39pGI,26037
|
19
19
|
aient/models/duckduckgo.py,sha256=1l7vYCs9SG5SWPCbcl7q6pCcB5AUF_r-a4l9frz3Ogo,8115
|
20
20
|
aient/models/gemini.py,sha256=chGLc-8G_DAOxr10HPoOhvVFW1RvMgHd6mt--VyAW98,14730
|
@@ -27,7 +27,7 @@ aient/plugins/excute_command.py,sha256=u-JOZ21dDcDx1j3O0KVIHAsa6MNuOxHFBdV3iCnTi
|
|
27
27
|
aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
|
28
28
|
aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
|
29
29
|
aient/plugins/list_directory.py,sha256=5ubm-mfrj-tanGSDp4M_Tmb6vQb3dx2-XVfQ2yL2G8A,1394
|
30
|
-
aient/plugins/read_file.py,sha256
|
30
|
+
aient/plugins/read_file.py,sha256=-RRmaj-rSl8y--5VKnxCsZ1YQHe75OhnqvsDRLJyujM,8412
|
31
31
|
aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
|
32
32
|
aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
|
33
33
|
aient/plugins/websearch.py,sha256=I4tYU7CGLdyG6Hd3yK19V-PoG5IbFI9FEEVggyrshRg,15227
|
@@ -36,9 +36,9 @@ aient/prompt/__init__.py,sha256=GBtn6-JDT8KHFCcuPpfSNE_aGddg5p4FEyMCy4BfwGs,20
|
|
36
36
|
aient/prompt/agent.py,sha256=6f5ZB66Rb8y0iQScHMRhvXZ1qMM3YsKpCBPCTAAw2rg,24917
|
37
37
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
38
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
39
|
-
aient/utils/scripts.py,sha256=
|
40
|
-
aient-1.0.
|
41
|
-
aient-1.0.
|
42
|
-
aient-1.0.
|
43
|
-
aient-1.0.
|
44
|
-
aient-1.0.
|
39
|
+
aient/utils/scripts.py,sha256=NXmTxcZqHoRv3S13isLsv7kvqktXnA5ej7uMsxCJUe0,26656
|
40
|
+
aient-1.1.0.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
41
|
+
aient-1.1.0.dist-info/METADATA,sha256=T5DmF0T811yIKF3FF4_zrUqG_AdQbntaKagrQ-thfn4,4944
|
42
|
+
aient-1.1.0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
43
|
+
aient-1.1.0.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
44
|
+
aient-1.1.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|