aient 1.1.10__py3-none-any.whl → 1.1.12__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 +1 -1
- aient/models/chatgpt.py +3 -3
- aient/plugins/read_file.py +11 -11
- aient/plugins/read_image.py +7 -7
- aient/utils/scripts.py +66 -8
- {aient-1.1.10.dist-info → aient-1.1.12.dist-info}/METADATA +1 -1
- {aient-1.1.10.dist-info → aient-1.1.12.dist-info}/RECORD +10 -10
- {aient-1.1.10.dist-info → aient-1.1.12.dist-info}/WHEEL +1 -1
- {aient-1.1.10.dist-info → aient-1.1.12.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.10.dist-info → aient-1.1.12.dist-info}/top_level.txt +0 -0
aient/core/request.py
CHANGED
@@ -306,7 +306,7 @@ async def get_vertex_gemini_payload(request, engine, provider, api_key=None):
|
|
306
306
|
search_tool = None
|
307
307
|
|
308
308
|
# https://cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/2-0-flash?hl=zh-cn
|
309
|
-
pro_models = ["gemini-2.5"]
|
309
|
+
pro_models = ["gemini-2.5", "gemini-2.0"]
|
310
310
|
if any(pro_model in original_model for pro_model in pro_models):
|
311
311
|
location = gemini2
|
312
312
|
search_tool = {"googleSearch": {}}
|
aient/models/chatgpt.py
CHANGED
@@ -558,12 +558,12 @@ class chatgpt(BaseLLM):
|
|
558
558
|
tool_response = chunk.replace("function_response:", "")
|
559
559
|
else:
|
560
560
|
yield chunk
|
561
|
-
if tool_name == "read_file" and "<
|
561
|
+
if tool_name == "read_file" and "<tool_error>" not in tool_response:
|
562
562
|
self.latest_file_content[tool_info['parameter']["file_path"]] = tool_response
|
563
563
|
all_responses.append(f"[{tool_name}({tool_args}) Result]:\n\nRead file successfully! The file content has been updated in the tag <latest_file_content>.")
|
564
|
-
elif tool_name == "write_to_file":
|
564
|
+
elif tool_name == "write_to_file" and "<tool_error>" not in tool_response:
|
565
565
|
all_responses.append(f"[{tool_name} Result]:\n\n{tool_response}")
|
566
|
-
elif tool_name == "read_image":
|
566
|
+
elif tool_name == "read_image" and "<tool_error>" not in tool_response:
|
567
567
|
tool_info["base64_image"] = tool_response
|
568
568
|
all_responses.append(f"[{tool_name}({tool_args}) Result]:\n\nRead image successfully!")
|
569
569
|
else:
|
aient/plugins/read_file.py
CHANGED
@@ -51,11 +51,11 @@ Examples:
|
|
51
51
|
try:
|
52
52
|
# 检查文件是否存在
|
53
53
|
if not os.path.exists(file_path):
|
54
|
-
return f"<
|
54
|
+
return f"<tool_error>文件 '{file_path}' 不存在</tool_error>"
|
55
55
|
|
56
56
|
# 检查是否为文件
|
57
57
|
if not os.path.isfile(file_path):
|
58
|
-
return f"<
|
58
|
+
return f"<tool_error>'{file_path}' 不是一个文件</tool_error>"
|
59
59
|
|
60
60
|
# 检查文件扩展名
|
61
61
|
if file_path.lower().endswith('.pdf'):
|
@@ -64,7 +64,7 @@ Examples:
|
|
64
64
|
|
65
65
|
# 如果提取结果为空
|
66
66
|
if not text_content:
|
67
|
-
return f"<
|
67
|
+
return f"<tool_error>无法从 '{file_path}' 提取文本内容</tool_error>"
|
68
68
|
elif file_path.lower().endswith('.ipynb'):
|
69
69
|
try:
|
70
70
|
with open(file_path, 'r', encoding='utf-8') as file:
|
@@ -96,9 +96,9 @@ Examples:
|
|
96
96
|
|
97
97
|
text_content = json.dumps(notebook_content, indent=2, ensure_ascii=False)
|
98
98
|
except json.JSONDecodeError:
|
99
|
-
return f"<
|
99
|
+
return f"<tool_error>文件 '{file_path}' 不是有效的JSON格式 (IPython Notebook)。</tool_error>"
|
100
100
|
except Exception as e:
|
101
|
-
return f"<
|
101
|
+
return f"<tool_error>处理IPython Notebook文件 '{file_path}' 时发生错误: {e}</tool_error>"
|
102
102
|
else:
|
103
103
|
# 更新:修改通用文件读取逻辑以支持多种编码
|
104
104
|
# 这部分替换了原有的 else 块内容
|
@@ -152,25 +152,25 @@ Examples:
|
|
152
152
|
elif primary_encoding_to_try: # 如果有检测结果但置信度低
|
153
153
|
detected_str_part = f"低置信度检测编码 '{primary_encoding_to_try}' (置信度 {confidence:.2f}), "
|
154
154
|
|
155
|
-
return f"<
|
155
|
+
return f"<tool_error>文件 '{file_path}' 无法解码。已尝试: {detected_str_part}UTF-8, UTF-16。</tool_error>"
|
156
156
|
|
157
157
|
except FileNotFoundError:
|
158
158
|
# 此处不太可能触发 FileNotFoundError,因为函数开头已有 os.path.exists 检查
|
159
|
-
return f"<
|
159
|
+
return f"<tool_error>文件 '{file_path}' 在读取过程中未找到。</tool_error>"
|
160
160
|
except Exception as e:
|
161
161
|
# 捕获在此块中可能发生的其他错误,例如未被早期检查捕获的文件读取问题
|
162
|
-
return f"<
|
162
|
+
return f"<tool_error>处理通用文件 '{file_path}' 时发生错误: {e}</tool_error>"
|
163
163
|
|
164
164
|
# 返回文件内容
|
165
165
|
return text_content
|
166
166
|
|
167
167
|
except PermissionError:
|
168
|
-
return f"<
|
168
|
+
return f"<tool_error>没有权限访问文件 '{file_path}'</tool_error>"
|
169
169
|
except UnicodeDecodeError:
|
170
170
|
# 更新:修改全局 UnicodeDecodeError 错误信息使其更通用
|
171
|
-
return f"<
|
171
|
+
return f"<tool_error>文件 '{file_path}' 包含无法解码的字符 (UnicodeDecodeError)。</tool_error>"
|
172
172
|
except Exception as e:
|
173
|
-
return f"<
|
173
|
+
return f"<tool_error>读取文件时发生错误: {e}</tool_error>"
|
174
174
|
|
175
175
|
if __name__ == "__main__":
|
176
176
|
# python -m beswarm.aient.src.aient.plugins.read_file
|
aient/plugins/read_image.py
CHANGED
@@ -19,17 +19,17 @@ def read_image(image_path: str):
|
|
19
19
|
try:
|
20
20
|
# 检查路径是否存在
|
21
21
|
if not os.path.exists(image_path):
|
22
|
-
return f"
|
22
|
+
return f"<tool_error>图片路径 '{image_path}' 不存在。</tool_error>"
|
23
23
|
# 检查是否为文件
|
24
24
|
if not os.path.isfile(image_path):
|
25
|
-
return f"
|
25
|
+
return f"<tool_error>路径 '{image_path}' 不是一个有效的文件 (可能是一个目录)。</tool_error>"
|
26
26
|
|
27
27
|
# 尝试猜测MIME类型
|
28
28
|
mime_type, _ = mimetypes.guess_type(image_path) # encoding 变量通常不需要
|
29
29
|
|
30
30
|
if not mime_type or not mime_type.startswith('image/'):
|
31
31
|
# 如果mimetypes无法识别,或者不是图片类型
|
32
|
-
return f"
|
32
|
+
return f"<tool_error>文件 '{image_path}' 的MIME类型无法识别为图片 (检测到: {mime_type})。请确保文件是常见的图片格式 (e.g., PNG, JPG, GIF, WEBP)。</tool_error>"
|
33
33
|
|
34
34
|
with open(image_path, "rb") as image_file:
|
35
35
|
image_data = image_file.read()
|
@@ -45,10 +45,10 @@ def read_image(image_path: str):
|
|
45
45
|
except FileNotFoundError:
|
46
46
|
# 这个异常通常由 open() 抛出,如果 os.path.exists 通过但文件在读取前被删除
|
47
47
|
# 或者路径检查逻辑未能完全覆盖所有情况 (理论上不应发生)
|
48
|
-
return f"
|
48
|
+
return f"<tool_error>图片路径 '{image_path}' 未找到 (可能在检查后被删除或移动)。</tool_error>"
|
49
49
|
except PermissionError:
|
50
|
-
return f"
|
50
|
+
return f"<tool_error>没有权限访问图片路径 '{image_path}'。</tool_error>"
|
51
51
|
except IOError as e: # 例如文件损坏无法读取,或磁盘问题
|
52
|
-
return f"
|
52
|
+
return f"<tool_error>读取图片 '{image_path}' 时发生 I/O 错误: {e}</tool_error>"
|
53
53
|
except Exception as e:
|
54
|
-
return f"
|
54
|
+
return f"<tool_error>读取图片 '{image_path}' 时发生未知错误: {e}</tool_error>"
|
aient/utils/scripts.py
CHANGED
@@ -440,7 +440,18 @@ def parse_function_xml(xml_content: str, check_line_start: bool = True) -> List[
|
|
440
440
|
# 如果 '<' 不在行首 (即 tag_start > 0 且其前一个字符不是换行符),
|
441
441
|
# 则将其视为普通文本的一部分,移动 position 并继续搜索
|
442
442
|
if check_line_start:
|
443
|
-
|
443
|
+
# 检查标签是否在行首,或者行首到标签之间只有空格
|
444
|
+
is_start_of_line_or_only_spaces_before = True
|
445
|
+
if tag_start > 0:
|
446
|
+
# 从 tag_start - 1 向前检查,直到行首或遇到非空格字符
|
447
|
+
check_pos = tag_start - 1
|
448
|
+
while check_pos >= 0 and xml_content[check_pos] != '\n':
|
449
|
+
if not xml_content[check_pos].isspace():
|
450
|
+
is_start_of_line_or_only_spaces_before = False
|
451
|
+
break
|
452
|
+
check_pos -= 1
|
453
|
+
|
454
|
+
if not is_start_of_line_or_only_spaces_before:
|
444
455
|
position = tag_start + 1 # 从 '<' 之后继续搜索
|
445
456
|
continue
|
446
457
|
|
@@ -666,15 +677,15 @@ if __name__ == "__main__":
|
|
666
677
|
</read_file>
|
667
678
|
</tool_call>好的,我现在读取 `README.md` 文件。
|
668
679
|
"""
|
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```"""
|
680
|
+
# 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```"""
|
670
681
|
test_xml = """
|
671
682
|
✅ 好的,我现在读取 `README.md` 文件。
|
672
|
-
<read_file>
|
673
|
-
<file_path>README.md</file_path>
|
674
|
-
</read_file>
|
675
|
-
<read_file>
|
676
|
-
<file_path>README.md</file_path>
|
677
|
-
</read_file>
|
683
|
+
<read_file>
|
684
|
+
<file_path>README.md</file_path>
|
685
|
+
</read_file>
|
686
|
+
<read_file>
|
687
|
+
<file_path>README.md</file_path>
|
688
|
+
</read_file>
|
678
689
|
|
679
690
|
<tool_call>
|
680
691
|
<read_file>
|
@@ -682,6 +693,53 @@ if __name__ == "__main__":
|
|
682
693
|
</read_file>
|
683
694
|
</tool_call>
|
684
695
|
好的,我现在读取 `README.md` 文件。`<answer> </answer>`
|
696
|
+
"""
|
697
|
+
test_xml = """
|
698
|
+
好的,我来报告上一组指令的执行结果:
|
699
|
+
|
700
|
+
1. **创建日志目录 `/root/ctm-server/ctm_tinyimagenet_logs_v5_drastic_reduction`**:
|
701
|
+
<excute_command>
|
702
|
+
<command>mkdir -p /root/ctm-server/ctm_tinyimagenet_logs_v5_drastic_reduction</command>
|
703
|
+
</excute_command>
|
704
|
+
*(我需要等待这个命令的实际执行结果才能确认。假设它会成功,因为 `mkdir -p` 通常不会失败。)*
|
705
|
+
|
706
|
+
2. **执行第五次实验的训练命令**:
|
707
|
+
<excute_command>
|
708
|
+
<command>python /root/ctm-server/continuous-thought-machines/tasks/image_classification/train.py \
|
709
|
+
--model ctm \
|
710
|
+
--dataset tinyimagenet \
|
711
|
+
--data_root /root/ctm-server/tiny-imagenet-200 \
|
712
|
+
--batch_size 1024 \
|
713
|
+
--training_iterations 10000 \
|
714
|
+
--device 0 \
|
715
|
+
--log_dir /root/ctm-server/ctm_tinyimagenet_logs_v5_drastic_reduction \
|
716
|
+
--save_every 1000 \
|
717
|
+
--track_every 200 \
|
718
|
+
--num_workers_train 2 \
|
719
|
+
--d_model 128 \
|
720
|
+
--iterations 10 \
|
721
|
+
--d_input 64 \
|
722
|
+
--heads 1 \
|
723
|
+
--synapse_depth 1 \
|
724
|
+
--n_synch_out 128 \
|
725
|
+
--n_synch_action 128 \
|
726
|
+
--memory_length 8 \
|
727
|
+
--backbone_type resnet18-1 \
|
728
|
+
--positional_embedding_type none \
|
729
|
+
--dropout 0.5 \
|
730
|
+
--weight_decay 1e-3 \
|
731
|
+
--use_amp</command>
|
732
|
+
</excute_command>
|
733
|
+
*(我需要等待这个训练命令的实际执行结果来确认训练是否完成。训练通常需要一些时间。)*
|
734
|
+
|
735
|
+
在上述两个 `excute_command` 的结果返回后,并且如果训练确认已完成,我将执行下一步:
|
736
|
+
|
737
|
+
3. **读取第五次实验的准确率图像**:
|
738
|
+
<read_image>
|
739
|
+
<image_path>/root/ctm-server/ctm_tinyimagenet_logs_v5_drastic_reduction/accuracies.png</image_path>
|
740
|
+
</read_image>
|
741
|
+
|
742
|
+
请提供前两个 `excute_command` 的执行结果。
|
685
743
|
"""
|
686
744
|
|
687
745
|
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=kF-HLi1I2k_G5r153ZHuiGH8_NmpTlFMfK0_myB28YQ,7366
|
7
|
-
aient/core/request.py,sha256=
|
7
|
+
aient/core/request.py,sha256=VItemXnWzqzS10W-RuLVrARki1w7MZMBZdyqyA5axw8,61943
|
8
8
|
aient/core/response.py,sha256=BNHLazjfQT8mVg7LnPLzlX429aQM3S03pumPbOpczCI,31518
|
9
9
|
aient/core/utils.py,sha256=n3dyaApN4rrSduI8cjZbeD0mv8_O5LPTTbwRkj1_v4w,26540
|
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=sfXqmYAiTTAa_dH2h49BZnVvjebEl99LJdQGepD2sCQ,46244
|
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,8 +27,8 @@ aient/plugins/excute_command.py,sha256=A3WmfZboEikU1EHvtMWhBv-xHxCyMxbDddQ982I_8
|
|
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=JZVuImecMSfEv6jLqii-0uQJ1UCsrpMNmYlwW3PEDg4,1374
|
30
|
-
aient/plugins/read_file.py,sha256
|
31
|
-
aient/plugins/read_image.py,sha256=
|
30
|
+
aient/plugins/read_file.py,sha256=Lv03AW-gWGzM2esos2vLTXHcceczdTqEO7_vqFT4yoY,8302
|
31
|
+
aient/plugins/read_image.py,sha256=jFu8MGCPWg19YOG-STWH3pqacf94F17i_4JaJu1XWLs,2704
|
32
32
|
aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
|
33
33
|
aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
|
34
34
|
aient/plugins/websearch.py,sha256=llxy1U0vJiNMiKvamMr4p7IruLb3nnDR4YErz8TYimc,15215
|
@@ -37,9 +37,9 @@ aient/prompt/__init__.py,sha256=GBtn6-JDT8KHFCcuPpfSNE_aGddg5p4FEyMCy4BfwGs,20
|
|
37
37
|
aient/prompt/agent.py,sha256=y2GETN6ScC5yQVs75VFfzm4YUWzblbqLYz0Sy6JnPRw,24950
|
38
38
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
39
39
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
40
|
-
aient/utils/scripts.py,sha256=
|
41
|
-
aient-1.1.
|
42
|
-
aient-1.1.
|
43
|
-
aient-1.1.
|
44
|
-
aient-1.1.
|
45
|
-
aient-1.1.
|
40
|
+
aient/utils/scripts.py,sha256=wutPtgbs-WXo5AACLpnCJaRQBOSKXWNnsf2grbYDzyQ,29098
|
41
|
+
aient-1.1.12.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
42
|
+
aient-1.1.12.dist-info/METADATA,sha256=Qw9hW21BsAFZHELCET7zEMTFUvvCaJv0r2WBgJmZM-I,4968
|
43
|
+
aient-1.1.12.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
44
|
+
aient-1.1.12.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
45
|
+
aient-1.1.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|