Skip to content

Commit

Permalink
Merge pull request geekan#1324 from usamimeri/for_config
Browse files Browse the repository at this point in the history
optimize error message when validating api_key failed
  • Loading branch information
better629 authored Jun 22, 2024
2 parents 116d3e9 + 76b0095 commit 9f8f0a2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions metagpt/configs/llm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 9f8f0a2

Please sign in to comment.