'commit'
This commit is contained in:
@@ -84,11 +84,44 @@ def setup_memory_collection(collection_name="emotional_support"):
|
||||
memory_service, _ = initialize_services()
|
||||
ensure_collection_exists(memory_service, collection_name)
|
||||
print(f"记忆体 '{collection_name}' 创建/验证成功")
|
||||
return memory_service
|
||||
|
||||
# 添加集合就绪等待
|
||||
print("等待集合准备就绪...")
|
||||
if wait_for_collection_ready(memory_service, collection_name):
|
||||
print(f"集合 '{collection_name}' 已就绪")
|
||||
return memory_service
|
||||
else:
|
||||
print(f"集合 '{collection_name}' 未能就绪")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"记忆体创建失败: {e}")
|
||||
return None
|
||||
|
||||
def wait_for_collection_ready(memory_service, collection_name, timeout=300, interval=10):
|
||||
"""
|
||||
等待集合准备就绪
|
||||
:param memory_service: 记忆库服务实例
|
||||
:param collection_name: 集合名称
|
||||
:param timeout: 超时时间(秒)
|
||||
:param interval: 检查间隔(秒)
|
||||
:return: True if ready, False if timeout
|
||||
"""
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
try:
|
||||
collection_info = memory_service.get_collection(collection_name)
|
||||
# 根据Volcengine API文档,状态可能在Status字段中,值可能为"READY"、"CREATING"等
|
||||
status = collection_info.get("Status", "UNKNOWN")
|
||||
print(f"集合 '{collection_name}' 当前状态: {status}")
|
||||
if status == "READY":
|
||||
return True
|
||||
time.sleep(interval)
|
||||
except Exception as e:
|
||||
print(f"检查集合状态失败: {e}")
|
||||
time.sleep(interval)
|
||||
print(f"集合 '{collection_name}' 在{timeout}秒内未就绪")
|
||||
return False
|
||||
|
||||
def main():
|
||||
print("开始端到端记忆测试...")
|
||||
collection_name="emotional_support"
|
||||
@@ -139,4 +172,9 @@ def main():
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup_memory_collection()
|
||||
# main()
|
||||
# main()
|
||||
"""
|
||||
memory_service = setup_memory_collection()
|
||||
if memory_service:
|
||||
is_ready = wait_for_collection_ready(memory_service, "emotional_support")
|
||||
"""
|
Reference in New Issue
Block a user