aient 1.1.98__py3-none-any.whl → 1.2.0__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.
@@ -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; self._cached_content: Optional[str] = None; self._is_stale: bool = True
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: return ContentBlock(self.name, self._cached_content)
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):
@@ -1021,6 +1021,38 @@ Current time: {Texts(lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))}
1021
1021
  empty_text = Texts("")
1022
1022
  self.assertEqual(empty_text.content, "")
1023
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
+
1024
1056
 
1025
1057
  # ==============================================================================
1026
1058
  # 6. 演示
aient/models/chatgpt.py CHANGED
@@ -97,13 +97,8 @@ class chatgpt(BaseLLM):
97
97
  Initialize Chatbot with API key (from https://platform.openai.com/account/api-keys)
98
98
  """
99
99
  super().__init__(api_key, engine, api_url, system_prompt, proxy, timeout, max_tokens, temperature, top_p, presence_penalty, frequency_penalty, reply_count, truncate_limit, use_plugins=use_plugins, print_log=print_log)
100
- self.conversation: dict[str, list[dict]] = {
101
- "default": [
102
- {
103
- "role": "system",
104
- "content": self.system_prompt,
105
- },
106
- ],
100
+ self.conversation: dict[str, Messages] = {
101
+ "default": Messages(SystemMessage(self.system_prompt)),
107
102
  }
108
103
  if cache_messages:
109
104
  self.conversation["default"] = cache_messages
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aient
3
- Version: 1.1.98
3
+ Version: 1.2.0
4
4
  Summary: Aient: The Awakening of Agent.
5
5
  Requires-Python: >=3.11
6
6
  Description-Content-Type: text/markdown
@@ -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=pgnJ5Q9dlxMpp4ilBuHzScxbTlVYihubpo6uYqNV1lU,20976
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=5xV8nrOBf2Gn49EGnBvGLNXQRbNGi_hD0PYESs7tl0g,49091
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
@@ -17,7 +17,7 @@ aient/core/test/test_payload.py,sha256=8jBiJY1uidm1jzL-EiK0s6UGmW9XkdsuuKFGrwFhF
17
17
  aient/models/__init__.py,sha256=ZTiZgbfBPTjIPSKURE7t6hlFBVLRS9lluGbmqc1WjxQ,43
18
18
  aient/models/audio.py,sha256=kRd-8-WXzv4vwvsTGwnstK-WR8--vr9CdfCZzu8y9LA,1934
19
19
  aient/models/base.py,sha256=-nnihYnx-vHZMqeVO9ljjt3k4FcD3n-iMk4tT-10nRQ,7232
20
- aient/models/chatgpt.py,sha256=EqvIcB6R_JGmvD5kEfR1ZRQYLfyGpmy4PvfRx8hMIKE,42019
20
+ aient/models/chatgpt.py,sha256=_fYGUnSciKSWYhPuS0lECtU6-C42GGGhFiqbVxejaJg,41919
21
21
  aient/plugins/__init__.py,sha256=p3KO6Aa3Lupos4i2SjzLQw1hzQTigOAfEHngsldrsyk,986
22
22
  aient/plugins/arXiv.py,sha256=yHjb6PS3GUWazpOYRMKMzghKJlxnZ5TX8z9F6UtUVow,1461
23
23
  aient/plugins/config.py,sha256=TGgZ5SnNKZ8MmdznrZ-TEq7s2ulhAAwTSKH89bci3dA,7079
@@ -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.98.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
39
- aient-1.1.98.dist-info/METADATA,sha256=Ovyrvqq57HzewzZke5vlu0OuV0E8TQm2s0FGMxlrKcA,4842
40
- aient-1.1.98.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
- aient-1.1.98.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
42
- aient-1.1.98.dist-info/RECORD,,
38
+ aient-1.2.0.dist-info/licenses/LICENSE,sha256=XNdbcWldt0yaNXXWB_Bakoqnxb3OVhUft4MgMA_71ds,1051
39
+ aient-1.2.0.dist-info/METADATA,sha256=YPHfQb4kRpMzEehuqTUOm36MKNkFfcc4VrDJQbNga00,4841
40
+ aient-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ aient-1.2.0.dist-info/top_level.txt,sha256=3oXzrP5sAVvyyqabpeq8A2_vfMtY554r4bVE-OHBrZk,6
42
+ aient-1.2.0.dist-info/RECORD,,
File without changes