34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from fastapi import Depends
|
|
from app.config import get_config
|
|
from app.services.file_service import FileService
|
|
from app.services.faiss_service import FAISSService
|
|
|
|
|
|
|
|
def get_file_service(config=Depends(get_config)) -> FileService:
|
|
"""
|
|
Dependency function to provide a FileService instance.
|
|
|
|
:param config: Configuration object obtained via dependency injection.
|
|
:return: An instance of FileService initialized with the PDF folder path.
|
|
"""
|
|
if not hasattr(config, "PDF_FOLDER") or not config.PDF_FOLDER:
|
|
raise ValueError("PDF_FOLDER is not configured in the application settings.")
|
|
return FileService(folder_path=config.PDF_FOLDER)
|
|
|
|
|
|
def get_faiss_service(file_service=Depends(get_file_service)) -> FAISSService:
|
|
"""
|
|
Dependency function to provide a FAISSService instance.
|
|
|
|
:param config: Configuration object obtained via dependency injection.
|
|
:param file_service: FileService instance for handling PDFs and documents.
|
|
:return: An instance of FAISSService initialized with vectorstore and embeddings.
|
|
"""
|
|
config = get_config()
|
|
|
|
return FAISSService(
|
|
openai_api_key=config.OPENAI_API_KEY,
|
|
index_path="local_faiss_index",
|
|
)
|