From fd6f41fa7eb48ea572178890c6703e3046f62462 Mon Sep 17 00:00:00 2001 From: harshalmore31 <86048671+harshalmore31@users.noreply.github.com> Date: Tue, 31 Dec 2024 21:27:41 +0530 Subject: [PATCH] fix: ensure .env file is created if not found when saving API key --- swarms/structs/ui/ui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/swarms/structs/ui/ui.py b/swarms/structs/ui/ui.py index bc9f0cc0..8367274f 100644 --- a/swarms/structs/ui/ui.py +++ b/swarms/structs/ui/ui.py @@ -1636,6 +1636,10 @@ def create_app(): # Save API key to .env env_path = find_dotenv() + if not env_path: + env_path = os.path.join(os.getcwd(), ".env") + with open(env_path, "w") as f: + f.write("") if provider == "openai": set_key(env_path, "OPENAI_API_KEY", api_key) elif provider == "anthropic":