# FastAPI RAG Chatbot

This is a FastAPI MVC project for a RAG (Retrieval-Augmented Generation) chatbot. It uses Pinecone as a vector database and OpenAI for embeddings and text generation via LangChain.

## Project Structure

```
.
├── app
│   ├── api
│   │   └── routes      # API endpoints (Controllers)
│   ├── core            # Configuration and settings
│   ├── models          # Pydantic models (Data validation)
│   └── services        # Business logic (Pinecone, LLM, RAG)
├── .env.example        # Environment variables example
├── main.py             # FastAPI application entry point
└── requirements.txt    # Project dependencies
```

## Setup

### 1) Install Python

On Ubuntu/Debian:
```bash
sudo apt-get update
sudo apt-get install -y python3 python3-pip python3-venv
```

### 2) Install Conda (Miniconda)

Download and install Miniconda for your OS, then initialize it for your shell:
```bash
# Example (adjust path/filename if needed)
bash ~/Downloads/Miniconda3-latest-Linux-x86_64.sh

# After installation, run:
~/miniconda3/bin/conda init
```

Close and reopen the terminal after `conda init`.

### 3) Create and activate the `pms-bot` environment

```bash
conda create -n pms-bot python=3.11 -y
conda activate pms-bot
```

### 4) Install dependencies

```bash
pip install -r requirements.txt
```

### 5) Configure environment variables

Copy `.env.example` to `.env` and fill in your API keys and configuration.
```bash
cp .env.example .env
```

### 6) Create `output.log` and start the server

From the project root:
```bash
touch output.log
chmod 666 output.log
make nohup
```

To stop:
```bash
make stop
```

## Endpoints

- `POST /chat`: Main chatbot endpoint. Expects a JSON payload like `{"query": "Hello"}`.
- `GET /health`: API health check.
- `GET /docs`: Swagger UI API documentation.
