Skip to content

Commit f5ad1ed

Browse files
committed
add key check for model
1 parent c936cc3 commit f5ad1ed

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

agent/agents.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from aider.models import Model
88
from aider.io import InputOutput
99
import re
10+
import os
1011

1112

1213
def handle_logging(logging_name: str, log_file: Path) -> None:
@@ -61,6 +62,22 @@ def __init__(self, max_iteration: int, model_name: str):
6162
super().__init__(max_iteration)
6263
self.model = Model(model_name)
6364

65+
# Check if API key is set for the model
66+
if "gpt" in model_name:
67+
api_key = os.environ.get("OPENAI_API_KEY", None)
68+
elif "claude" in model_name:
69+
api_key = os.environ.get("ANTHROPIC_API_KEY", None)
70+
elif "gemini" in model_name:
71+
api_key = os.environ.get("API_KEY", None)
72+
else:
73+
raise ValueError(f"Unsupported model: {model_name}")
74+
75+
if not api_key:
76+
raise ValueError(
77+
"API Key Error: There is no API key associated with the model for this agent. "
78+
"Edit model_name parameter in .agent.yaml, export API key for that model, and try again."
79+
)
80+
6481
def run(
6582
self,
6683
message: str,

0 commit comments

Comments
 (0)