aient 1.2.12__tar.gz → 1.2.13__tar.gz
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-1.2.12 → aient-1.2.13}/PKG-INFO +1 -1
- {aient-1.2.12 → aient-1.2.13}/aient/architext/architext/core.py +23 -0
- {aient-1.2.12 → aient-1.2.13}/aient/architext/test/test.py +44 -0
- {aient-1.2.12 → aient-1.2.13}/aient.egg-info/PKG-INFO +1 -1
- {aient-1.2.12 → aient-1.2.13}/pyproject.toml +1 -1
- {aient-1.2.12 → aient-1.2.13}/LICENSE +0 -0
- {aient-1.2.12 → aient-1.2.13}/README.md +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/architext/architext/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/architext/test/openai_client.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/architext/test/test_save_load.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/log_config.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/models.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/request.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/response.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/test/test_base_api.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/test/test_geminimask.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/test/test_image.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/test/test_payload.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/core/utils.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/models/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/models/audio.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/models/base.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/models/chatgpt.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/arXiv.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/config.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/excute_command.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/get_time.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/image.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/list_directory.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/read_file.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/read_image.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/readonly.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/registry.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/run_python.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/websearch.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/plugins/write_file.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/utils/__init__.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/utils/prompt.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient/utils/scripts.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient.egg-info/SOURCES.txt +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient.egg-info/dependency_links.txt +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient.egg-info/requires.txt +0 -0
- {aient-1.2.12 → aient-1.2.13}/aient.egg-info/top_level.txt +0 -0
- {aient-1.2.12 → aient-1.2.13}/setup.cfg +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_Web_crawler.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_ddg_search.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_google_search.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_ollama.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_plugin.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_search.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_url.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_whisper.py +0 -0
- {aient-1.2.12 → aient-1.2.13}/test/test_yjh.py +0 -0
@@ -147,6 +147,29 @@ class Texts(ContextProvider):
|
|
147
147
|
async def render(self) -> Optional[str]:
|
148
148
|
return self.content
|
149
149
|
|
150
|
+
def __getstate__(self):
|
151
|
+
"""Custom state for pickling."""
|
152
|
+
state = self.__dict__.copy()
|
153
|
+
if self._is_dynamic:
|
154
|
+
# For dynamic content, we snapshot its current value for serialization.
|
155
|
+
# The lambda function itself cannot be pickled.
|
156
|
+
try:
|
157
|
+
# Evaluate the lambda and store it as a static string
|
158
|
+
state['_text'] = self.content
|
159
|
+
# Mark it as no longer dynamic in the pickled state
|
160
|
+
state['_is_dynamic'] = False
|
161
|
+
except Exception as e:
|
162
|
+
# If the lambda fails for some reason, store an error message.
|
163
|
+
logging.error(f"Error evaluating dynamic text '{self.name}' during pickling: {e}")
|
164
|
+
state['_text'] = f"[Error: Could not evaluate dynamic content during save: {e}]"
|
165
|
+
state['_is_dynamic'] = False
|
166
|
+
return state
|
167
|
+
|
168
|
+
def __setstate__(self, state):
|
169
|
+
"""Custom state for unpickling."""
|
170
|
+
# Just restore the dictionary. The transformation is one-way.
|
171
|
+
self.__dict__.update(state)
|
172
|
+
|
150
173
|
def __eq__(self, other):
|
151
174
|
if not isinstance(other, Texts):
|
152
175
|
return NotImplemented
|
@@ -1258,6 +1258,50 @@ Current time: {Texts(lambda: datetime.now().strftime("%Y-%m-%d %H:%M:%S"))}
|
|
1258
1258
|
self.assertEqual(messages3[2].content, "C")
|
1259
1259
|
self.assertIsInstance(messages3[1], AssistantMessage)
|
1260
1260
|
|
1261
|
+
async def test_ze_fstring_lambda_serialization(self):
|
1262
|
+
"""测试包含 lambda 的 f-string 消息是否可以被序列化和反序列化"""
|
1263
|
+
import platform
|
1264
|
+
import os
|
1265
|
+
|
1266
|
+
# 1. 创建一个使用 f-string 和 lambda 的动态消息
|
1267
|
+
f_string_message = f"""系统信息: {Texts(lambda: platform.platform())}"""
|
1268
|
+
messages_to_save = Messages(SystemMessage(f_string_message))
|
1269
|
+
|
1270
|
+
# 2. 定义一个临时文件路径
|
1271
|
+
test_file_path = "test_lambda_serialization.pkl"
|
1272
|
+
|
1273
|
+
# 3. 序列化和反序列化
|
1274
|
+
try:
|
1275
|
+
# 保存
|
1276
|
+
messages_to_save.save(test_file_path)
|
1277
|
+
|
1278
|
+
# 确认文件已创建
|
1279
|
+
self.assertTrue(os.path.exists(test_file_path))
|
1280
|
+
|
1281
|
+
# 加载
|
1282
|
+
messages_loaded = Messages.load(test_file_path)
|
1283
|
+
|
1284
|
+
# 验证加载的对象
|
1285
|
+
self.assertIsNotNone(messages_loaded)
|
1286
|
+
self.assertIsInstance(messages_loaded, Messages)
|
1287
|
+
self.assertEqual(len(messages_loaded), 1)
|
1288
|
+
|
1289
|
+
# 4. 渲染加载后的消息以验证 lambda 是否仍然有效
|
1290
|
+
rendered = await messages_loaded.render_latest()
|
1291
|
+
|
1292
|
+
self.assertEqual(len(rendered), 1)
|
1293
|
+
self.assertIn("系统信息:", rendered[0]['content'])
|
1294
|
+
# 验证 platform.platform() 的结果是否在渲染内容中
|
1295
|
+
self.assertIn(platform.platform(), rendered[0]['content'])
|
1296
|
+
|
1297
|
+
except Exception as e:
|
1298
|
+
# 如果出现任何异常,测试失败
|
1299
|
+
self.fail(f"序列化或反序列化带有 lambda 的 f-string 消息时出错: {e}")
|
1300
|
+
finally:
|
1301
|
+
# 5. 清理临时文件
|
1302
|
+
if os.path.exists(test_file_path):
|
1303
|
+
os.remove(test_file_path)
|
1304
|
+
|
1261
1305
|
|
1262
1306
|
# ==============================================================================
|
1263
1307
|
# 6. 演示
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|