From 2528581c4ce80a90826f9f07b4db70b4d21173a2 Mon Sep 17 00:00:00 2001 From: isaacJinyu <1376193973@qq.com> Date: Fri, 7 Feb 2025 20:19:50 +0800 Subject: [PATCH] update SPO code --- metagpt/ext/spo/utils/load.py | 14 +++++++++++--- metagpt/ext/spo/utils/prompt_utils.py | 2 -- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/metagpt/ext/spo/utils/load.py b/metagpt/ext/spo/utils/load.py index 14dee74c6..2b3a1371d 100644 --- a/metagpt/ext/spo/utils/load.py +++ b/metagpt/ext/spo/utils/load.py @@ -11,11 +11,19 @@ def set_file_name(name): def load_meta_data(k=SAMPLE_K): - # load yaml file config_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'settings', FILE_NAME) - with open(config_path, 'r', encoding='utf-8') as file: - data = yaml.safe_load(file) + + if not os.path.exists(config_path): + raise FileNotFoundError(f"Configuration file '{FILE_NAME}' not found in settings directory") + + try: + with open(config_path, '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)}") + except Exception as e: + raise Exception(f"Error reading file '{FILE_NAME}': {str(e)}") qa = [] diff --git a/metagpt/ext/spo/utils/prompt_utils.py b/metagpt/ext/spo/utils/prompt_utils.py index 1fcc4cb4e..8bf1ec898 100644 --- a/metagpt/ext/spo/utils/prompt_utils.py +++ b/metagpt/ext/spo/utils/prompt_utils.py @@ -33,6 +33,4 @@ class PromptUtils: with open(os.path.join(directory, "prompt.txt"), "w", encoding="utf-8") as file: file.write(prompt) - with open(os.path.join(directory, "__init__.py"), "w", encoding="utf-8") as file: - file.write("")