From 700f9aae41ae4ca6eccd82752747078ba975ea5c Mon Sep 17 00:00:00 2001 From: usamimeri_renko <93753250+usamimeri@users.noreply.github.com> Date: Wed, 5 Jun 2024 18:47:15 +0800 Subject: [PATCH 1/2] optimize error message when validating api_key failed --- metagpt/configs/llm_config.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/metagpt/configs/llm_config.py b/metagpt/configs/llm_config.py index 12bb8541e..469613dc1 100644 --- a/metagpt/configs/llm_config.py +++ b/metagpt/configs/llm_config.py @@ -12,7 +12,7 @@ from pydantic import field_validator from metagpt.const import LLM_API_TIMEOUT from metagpt.utils.yaml_model import YamlModel - +from metagpt.const import METAGPT_ROOT, CONFIG_ROOT class LLMType(Enum): OPENAI = "openai" @@ -94,7 +94,15 @@ class LLMConfig(YamlModel): @classmethod def check_llm_key(cls, v): if v in ["", None, "YOUR_API_KEY"]: - raise ValueError("Please set your API key in config2.yaml") + repo_config_path=(METAGPT_ROOT / "config/config2.yaml") + root_config_path=(CONFIG_ROOT / "config2.yaml") + if root_config_path.exists(): + raise ValueError( + f"Please set your API key in {root_config_path}. If you also set your config in {repo_config_path}, \nthe former will overwrite the latter. This may cause unexpected result.\n") + elif repo_config_path.exists(): + raise ValueError(f"Please set your API key in {repo_config_path}") + else: + raise ValueError(f"Please set your API key in config2.yaml") return v @field_validator("timeout") From 76b009513a4458a5a7246afd2627f2c65e5df3f0 Mon Sep 17 00:00:00 2001 From: usamimeri_renko <93753250+usamimeri@users.noreply.github.com> Date: Sat, 22 Jun 2024 14:57:47 +0800 Subject: [PATCH 2/2] Update llm_config.py --- metagpt/configs/llm_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/metagpt/configs/llm_config.py b/metagpt/configs/llm_config.py index 469613dc1..0284c8993 100644 --- a/metagpt/configs/llm_config.py +++ b/metagpt/configs/llm_config.py @@ -94,8 +94,8 @@ class LLMConfig(YamlModel): @classmethod def check_llm_key(cls, v): if v in ["", None, "YOUR_API_KEY"]: - repo_config_path=(METAGPT_ROOT / "config/config2.yaml") - root_config_path=(CONFIG_ROOT / "config2.yaml") + repo_config_path = METAGPT_ROOT / "config/config2.yaml" + root_config_path = CONFIG_ROOT / "config2.yaml" if root_config_path.exists(): raise ValueError( f"Please set your API key in {root_config_path}. If you also set your config in {repo_config_path}, \nthe former will overwrite the latter. This may cause unexpected result.\n")