aient 1.1.9__py3-none-any.whl → 1.1.10__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/models/chatgpt.py +21 -4
- aient/plugins/list_directory.py +5 -5
- aient/plugins/read_image.py +54 -0
- aient/prompt/agent.py +2 -0
- {aient-1.1.9.dist-info → aient-1.1.10.dist-info}/METADATA +1 -1
- {aient-1.1.9.dist-info → aient-1.1.10.dist-info}/RECORD +9 -8
- {aient-1.1.9.dist-info → aient-1.1.10.dist-info}/WHEEL +0 -0
- {aient-1.1.9.dist-info → aient-1.1.10.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.9.dist-info → aient-1.1.10.dist-info}/top_level.txt +0 -0
aient/models/chatgpt.py
CHANGED
@@ -152,8 +152,25 @@ class chatgpt(BaseLLM):
|
|
152
152
|
else:
|
153
153
|
last_user_message = self.conversation[convo_id][-1]["content"]
|
154
154
|
if last_user_message != message:
|
155
|
+
image_message_list = []
|
156
|
+
if isinstance(function_arguments, str):
|
157
|
+
functions_list = json.loads(function_arguments)
|
158
|
+
else:
|
159
|
+
functions_list = function_arguments
|
160
|
+
for tool_info in functions_list:
|
161
|
+
if tool_info.get("base64_image"):
|
162
|
+
image_message_list.append({"type": "text", "text": safe_get(tool_info, "parameter", "image_path", default="") + " image:"})
|
163
|
+
image_message_list.append({
|
164
|
+
"type": "image_url",
|
165
|
+
"image_url": {
|
166
|
+
"url": tool_info["base64_image"],
|
167
|
+
}
|
168
|
+
})
|
155
169
|
self.conversation[convo_id].append({"role": "assistant", "content": convert_functions_to_xml(function_arguments)})
|
156
|
-
|
170
|
+
if image_message_list:
|
171
|
+
self.conversation[convo_id].append({"role": "user", "content": [{"type": "text", "text": message}] + image_message_list})
|
172
|
+
else:
|
173
|
+
self.conversation[convo_id].append({"role": "user", "content": message})
|
157
174
|
else:
|
158
175
|
self.conversation[convo_id].append({"role": "assistant", "content": "我已经执行过这个工具了,接下来我需要做什么?"})
|
159
176
|
|
@@ -545,10 +562,10 @@ class chatgpt(BaseLLM):
|
|
545
562
|
self.latest_file_content[tool_info['parameter']["file_path"]] = tool_response
|
546
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>.")
|
547
564
|
elif tool_name == "write_to_file":
|
548
|
-
# change_tools_args = copy.deepcopy(tool_info['parameter'])
|
549
|
-
# change_tools_args["content"] = "...文件已写入,内容已省略以节省上下文..."
|
550
|
-
# tool_args = json.dumps(change_tools_args, ensure_ascii=False) if not isinstance(change_tools_args, str) else change_tools_args
|
551
565
|
all_responses.append(f"[{tool_name} Result]:\n\n{tool_response}")
|
566
|
+
elif tool_name == "read_image":
|
567
|
+
tool_info["base64_image"] = tool_response
|
568
|
+
all_responses.append(f"[{tool_name}({tool_args}) Result]:\n\nRead image successfully!")
|
552
569
|
else:
|
553
570
|
all_responses.append(f"[{tool_name}({tool_args}) Result]:\n\n{tool_response}")
|
554
571
|
|
aient/plugins/list_directory.py
CHANGED
@@ -5,13 +5,13 @@ from .registry import register_tool
|
|
5
5
|
@register_tool()
|
6
6
|
def list_directory(path="."):
|
7
7
|
"""
|
8
|
-
|
8
|
+
列出指定目录中的所有文件和子目录
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
参数:
|
11
|
+
path: 要列出内容的目录路径,默认为当前目录
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
返回:
|
14
|
+
目录内容的列表字符串
|
15
15
|
"""
|
16
16
|
try:
|
17
17
|
# 获取目录内容
|
@@ -0,0 +1,54 @@
|
|
1
|
+
import os
|
2
|
+
import base64
|
3
|
+
import mimetypes
|
4
|
+
from .registry import register_tool
|
5
|
+
|
6
|
+
@register_tool()
|
7
|
+
def read_image(image_path: str):
|
8
|
+
"""
|
9
|
+
读取本地图片文件,将其转换为 Base64 编码,并返回包含 MIME 类型和完整数据的字符串。
|
10
|
+
此工具用于将图片内容加载到上下文中。
|
11
|
+
|
12
|
+
参数:
|
13
|
+
image_path (str): 本地图片文件的路径。
|
14
|
+
|
15
|
+
返回:
|
16
|
+
str: 成功时返回包含图片MIME类型和Base64编码数据的格式化字符串。
|
17
|
+
失败时返回错误信息字符串。
|
18
|
+
"""
|
19
|
+
try:
|
20
|
+
# 检查路径是否存在
|
21
|
+
if not os.path.exists(image_path):
|
22
|
+
return f"错误: 图片路径 '{image_path}' 不存在。"
|
23
|
+
# 检查是否为文件
|
24
|
+
if not os.path.isfile(image_path):
|
25
|
+
return f"错误: 路径 '{image_path}' 不是一个有效的文件 (可能是一个目录)。"
|
26
|
+
|
27
|
+
# 尝试猜测MIME类型
|
28
|
+
mime_type, _ = mimetypes.guess_type(image_path) # encoding 变量通常不需要
|
29
|
+
|
30
|
+
if not mime_type or not mime_type.startswith('image/'):
|
31
|
+
# 如果mimetypes无法识别,或者不是图片类型
|
32
|
+
return f"错误: 文件 '{image_path}' 的MIME类型无法识别为图片 (检测到: {mime_type})。请确保文件是常见的图片格式 (e.g., PNG, JPG, GIF, WEBP)。"
|
33
|
+
|
34
|
+
with open(image_path, "rb") as image_file:
|
35
|
+
image_data = image_file.read()
|
36
|
+
|
37
|
+
base64_encoded_data = base64.b64encode(image_data).decode('utf-8')
|
38
|
+
|
39
|
+
# 返回一个描述性字符串,模仿 list_directory.py 的风格
|
40
|
+
# 包含完整的 Base64 数据
|
41
|
+
# 注意:对于非常大的图片,这可能会产生非常长的输出字符串。
|
42
|
+
# return f"成功读取图片 '{image_path}':\n MIME 类型: {mime_type}\n Base64 数据: {base64_encoded_data}"
|
43
|
+
return f"data:{mime_type};base64," + base64_encoded_data
|
44
|
+
|
45
|
+
except FileNotFoundError:
|
46
|
+
# 这个异常通常由 open() 抛出,如果 os.path.exists 通过但文件在读取前被删除
|
47
|
+
# 或者路径检查逻辑未能完全覆盖所有情况 (理论上不应发生)
|
48
|
+
return f"错误: 图片路径 '{image_path}' 未找到 (可能在检查后被删除或移动)。"
|
49
|
+
except PermissionError:
|
50
|
+
return f"错误: 没有权限访问图片路径 '{image_path}'。"
|
51
|
+
except IOError as e: # 例如文件损坏无法读取,或磁盘问题
|
52
|
+
return f"错误: 读取图片 '{image_path}' 时发生 I/O 错误: {e}"
|
53
|
+
except Exception as e:
|
54
|
+
return f"读取图片 '{image_path}' 时发生未知错误: {e}"
|
aient/prompt/agent.py
CHANGED
@@ -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=6SuMfV8n0pBOaKN3WGqhPc53_LHBdyOECQgVsHscso8,46169
|
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
|
@@ -26,19 +26,20 @@ aient/plugins/config.py,sha256=Vp6CG9ocdC_FAlCMEGtKj45xamir76DFxdJVvURNtog,6539
|
|
26
26
|
aient/plugins/excute_command.py,sha256=A3WmfZboEikU1EHvtMWhBv-xHxCyMxbDddQ982I_8wE,10482
|
27
27
|
aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
|
28
28
|
aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
|
29
|
-
aient/plugins/list_directory.py,sha256=
|
29
|
+
aient/plugins/list_directory.py,sha256=JZVuImecMSfEv6jLqii-0uQJ1UCsrpMNmYlwW3PEDg4,1374
|
30
30
|
aient/plugins/read_file.py,sha256=-RRmaj-rSl8y--5VKnxCsZ1YQHe75OhnqvsDRLJyujM,8412
|
31
|
+
aient/plugins/read_image.py,sha256=goBnpmnmu753pQBkEROTo1ZaGE23fx5WJVr8T8z4598,2577
|
31
32
|
aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
|
32
33
|
aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
|
33
34
|
aient/plugins/websearch.py,sha256=llxy1U0vJiNMiKvamMr4p7IruLb3nnDR4YErz8TYimc,15215
|
34
35
|
aient/plugins/write_file.py,sha256=YRvQKMvV-5lwohxlvwt9hjfxz2dRJP85AJWAMUIqbBY,3804
|
35
36
|
aient/prompt/__init__.py,sha256=GBtn6-JDT8KHFCcuPpfSNE_aGddg5p4FEyMCy4BfwGs,20
|
36
|
-
aient/prompt/agent.py,sha256=
|
37
|
+
aient/prompt/agent.py,sha256=y2GETN6ScC5yQVs75VFfzm4YUWzblbqLYz0Sy6JnPRw,24950
|
37
38
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
38
39
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
39
40
|
aient/utils/scripts.py,sha256=NXmTxcZqHoRv3S13isLsv7kvqktXnA5ej7uMsxCJUe0,26656
|
40
|
-
aient-1.1.
|
41
|
-
aient-1.1.
|
42
|
-
aient-1.1.
|
43
|
-
aient-1.1.
|
44
|
-
aient-1.1.
|
41
|
+
aient-1.1.10.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
42
|
+
aient-1.1.10.dist-info/METADATA,sha256=59vJo7hMpLQ6Y9ZHXoLkZwiHuVpk1B5qLSepbTxXrXc,4968
|
43
|
+
aient-1.1.10.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
44
|
+
aient-1.1.10.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
45
|
+
aient-1.1.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|