Skip to content
tanvirahmodrafiPublic

About

An Ai Chatbot for Business.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Installation and Setup Guide for RAG FastAPI Application

Installation

  1. Install FastAPI dependencies:
pip install fastapi uvicorn python-multipart
  1. Or install all requirements:
pip install -r requirements.txt

Running the Application

Development Mode

python app.py

Production Mode

uvicorn app:app --host 0.0.0.0 --port 8000 --reload

API Endpoints

1. Root Endpoint

  • GET /
  • Returns API information and available endpoints

2. Upload PDF

  • POST /upload-pdf/
  • Upload and process a PDF file
  • Body: Form data with file upload

3. Add URL

  • POST /add-url/
  • Add and process a web URL
  • Body: {"url": "https://example.com"}

4. Ask Question

  • POST /ask/
  • Ask a question based on processed documents
  • Body: {"question": "Your question here"}

5. Get Conversations

  • GET /conversations/
  • Retrieve all conversation history

6. Get Documents

  • GET /documents/
  • Retrieve all processed documents

7. Health Check

  • GET /health/
  • Check if the service is running

Example Usage

Using curl:

# Upload a PDF
curl -X POST "http://localhost:8000/upload-pdf/" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@sample.pdf"

# Add a URL
curl -X POST "http://localhost:8000/add-url/" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com"}'

# Ask a question
curl -X POST "http://localhost:8000/ask/" \
  -H "Content-Type: application/json" \
  -d '{"question": "What is this document about?"}'

# Get conversations
curl -X GET "http://localhost:8000/conversations/"

Using Python requests:

import requests

# Upload PDF
with open("sample.pdf", "rb") as f:
    response = requests.post(
        "http://localhost:8000/upload-pdf/",
        files={"file": f}
    )

# Add URL
response = requests.post(
    "http://localhost:8000/add-url/",
    json={"url": "https://example.com"}
)

# Ask question
response = requests.post(
    "http://localhost:8000/ask/",
    json={"question": "What is this document about?"}
)

Interactive API Documentation

Once the server is running, visit:

Database

Currently using a simple JSON file-based database (simple_db.json). You can replace this with PostgreSQL, MongoDB, or any other database later.

Environment Variables

Make sure your .env file contains:

OPENAI_API_KEY=your_openai_api_key
PINECONE_API_KEY=your_pinecone_api_key

Deployment

Using Docker (optional):

  1. Create Dockerfile:
FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
  1. Build and run:
docker build -t rag-api .
docker run -p 8000:8000 rag-api

About

An Ai Chatbot for Business.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages