Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

modify spo load, use pathlib instead of os.path

xiangjinyuf3f66d43bbcb
diff --git a/metagpt/ext/spo/utils/load.py b/metagpt/ext/spo/utils/load.py
index bf0d8af4e..f8c4f53fc 100644
--- a/metagpt/ext/spo/utils/load.py
+++ b/metagpt/ext/spo/utils/load.py
@@ -1,5 +1,5 @@
-import os
import random
+from pathlib import Path
import yaml
@@ -14,13 +14,13 @@ def set_file_name(name: str):
def load_meta_data(k: int = SAMPLE_K):
# load yaml file
- config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "settings", FILE_NAME)
+ config_path = Path(__file__).parent.parent / "settings" / FILE_NAME
- if not os.path.exists(config_path):
+ if not config_path.exists():
raise FileNotFoundError(f"Configuration file '{FILE_NAME}' not found in settings directory")
try:
- with open(config_path, "r", encoding="utf-8") as file:
+ with config_path.open("r", encoding="utf-8") as file:
data = yaml.safe_load(file)
except yaml.YAMLError as e:
raise ValueError(f"Error parsing YAML file '{FILE_NAME}': {str(e)}")