From 9935d9e8d379e3fd035a21afc1cc3d5fadfdfbc9 Mon Sep 17 00:00:00 2001 From: Ruben Lucas Date: Thu, 17 Apr 2025 13:06:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Change=20config=20file=20location?= =?UTF-8?q?=20using=20argument=20parser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generic_rag/app.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/generic_rag/app.py b/generic_rag/app.py index d682d1a..d1383b7 100644 --- a/generic_rag/app.py +++ b/generic_rag/app.py @@ -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)