aient 1.1.22__py3-none-any.whl → 1.1.24__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/plugins/config.py CHANGED
@@ -8,10 +8,25 @@ from ..utils.prompt import search_key_word_prompt
8
8
  async def get_tools_result_async(function_call_name, function_full_response, function_call_max_tokens, engine, robot, api_key, api_url, use_plugins, model, add_message, convo_id, language):
9
9
  function_response = ""
10
10
  function_to_call = None
11
+ call_args = json.loads(function_full_response)
11
12
  if function_call_name in registry.tools:
12
13
  function_to_call = registry.tools[function_call_name]
14
+ call_args_name_list = call_args.keys()
15
+ required_args = registry.tools_info[function_call_name].args
16
+ invalid_args = [arg_name for arg_name in call_args_name_list if arg_name not in required_args]
17
+ if invalid_args:
18
+ function_response = (
19
+ "function_response:"
20
+ "<tool_error>"
21
+ f"无效的参数: {invalid_args}"
22
+ f"{function_call_name} 只允许使用以下参数: {required_args}"
23
+ "</tool_error>"
24
+ )
25
+ yield function_response
26
+ return
27
+
13
28
  if function_call_name == "get_search_results":
14
- prompt = json.loads(function_full_response)["query"]
29
+ prompt = call_args["query"]
15
30
  yield "message_search_stage_1"
16
31
  llm = robot(api_key=api_key, api_url=api_url, engine=engine, use_plugins=use_plugins)
17
32
  keywords = (await llm.ask_async(search_key_word_prompt.format(source=prompt), model=model)).split("\n")
