Skip to content

Commit 193db86

Browse files
committed
Take api_key by default from the environment variable
1 parent 6cd26af commit 193db86

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/generalagents/agent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import os
23
from io import BytesIO
34

45
import cattrs
@@ -54,11 +55,17 @@ class Agent:
5455
def __init__(
5556
self,
5657
model: str,
57-
api_key: str,
58+
api_key: str = os.getenv("GENERALAGENTS_API_KEY", ""),
5859
temperature: float = 0.3,
5960
max_previous_actions: int = 20,
6061
):
6162
""""""
63+
if not api_key:
64+
msg = (
65+
"No API key provided, please set an environment variable "
66+
"GENERALAGENTS_API_KEY or provide it to the Agent constructor"
67+
)
68+
raise ValueError(msg)
6269
self.model = model
6370
self.api_key = api_key
6471
self.temperature = temperature

0 commit comments

Comments
 (0)