aient 1.1.97__py3-none-any.whl → 1.1.99__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 +29 -3
- aient/architext/test/test.py +55 -0
- {aient-1.1.97.dist-info → aient-1.1.99.dist-info}/METADATA +1 -1
- {aient-1.1.97.dist-info → aient-1.1.99.dist-info}/RECORD +7 -7
- {aient-1.1.97.dist-info → aient-1.1.99.dist-info}/WHEEL +0 -0
- {aient-1.1.97.dist-info → aient-1.1.99.dist-info}/licenses/LICENSE +0 -0
- {aient-1.1.97.dist-info → aient-1.1.99.dist-info}/top_level.txt +0 -0
@@ -35,13 +35,30 @@ class ContentBlock:
|
|
35
35
|
# 2. 上下文提供者 (带缓存)
|
36
36
|
class ContextProvider(ABC):
|
37
37
|
def __init__(self, name: str):
|
38
|
-
self.name = name
|
38
|
+
self.name = name
|
39
|
+
self._cached_content: Optional[str] = None
|
40
|
+
self._is_stale: bool = True
|
41
|
+
self._visible: bool = True
|
39
42
|
|
40
43
|
def __str__(self):
|
41
44
|
# This allows the object to be captured when used inside an f-string.
|
42
45
|
return _register_provider(self)
|
43
46
|
|
44
47
|
def mark_stale(self): self._is_stale = True
|
48
|
+
|
49
|
+
@property
|
50
|
+
def visible(self) -> bool:
|
51
|
+
"""Gets the visibility of the provider."""
|
52
|
+
return self._visible
|
53
|
+
|
54
|
+
@visible.setter
|
55
|
+
def visible(self, value: bool):
|
56
|
+
"""Sets the visibility of the provider."""
|
57
|
+
if self._visible != value:
|
58
|
+
self._visible = value
|
59
|
+
# Content needs to be re-evaluated, but the source data hasn't changed,
|
60
|
+
# so just marking it stale is enough for the renderer to reconsider it.
|
61
|
+
self.mark_stale()
|
45
62
|
async def refresh(self):
|
46
63
|
if self._is_stale:
|
47
64
|
self._cached_content = await self.render()
|
@@ -51,7 +68,8 @@ class ContextProvider(ABC):
|
|
51
68
|
@abstractmethod
|
52
69
|
def update(self, *args, **kwargs): raise NotImplementedError
|
53
70
|
def get_content_block(self) -> Optional[ContentBlock]:
|
54
|
-
if self._cached_content is not None:
|
71
|
+
if self.visible and self._cached_content is not None:
|
72
|
+
return ContentBlock(self.name, self._cached_content)
|
55
73
|
return None
|
56
74
|
|
57
75
|
class Texts(ContextProvider):
|
@@ -84,7 +102,12 @@ class Texts(ContextProvider):
|
|
84
102
|
self._is_dynamic = callable(self._text)
|
85
103
|
self.mark_stale()
|
86
104
|
|
87
|
-
|
105
|
+
@property
|
106
|
+
def content(self) -> Optional[str]:
|
107
|
+
"""
|
108
|
+
Synchronously retrieves the raw text content as a property.
|
109
|
+
If the content is dynamic (a callable), it executes the callable.
|
110
|
+
"""
|
88
111
|
if self._is_dynamic:
|
89
112
|
# Ensure dynamic content returns a string, even if empty
|
90
113
|
result = self._text()
|
@@ -92,6 +115,9 @@ class Texts(ContextProvider):
|
|
92
115
|
# Ensure static content returns a string, even if empty
|
93
116
|
return self._text if self._text is not None else ""
|
94
117
|
|
118
|
+
async def render(self) -> Optional[str]:
|
119
|
+
return self.content
|
120
|
+
|
95
121
|
class Tools(ContextProvider):
|
96
122
|
def __init__(self, tools_json: Optional[List[Dict]] = None, name: str = "tools"):
|
97
123
|
super().__init__(name)
|
aient/architext/test/test.py
CHANGED
@@ -998,6 +998,61 @@ Current time: {Texts(lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))}
|
|
998
998
|
# 验证两次渲染的时间戳不同
|
999
999
|
self.assertNotEqual(time1_str_part, time2_str_part, "f-string 中的动态 lambda 内容在两次渲染之间应该更新")
|
1000
1000
|
|
1001
|
+
def test_z6_direct_content_access(self):
|
1002
|
+
"""测试通过 .content 属性直接访问 Texts 内容"""
|
1003
|
+
# 1. 测试静态内容
|
1004
|
+
static_text = Texts("Hello, Architext!")
|
1005
|
+
self.assertEqual(static_text.content, "Hello, Architext!")
|
1006
|
+
|
1007
|
+
# 2. 测试动态内容
|
1008
|
+
from datetime import datetime
|
1009
|
+
current_time_str = datetime.now().isoformat()
|
1010
|
+
dynamic_text = Texts(lambda: current_time_str)
|
1011
|
+
self.assertEqual(dynamic_text.content, current_time_str)
|
1012
|
+
|
1013
|
+
# 3. 测试更新后的内容访问
|
1014
|
+
static_text.update("Updated content.")
|
1015
|
+
self.assertEqual(static_text.content, "Updated content.")
|
1016
|
+
|
1017
|
+
# 4. 测试 None 和空字符串
|
1018
|
+
none_text = Texts(name="none_text") # Provide a name when text is None
|
1019
|
+
self.assertEqual(none_text.content, "")
|
1020
|
+
|
1021
|
+
empty_text = Texts("")
|
1022
|
+
self.assertEqual(empty_text.content, "")
|
1023
|
+
|
1024
|
+
async def test_z7_provider_visibility(self):
|
1025
|
+
"""测试 provider 的可见性标志是否能正常工作"""
|
1026
|
+
# 1. 初始化 provider,visible 默认为 True
|
1027
|
+
text_provider = Texts("Hello, World!", name="greeting")
|
1028
|
+
self.assertTrue(text_provider.visible)
|
1029
|
+
|
1030
|
+
messages = Messages(SystemMessage(text_provider))
|
1031
|
+
|
1032
|
+
# 2. 初始渲染,内容应该可见
|
1033
|
+
rendered_visible = await messages.render_latest()
|
1034
|
+
self.assertEqual(len(rendered_visible), 1)
|
1035
|
+
self.assertEqual(rendered_visible[0]['content'], "Hello, World!")
|
1036
|
+
|
1037
|
+
# 3. 设置为不可见
|
1038
|
+
provider = messages.provider("greeting")
|
1039
|
+
provider.visible = False
|
1040
|
+
self.assertFalse(provider.visible)
|
1041
|
+
|
1042
|
+
# 4. 再次渲染,内容应该消失
|
1043
|
+
# 因为 visibility 变化会 mark_stale,所以需要 render_latest
|
1044
|
+
rendered_invisible = await messages.render_latest()
|
1045
|
+
self.assertEqual(len(rendered_invisible), 0, "设置为不可见后,消息应该不被渲染")
|
1046
|
+
|
1047
|
+
# 5. 再次设置为可见
|
1048
|
+
provider.visible = True
|
1049
|
+
self.assertTrue(provider.visible)
|
1050
|
+
|
1051
|
+
# 6. 渲染,内容应该再次出现
|
1052
|
+
rendered_visible_again = await messages.render_latest()
|
1053
|
+
self.assertEqual(len(rendered_visible_again), 1)
|
1054
|
+
self.assertEqual(rendered_visible_again[0]['content'], "Hello, World!")
|
1055
|
+
|
1001
1056
|
|
1002
1057
|
# ==============================================================================
|
1003
1058
|
# 6. 演示
|
@@ -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=RGUKPrTm0mXrC7FweIkPXRAXCDE1xxU08pZo1n-2tsA,21555
|
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=CSjXZbY-cgJP1xXY-vA56iM5XXMfwsW2sZQLwAwWS7k,50477
|
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
|
@@ -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.1.
|
39
|
-
aient-1.1.
|
40
|
-
aient-1.1.
|
41
|
-
aient-1.1.
|
42
|
-
aient-1.1.
|
38
|
+
aient-1.1.99.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
|
39
|
+
aient-1.1.99.dist-info/METADATA,sha256=lUsprSWgvrH42NHm6pTNppqBmiSn7FG1BH2IDEZa4cE,4842
|
40
|
+
aient-1.1.99.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
41
|
+
aient-1.1.99.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
|
42
|
+
aient-1.1.99.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|