-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
49 lines (39 loc) · 1.38 KB
/
settings.py
File metadata and controls
49 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# coding=utf-8
import os
import sys
from os.path import abspath, dirname
from inspect import stack
import logging
__author__ = "Adam Kruger"
sys.dont_write_bytecode = True
path_app = dirname(abspath(stack()[0][1]))
if path_app not in sys.path:
sys.path.append(path_app)
path_source = os.path.dirname(os.path.abspath(__file__))
def load_env_file(filepath):
print(f"Loading environment from {filepath}...")
try:
with open(filepath) as f:
for line in f:
if line.strip() and not line.startswith("#"):
key, value = line.strip().split("=", 1)
os.environ[key] = value
print("Environment loaded successfully")
except FileNotFoundError:
print(
f"Environment file {filepath} not found. Checking system environment variables."
)
logging.warning(
f"Environment file {filepath} not found. Checking system environment variables."
)
except Exception as e:
print(f"Error loading environment file: {e}")
logging.error(f"Error loading environment file: {e}")
# Load environment variables from .env file
load_env_file(".env")
# Configure OpenAI
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
raise ValueError(
"OPENAI_API_KEY environment variable is not set. Please set it in .env file or system environment."
)