This document provides instructions on setting up and using the FastAPI-based API endpoints for processing CSV files and performing question answering.
The raw data is sourced from the text_segments.csv
file, containing information about document segments including pagenum
, docname
, and text
.
- Text Aggregation: Combine text segments from the same page of the same document to enhance document coherency.
- JSON Serialization: Serialize aggregated text segments into JSON files, one for each unique document, to preserve metadata.
- Consistency in Document Processing: Ensuring uniformity in document structure to facilitate effective embedding for question-answering.
- Document File Format Selection: Choosing between file formats; JSON was selected for metadata retention.
-
Custom Prompts for QA: Enhance question-answering with custom prompts for more polite and nuanced responses.
-
Guardrails Implementation: Strengthen input validation and error handling mechanisms.
-
Chat History Integration: Enable continuous conversations by adding support for chat history.
-
User-Specific Document Support: Allow users to upload and analyze their own documents.
app/
: Contains the FastAPI application code.data/
: Holds processed data, including serialized JSON files.
-
Python Environment:
- Ensure you have Python installed on your system. You can download Python from python.org.
-
Virtual Environment:
- Create a virtual environment to isolate dependencies.
python -m venv venv
- Create a virtual environment to isolate dependencies.
-
Activate Virtual Environment:
- Activate the virtual environment.
- On Windows:
.\venv\Scripts\activate
- On Unix or MacOS:
source venv/bin/activate
- On Windows:
- Activate the virtual environment.
-
Install Requirements:
- Install the required Python packages.
pip install -r requirements.txt
- Install the required Python packages.
-
Create .env file:
- Create a
.env
file in the project root based on the providedenv.example
file. This file should contain any necessary environment variables.
- Create a
-
Run the FastAPI Server:
- Execute the following command to start the FastAPI server.
uvicorn app.main:app --reload
- The
--reload
flag enables automatic reloading of the server when code changes are detected.
- Execute the following command to start the FastAPI server.
-
Access API Documentation:
- Open your browser and go to http://127.0.0.1:8000/docs.
- This will open the FastAPI Swagger UI, providing an interactive interface for exploring and testing the API endpoints.
-
Build and Run Docker Containers:
- Execute the following command to build the Docker image and start the FastAPI server along with any required services defined in the
docker-compose.yml
file.docker-compose up --build -d
- The
--build
flag ensures that the Docker images are rebuilt, and the-d
flag runs the services in the background.
- Execute the following command to build the Docker image and start the FastAPI server along with any required services defined in the
-
Access API Documentation:
- Open your browser and go to http://127.0.0.1:8000/docs.
- This will open the FastAPI Swagger UI, providing an interactive interface for exploring and testing the API endpoints.
-
Stopping Docker Compose:
- To stop the running containers, use the following command:
docker-compose down
- This will stop and remove the containers defined in the
docker-compose.yml
file.
- To stop the running containers, use the following command:
- Endpoint:
/process_csv
- Method:
POST
- Request Payload:
- Upload a CSV file using the provided form.
- Response:
- Successful response:
{"message": "File processed and stored"}
- In case of an error, an appropriate error message will be returned.
- Successful response:
- Endpoint:
/qa
- Method:
POST
- Request Payload:
- Provide a JSON object with the question using the key
query
.{ "query": "Your question goes here" }
- Provide a JSON object with the question using the key
- Response:
- Successful response:
{"response": "Answer to the question"}
- In case of an error, an appropriate error message will be returned.
- Successful response:
- Please refer to frontend_readme.md for frontend setup.