aient 1.0.77__py3-none-any.whl → 1.0.78__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.
@@ -1,4 +1,5 @@
1
1
  import os
2
+ import json
2
3
  from pdfminer.high_level import extract_text
3
4
 
4
5
  from .registry import register_tool
@@ -63,6 +64,40 @@ Examples:
63
64
  # 如果提取结果为空
64
65
  if not text_content:
65
66
  return f"错误: 无法从 '{file_path}' 提取文本内容"
67
+ elif file_path.lower().endswith('.ipynb'):
68
+ try:
69
+ with open(file_path, 'r', encoding='utf-8') as file:
70
+ notebook_content = json.load(file)
71
+
72
+ for cell in notebook_content.get('cells', []):
73
+ if cell.get('cell_type') == 'code' and 'outputs' in cell:
74
+ filtered_outputs = []
75
+ for output in cell.get('outputs', []):
76
+ new_output = output.copy()
77
+ if 'data' in new_output:
78
+ original_data = new_output['data']
79
+ filtered_data = {}
80
+ for key, value in original_data.items():
81
+ if key.startswith('image/'):
82
+ continue
83
+ if key == 'text/html':
84
+ html_content = "".join(value) if isinstance(value, list) else value
85
+ if isinstance(html_content, str) and '<table class="show_videos"' in html_content:
86
+ continue
87
+ filtered_data[key] = value
88
+ if filtered_data:
89
+ new_output['data'] = filtered_data
90
+ filtered_outputs.append(new_output)
91
+ elif 'output_type' in new_output and new_output['output_type'] in ['stream', 'error']:
92
+ filtered_outputs.append(new_output)
93
+
94
+ cell['outputs'] = filtered_outputs
95
+
96
+ text_content = json.dumps(notebook_content, indent=2, ensure_ascii=False)
97
+ except json.JSONDecodeError:
98
+ return f"错误: 文件 '{file_path}' 不是有效的JSON格式 (IPython Notebook)。"
99
+ except Exception as e:
100
+ return f"处理IPython Notebook文件 '{file_path}' 时发生错误: {e}"
66
101
  else:
67
102
  # 读取文件内容
68
103
  with open(file_path, 'r', encoding='utf-8') as file:
@@ -76,4 +111,10 @@ Examples:
76
111
  except UnicodeDecodeError:
77
112
  return f"错误: 文件 '{file_path}' 不是文本文件或编码不是UTF-8"
78
113
  except Exception as e:
79
- return f"读取文件时发生错误: {e}"
114
+ return f"读取文件时发生错误: {e}"
115
+
116
+ if __name__ == "__main__":
117
+ # python -m beswarm.aient.src.aient.plugins.read_file
118
+ result = read_file("./work/cax/Lenia Notebook.ipynb")
119
+ print(result)
120
+ print(len(result))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.0.77
3
+ Version: 1.0.78
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -26,7 +26,7 @@ aient/plugins/excute_command.py,sha256=0sQZGLCaRfh0yMM63fXU8XZV7jlo9FKeyEbM-rfgT
26
26
  aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
27
27
  aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
28
28
  aient/plugins/list_directory.py,sha256=5ubm-mfrj-tanGSDp4M_Tmb6vQb3dx2-XVfQ2yL2G8A,1394
29
- aient/plugins/read_file.py,sha256=kjHqtAGSy6AV8kFpv342x6yWGYfvZ9LGmxFZXJ3XzQI,2369
29
+ aient/plugins/read_file.py,sha256=v07127SXOhS8YGJ6X82Gw2xlk-nlKvX7SdxzZVe1z0Y,4625
30
30
  aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
31
31
  aient/plugins/run_python.py,sha256=dgcUwBunMuDkaSKR5bToudVzSdrXVewktDDFUz_iIOQ,4589
32
32
  aient/plugins/websearch.py,sha256=yiBzqXK5X220ibR-zko3VDsn4QOnLu1k6E2YOygCeTQ,15185
@@ -36,8 +36,8 @@ aient/prompt/agent.py,sha256=WLs0KiNZs29FJ5w7N3kQZYLVEeS7K8vxIOUw06LcXVE,23825
36
36
  aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
38
38
  aient/utils/scripts.py,sha256=n0jR5eXCBIK12W4bIx-xU1FVl1hZ4zDC7hq_BWQHYJU,27537
39
- aient-1.0.77.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
40
- aient-1.0.77.dist-info/METADATA,sha256=C5HByv10I5sF4pNpCeJcxYlVefOZBiqD9HBvSmQI4Kg,5000
41
- aient-1.0.77.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
42
- aient-1.0.77.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
43
- aient-1.0.77.dist-info/RECORD,,
39
+ aient-1.0.78.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
40
+ aient-1.0.78.dist-info/METADATA,sha256=u_ftnmrNBcaKp2aPJrFYey2mWB67bYmGqER_iKT4Th8,5000
41
+ aient-1.0.78.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
42
+ aient-1.0.78.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
43
+ aient-1.0.78.dist-info/RECORD,,
File without changes