aient 1.2.22__py3-none-any.whl → 1.2.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/architext/architext/core.py +19 -0
- aient/architext/test/test.py +25 -0
- aient/plugins/read_file.py +20 -9
- {aient-1.2.22.dist-info → aient-1.2.24.dist-info}/METADATA +1 -1
- {aient-1.2.22.dist-info → aient-1.2.24.dist-info}/RECORD +8 -8
- {aient-1.2.22.dist-info → aient-1.2.24.dist-info}/WHEEL +0 -0
- {aient-1.2.22.dist-info → aient-1.2.24.dist-info}/licenses/LICENSE +0 -0
- {aient-1.2.22.dist-info → aient-1.2.24.dist-info}/top_level.txt +0 -0
@@ -457,6 +457,15 @@ class Message(ABC):
|
|
457
457
|
return len(self._items)
|
458
458
|
|
459
459
|
def __repr__(self): return f"Message(role='{self.role}', items={[i.name for i in self._items]})"
|
460
|
+
|
461
|
+
def __contains__(self, item: Any) -> bool:
|
462
|
+
"""Checks if a ContextProvider is in the message."""
|
463
|
+
if not isinstance(item, ContextProvider):
|
464
|
+
return False
|
465
|
+
# The `in` operator on a list checks for equality,
|
466
|
+
# and our custom __eq__ on ContextProvider handles the comparison logic.
|
467
|
+
return item in self._items
|
468
|
+
|
460
469
|
def __bool__(self) -> bool:
|
461
470
|
return bool(self._items)
|
462
471
|
def get(self, key: str, default: Any = None) -> Any:
|
@@ -717,3 +726,13 @@ class Messages:
|
|
717
726
|
|
718
727
|
def __len__(self) -> int: return len(self._messages)
|
719
728
|
def __iter__(self): return iter(self._messages)
|
729
|
+
|
730
|
+
def __contains__(self, item: Any) -> bool:
|
731
|
+
"""Checks if a Message or ContextProvider is in the collection."""
|
732
|
+
if isinstance(item, Message):
|
733
|
+
# Check for object identity
|
734
|
+
return any(item is msg for msg in self._messages)
|
735
|
+
if isinstance(item, ContextProvider):
|
736
|
+
# Check if any message contains the provider
|
737
|
+
return any(item in msg for msg in self._messages)
|
738
|
+
return False
|
aient/architext/test/test.py
CHANGED
@@ -1409,6 +1409,31 @@ Files: {Files(visible=True, name="files")}
|
|
1409
1409
|
# 5. 验证 provider 索引
|
1410
1410
|
self.assertIsNotNone(messages.provider(text_provider.name))
|
1411
1411
|
|
1412
|
+
async def test_zi_provider_in_message_and_messages(self):
|
1413
|
+
"""测试 `in` 操作符是否能检查 provider 是否存在于 Message 或 Messages 中"""
|
1414
|
+
# 1. 准备 providers 和 messages
|
1415
|
+
text_hi = Texts("hi")
|
1416
|
+
text_hello = Texts("hello")
|
1417
|
+
text_world = Texts("world")
|
1418
|
+
|
1419
|
+
message = UserMessage(text_hello, text_hi)
|
1420
|
+
messages_collection = Messages(SystemMessage("System"), message)
|
1421
|
+
|
1422
|
+
# 2. 测试 `in` Message
|
1423
|
+
self.assertTrue(Texts("hi") in UserMessage(Texts("hello"), Texts("hi")))
|
1424
|
+
self.assertTrue(text_hi in message)
|
1425
|
+
self.assertTrue(text_hello in message)
|
1426
|
+
self.assertFalse(text_world in message)
|
1427
|
+
|
1428
|
+
# 3. 测试 `in` Messages
|
1429
|
+
self.assertTrue(text_hi in messages_collection)
|
1430
|
+
self.assertTrue(text_hello in messages_collection)
|
1431
|
+
self.assertFalse(text_world in messages_collection)
|
1432
|
+
|
1433
|
+
# 4. 测试一个 Message 对象是否在 Messages 中
|
1434
|
+
self.assertTrue(message in messages_collection)
|
1435
|
+
self.assertFalse(UserMessage("not in collection") in messages_collection)
|
1436
|
+
|
1412
1437
|
|
1413
1438
|
# ==============================================================================
|
1414
1439
|
# 6. 演示
|
aient/plugins/read_file.py
CHANGED
@@ -7,7 +7,7 @@ from .registry import register_tool
|
|
7
7
|
|
8
8
|
# 读取文件内容
|
9
9
|
@register_tool()
|
10
|
-
def read_file(file_path):
|
10
|
+
def read_file(file_path, head: int = None):
|
11
11
|
"""
|
12
12
|
Description: Request to read the contents of a file at the specified path. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. Automatically extracts raw text from PDF and DOCX files. May not be suitable for other types of binary files, as it returns the raw content as a string.
|
13
13
|
|
@@ -16,6 +16,7 @@ Description: Request to read the contents of a file at the specified path. Use t
|
|
16
16
|
|
17
17
|
参数:
|
18
18
|
file_path: 要读取的文件路径,(required) The path of the file to read (relative to the current working directory)
|
19
|
+
head: (可选) 读取文件的前N行,默认为None,读取整个文件
|
19
20
|
|
20
21
|
返回:
|
21
22
|
文件内容的字符串
|
@@ -161,13 +162,23 @@ Examples:
|
|
161
162
|
# 捕获在此块中可能发生的其他错误,例如未被早期检查捕获的文件读取问题
|
162
163
|
return f"<tool_error>处理通用文件 '{file_path}' 时发生错误: {e}</tool_error>"
|
163
164
|
|
164
|
-
if
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
165
|
+
if head is not None:
|
166
|
+
try:
|
167
|
+
num_lines = int(head)
|
168
|
+
if num_lines > 0:
|
169
|
+
lines = text_content.splitlines(True)
|
170
|
+
return "".join(lines[:num_lines])
|
171
|
+
except (ValueError, TypeError):
|
172
|
+
# Invalid head value, ignore and proceed with normal logic.
|
173
|
+
pass
|
174
|
+
|
175
|
+
# if file_path.lower().endswith('.csv'):
|
176
|
+
# lines = text_content.splitlines(True)
|
177
|
+
# if len(lines) > 500:
|
178
|
+
# top_lines = lines[:250]
|
179
|
+
# bottom_lines = lines[-250:]
|
180
|
+
# omitted_count = len(lines) - 500
|
181
|
+
# text_content = "".join(top_lines) + f"\n... (中间省略了 {omitted_count} 行) ...\n" + "".join(bottom_lines)
|
171
182
|
|
172
183
|
# 返回文件内容
|
173
184
|
return text_content
|
@@ -182,6 +193,6 @@ Examples:
|
|
182
193
|
|
183
194
|
if __name__ == "__main__":
|
184
195
|
# python -m beswarm.aient.aient.plugins.read_file
|
185
|
-
result = read_file("./work/cax/Lenia Notebook.ipynb")
|
196
|
+
result = read_file("./work/cax/Lenia Notebook.ipynb", head=10)
|
186
197
|
print(result)
|
187
198
|
print(len(result))
|
@@ -1,8 +1,8 @@
|
|
1
1
|
aient/__init__.py,sha256=SRfF7oDVlOOAi6nGKiJIUK6B_arqYLO9iSMp-2IZZps,21
|
2
2
|
aient/architext/architext/__init__.py,sha256=79Ih1151rfcqZdr7F8HSZSTs_iT2SKd1xCkehMsXeXs,19
|
3
|
-
aient/architext/architext/core.py,sha256=
|
3
|
+
aient/architext/architext/core.py,sha256=_o5gI5XF6e4kQo4L4x8Q1Tb7C1U0GANm24gJmvAgoXE,30546
|
4
4
|
aient/architext/test/openai_client.py,sha256=Dqtbmubv6vwF8uBqcayG0kbsiO65of7sgU2-DRBi-UM,4590
|
5
|
-
aient/architext/test/test.py,sha256=
|
5
|
+
aient/architext/test/test.py,sha256=G64knZR1rSo0hr8lZPaWWJizEq1A8RGCzcN0e9uhZEM,66729
|
6
6
|
aient/architext/test/test_save_load.py,sha256=o8DqH6gDYZkFkQy-a7blqLtJTRj5e4a-Lil48pJ0V3g,3260
|
7
7
|
aient/core/__init__.py,sha256=NxjebTlku35S4Dzr16rdSqSTWUvvwEeACe8KvHJnjPg,34
|
8
8
|
aient/core/log_config.py,sha256=kz2_yJv1p-o3lUQOwA3qh-LSc3wMHv13iCQclw44W9c,274
|
@@ -25,7 +25,7 @@ aient/plugins/excute_command.py,sha256=b-rxsyFN6_HnZJAhUi9Qsp8iJ6XTf-zU-CIUIxeQO
|
|
25
25
|
aient/plugins/get_time.py,sha256=Ih5XIW5SDAIhrZ9W4Qe5Hs1k4ieKPUc_LAd6ySNyqZk,654
|
26
26
|
aient/plugins/image.py,sha256=ZElCIaZznE06TN9xW3DrSukS7U3A5_cjk1Jge4NzPxw,2072
|
27
27
|
aient/plugins/list_directory.py,sha256=V_uKkLx_fQDL5z__bSDC-PqAP-o32KmQW6Pdhx0Fx0s,1433
|
28
|
-
aient/plugins/read_file.py,sha256=
|
28
|
+
aient/plugins/read_file.py,sha256=qHAhdesOr1VMOCDkeHNvI8UV2ZI98HmJl6GhN4Aq9dU,9183
|
29
29
|
aient/plugins/read_image.py,sha256=4FbIiMNVFUQpNyiH5ApGSRvOD9ujcXGyuqlGTJMd7ac,4017
|
30
30
|
aient/plugins/readonly.py,sha256=qK5-kBM3NDH1b-otFxFHpAjV5BXEY_e7cTWBcpP7G5k,710
|
31
31
|
aient/plugins/registry.py,sha256=YknzhieU_8nQ3oKlUSSWDB4X7t2Jx0JnqT2Jd9Xsvfk,3574
|
@@ -35,8 +35,8 @@ aient/plugins/write_file.py,sha256=Jt8fOEwqhYiSWpCbwfAr1xoi_BmFnx3076GMhuL06uI,3
|
|
35
35
|
aient/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
36
36
|
aient/utils/prompt.py,sha256=UcSzKkFE4-h_1b6NofI6xgk3GoleqALRKY8VBaXLjmI,11311
|
37
37
|
aient/utils/scripts.py,sha256=VqtK4RFEx7KxkmcqG3lFDS1DxoNlFFGErEjopVcc8IE,40974
|
38
|
-
aient-1.2.
|
39
|
-
aient-1.2.
|
40
|
-
aient-1.2.
|
41
|
-
aient-1.2.
|
42
|
-
aient-1.2.
|
38
|
+
aient-1.2.24.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
39
|
+
aient-1.2.24.dist-info/METADATA,sha256=asc_up8u5JmXRD4lm8vxwTYaK2fm7hmVpwLbgxFWdTo,4842
|
40
|
+
aient-1.2.24.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
41
|
+
aient-1.2.24.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
42
|
+
aient-1.2.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|