Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

fix: Able to use env before loading config utils

Clémence Lesné470db802ecde
diff --git a/helpers/__init__.py b/helpers/__init__.py
index e69de29..ba2b052 100644
--- a/helpers/__init__.py
+++ b/helpers/__init__.py
@@ -0,0 +1,13 @@
+from dotenv import find_dotenv, load_dotenv
+
+
+def init_env():
+ path = find_dotenv()
+ if not path:
+ print("Env file not found")
+ return
+ load_dotenv(path)
+ print(f'Env file loaded from "{path}"')
+
+
+init_env()
diff --git a/helpers/config.py b/helpers/config.py
index 05e0620..98a2bd9 100644
--- a/helpers/config.py
+++ b/helpers/config.py
@@ -2,7 +2,7 @@ from os import environ
from typing import Optional
import yaml
-from dotenv import find_dotenv, load_dotenv
+from dotenv import find_dotenv
from pydantic import ValidationError
from helpers.config_models.root import RootModel
@@ -16,15 +16,6 @@ class ConfigBadFormat(Exception):
pass
-def init_env():
- path = find_dotenv()
- if not path:
- print("Env file not found")
- return
- load_dotenv(path)
- print(f'Env file loaded from "{path}"')
-
-
def load_config() -> RootModel:
config: Optional[RootModel] = None
config_env = "CONFIG_JSON"
@@ -42,7 +33,7 @@ def load_config() -> RootModel:
try:
with open(path, encoding="utf-8") as f:
config = RootModel.model_validate(yaml.safe_load(f))
- print(f'Config loaded from "{path}"')
+ print(f'Config loaded from file "{path}"')
return config
except ValidationError as e:
raise ConfigBadFormat("Config values are not valid") from e
@@ -50,5 +41,4 @@ def load_config() -> RootModel:
raise ConfigBadFormat("Config YAML format is not valid") from e
-init_env()
CONFIG = load_config()