@@ -38,11 +53,10 @@ async def get_tools_result_async(function_call_name, function_full_response, fun
38
53
  function_response = "无法找到相关信息,停止使用 tools"
39
54
 
40
55
  elif function_to_call:
41
- prompt = json.loads(function_full_response)
42
56
  if inspect.iscoroutinefunction(function_to_call):
43
- function_response = await function_to_call(**prompt)
57
+ function_response = await function_to_call(**call_args)
44
58
  else:
45
- function_response = function_to_call(**prompt)
59
+ function_response = function_to_call(**call_args)
46
60
 
47
61
  function_response = (
48
62
  f"function_response:{function_response}"
@@ -2,6 +2,8 @@ import os
2
2
  import base64
3
3
  import mimetypes
4
4
  from .registry import register_tool
5
+ import io
6
+ from PIL import Image, UnidentifiedImageError
5
7
 
6
8
  @register_tool()
7
9
  def read_image(image_path: str):
@@ -16,7 +18,12 @@ def read_image(image_path: str):
16
18
  str: 成功时返回包含图片MIME类型和Base64编码数据的格式化字符串。
17
19
  失败时返回错误信息字符串。
18
20
  """
21
+ original_max_pixels = Image.MAX_IMAGE_PIXELS
19
22
  try:
23
+ # 暂时禁用解压炸弹检查,以允许打开非常大的图像进行缩放。
24
+ # 这是安全的,因为我们控制代码,并且会立即对图像进行缩减。
25
+ Image.MAX_IMAGE_PIXELS = None
26
+
20
27
  # 检查路径是否存在
21
28
  if not os.path.exists(image_path):
22
29
  return f"<tool_error>图片路径 '{image_path}' 不存在。</tool_error>"
@@ -31,17 +38,40 @@ def read_image(image_path: str):
31
38
  # 如果mimetypes无法识别,或者不是图片类型
32
39
  return f"<tool_error>文件 '{image_path}' 的MIME类型无法识别为图片 (检测到: {mime_type})。请确保文件是常见的图片格式 (e.g., PNG, JPG, GIF, WEBP)。</tool_error>"
33
40
 
34
- with open(image_path, "rb") as image_file:
35
- image_data = image_file.read()
41
+ max_dim = 3072
42
+ with Image.open(image_path) as img:
43
+ width, height = img.size
44
+
45
+ target_img = img
46
+ if width > max_dim or height > max_dim:
47
+ if width > height:
48
+ new_width = max_dim
49
+ new_height = int(height * (max_dim / width))
50
+ else:
51
+ new_height = max_dim
52
+ new_width = int(width * (max_dim / height))
53
+
54
+ try:
55
+ resampling_filter = Image.Resampling.LANCZOS
56
+ except AttributeError:
57
+ # 兼容旧版 Pillow
58
+ resampling_filter = Image.LANCZOS
59
+
60
+ target_img = img.resize((new_width, new_height), resampling_filter)
61
+
62
+ # 将处理后的图片保存到内存中的字节流
63
+ img_byte_arr = io.BytesIO()
64
+ # 保留原始图片格式以获得最佳兼容性,如果无法确定格式,默认为PNG
65
+ img_format = img.format or 'PNG'
66
+ target_img.save(img_byte_arr, format=img_format)
67
+ image_data = img_byte_arr.getvalue()
36
68
 
37
69
  base64_encoded_data = base64.b64encode(image_data).decode('utf-8')
38
70
 
39
- # 返回一个描述性字符串,模仿 list_directory.py 的风格
40
- # 包含完整的 Base64 数据
41
- # 注意:对于非常大的图片,这可能会产生非常长的输出字符串。
42
- # return f"成功读取图片 '{image_path}':\n MIME 类型: {mime_type}\n Base64 数据: {base64_encoded_data}"
43
71
  return f"data:{mime_type};base64," + base64_encoded_data
44
72
 
73
+ except UnidentifiedImageError:
74
+ return f"<tool_error>无法识别的图片格式 '{image_path}',文件可能已损坏或格式不受支持。</tool_error>"
45
75
  except FileNotFoundError:
46
76
  # 这个异常通常由 open() 抛出,如果 os.path.exists 通过但文件在读取前被删除
47
77
  # 或者路径检查逻辑未能完全覆盖所有情况 (理论上不应发生)
@@ -51,4 +81,7 @@ def read_image(image_path: str):
51
81
  except IOError as e: # 例如文件损坏无法读取,或磁盘问题
52
82
  return f"<tool_error>读取图片 '{image_path}' 时发生 I/O 错误: {e}</tool_error>"
53
83
  except Exception as e:
54
- return f"<tool_error>读取图片 '{image_path}' 时发生未知错误: {e}</tool_error>"
84
+ return f"<tool_error>读取图片 '{image_path}' 时发生未知错误: {e}</tool_error>"
85
+ finally:
86
+ # 恢复原始限制以避免副作用。
87
+ Image.MAX_IMAGE_PIXELS = original_max_pixels
aient/utils/scripts.py CHANGED
@@ -496,7 +496,7 @@ def parse_function_xml(xml_content: str, check_line_start: bool = True) -> List[
496
496
  tag_inner_content = xml_content[tag_end+1:end_pos]
497
497
 
498
498
  # 如果是普通辅助标签(如tool_call),则在其内部寻找函数调用
499
- if tag_name in ["tool_call", "function_call", "tool", "function"]:
499
+ if tag_name in ["tool_call", "function_call", "tool", "function", "tools"]:
500
500
  # 递归处理内部内容,此时不再检查行首条件
501
501
  nested_functions = parse_function_xml(tag_inner_content, check_line_start=False)
502
502
  result_functions.extend(nested_functions)
@@ -740,7 +740,14 @@ if __name__ == "__main__":
740
740
 
741
741
  请提供前两个 `excute_command` 的执行结果。
742
742
  """
743
-
743
+ test_xml = """
744
+ 好的,我现在执行第一步。
745
+ <tools>
746
+ <list_directory>
747
+ <path>/Downloads/GitHub/beswarm/work/test</path>
748
+ </list_directory>
749
+ </tools>
750
+ """
744
751
  print(parse_function_xml(test_xml))
745
752
 
746
753
  # 运行本文件:python -m beswarm.aient.src.aient.utils.scripts
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.22
3
+ Version: 1.1.24
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -22,13 +22,13 @@ aient/models/groq.py,sha256=eXfSOaPxgQEtk4U8qseArN8rFYOFBfMsPwRcDW1nERo,8790
22
22
  aient/models/vertex.py,sha256=qVD5l1Q538xXUPulxG4nmDjXE1VoV4yuAkTCpIeJVw0,16795
23
23
  aient/plugins/__init__.py,sha256=p3KO6Aa3Lupos4i2SjzLQw1hzQTigOAfEHngsldrsyk,986
24
24
  aient/plugins/arXiv.py,sha256=yHjb6PS3GUWazpOYRMKMzghKJlxnZ5TX8z9F6UtUVow,1461
25
- aient/plugins/config.py,sha256=Vp6CG9ocdC_FAlCMEGtKj45xamir76DFxdJVvURNtog,6539
25
+ aient/plugins/config.py,sha256=QGyI9LlNaU36GUpY531o7UbTFBB39u7LfS6rrx_RTWw,7103
26
26
  aient/plugins/excute_command.py,sha256=i5AUSfnYe05cS4YZuNIhuCy-Cfxil7RJG372YwzteXs,10691
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
30
  aient/plugins/read_file.py,sha256=Lv03AW-gWGzM2esos2vLTXHcceczdTqEO7_vqFT4yoY,8302
31
- aient/plugins/read_image.py,sha256=jFu8MGCPWg19YOG-STWH3pqacf94F17i_4JaJu1XWLs,2704
31
+ aient/plugins/read_image.py,sha256=4FbIiMNVFUQpNyiH5ApGSRvOD9ujcXGyuqlGTJMd7ac,4017
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=ZNsbgXRyvYzAFTRRziAnNVqcTyAnxrGcsGfGrt72j6k,25427
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=LD8adnfuRrJoY2tWKseXOPJXaxbrUmz4czsnUvHswNY,29096
41
- aient-1.1.22.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
42
- aient-1.1.22.dist-info/METADATA,sha256=sFiobRMyPCjvaMyWZk4GCwe2_KFCzHSLNKEeJ75HSUI,4968
43
- aient-1.1.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
- aient-1.1.22.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
45
- aient-1.1.22.dist-info/RECORD,,
40
+ aient/utils/scripts.py,sha256=RFkuu3j1tC_x1SwQQsS__wQOZe5olmy7FPHEOk5Obds,29265
41
+ aient-1.1.24.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
42
+ aient-1.1.24.dist-info/METADATA,sha256=FyHXoKl3zIZncMu4FevGSBk52ZEEa-cn_o1KS4Ru18g,4968
43
+ aient-1.1.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
44
+ aient-1.1.24.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
45
+ aient-1.1.24.dist-info/RECORD,,
File without changes