This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Deploy financial assistant as a RESTful API
- Loading branch information
1 parent
b94acc8
commit 3a860f1
Showing
14 changed files
with
473 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
model_cache/* | ||
results/* | ||
output/* | ||
logs/* | ||
.ruff_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
import logging.config | ||
import os | ||
import yaml | ||
|
||
from dotenv import load_dotenv, find_dotenv | ||
from pathlib import Path | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def initialize(logging_config_path: str = "logging.yaml", env_file_path: str = ".env"): | ||
logger.info("Initializing logger...") | ||
try: | ||
initialize_logger(config_path=logging_config_path) | ||
except FileNotFoundError: | ||
logger.warning( | ||
f"No logging configuration file found at: {logging_config_path}. Setting logging level to INFO." | ||
) | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
logger.info("Initializing env vars...") | ||
if env_file_path is None: | ||
env_file_path = find_dotenv(raise_error_if_not_found=True, usecwd=False) | ||
|
||
logger.info(f"Loading environment variables from: {env_file_path}") | ||
found_env_file = load_dotenv(env_file_path, verbose=True, override=True) | ||
if found_env_file is False: | ||
raise RuntimeError(f"Could not find environment file at: {env_file_path}") | ||
|
||
|
||
def initialize_logger( | ||
config_path: str = "logging.yaml", logs_dir_name: str = "logs" | ||
) -> logging.Logger: | ||
"""Initialize logger from a YAML config file.""" | ||
|
||
# Create logs directory. | ||
config_path_parent = Path(config_path).parent | ||
logs_dir = config_path_parent / logs_dir_name | ||
logs_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
with open(config_path, "rt") as f: | ||
config = yaml.safe_load(f.read()) | ||
|
||
# Make sure that existing logger will still work. | ||
config["disable_existing_loggers"] = False | ||
|
||
logging.config.dictConfig(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
version: 1 | ||
|
||
formatters: | ||
simple: | ||
format: "%(asctime)s - %(levelname)s - %(message)s" | ||
handlers: | ||
console: | ||
class: logging.StreamHandler | ||
level: DEBUG | ||
formatter: simple | ||
stream: ext://sys.stdout | ||
file_info: | ||
class: logging.FileHandler | ||
formatter: simple | ||
level: INFO | ||
filename: logs/info.log | ||
mode: 'a' | ||
file_error: | ||
class: logging.FileHandler | ||
formatter: simple | ||
level: ERROR | ||
filename: logs/error.log | ||
mode: 'a' | ||
root: | ||
level: INFO | ||
handlers: [console, file_info, file_error] | ||
|
Oops, something went wrong.