Change config file location using argument parser

This commit is contained in:
Ruben Lucas 2025-04-17 13:06:27 +02:00
parent a58ef2f365
commit 9935d9e8d3

View File

@ -1,3 +1,4 @@
import argparse
import json
import logging
import os
@ -17,6 +18,8 @@ from generic_rag.parsers.parser import add_pdf_files, add_urls
logger = logging.getLogger("sogeti-rag")
logger.setLevel(logging.DEBUG)
PROJECT_ROOT = Path(__file__).resolve().parent.parent
system_prompt = (
"You are an assistant for question-answering tasks. "
"If the question is in Dutch, answer in Dutch. If the question is in English, answer in English."
@ -24,13 +27,21 @@ system_prompt = (
"If you don't know the answer, say that you don't know."
)
PROJECT_ROOT = Path(__file__).resolve().parent.parent
CONFIG_FILE_PATH = PROJECT_ROOT / "config.yaml"
parser = argparse.ArgumentParser(description="A Sogeti Netherlands Generic RAG demo.")
parser.add_argument(
"-c",
"--config",
type=Path,
default=PROJECT_ROOT / "config.yaml",
help="Path to configuration file (YAML format). Defaults to 'config.yaml' in project root.",
)
args = parser.parse_args()
try:
settings: AppSettings = load_settings(CONFIG_FILE_PATH)
settings: AppSettings = load_settings(args.config)
except (FileNotFoundError, Exception) as e:
logger.error(f"Failed to load configuration from {CONFIG_FILE_PATH}. Exiting.")
logger.error(f"Failed to load configuration from {args.config}. Exiting.")
sys.exit(1)
embedding_function = get_embedding_model(settings)