Skip to content

Latest commit

 

History

History
130 lines (97 loc) · 3.03 KB

File metadata and controls

130 lines (97 loc) · 3.03 KB

Proust Backend

AI-powered chat application backend built with FastAPI and Google Gemini.

🚀 Quick Start

Prerequisites

  • Python 3.9+
  • Google Gemini API key
  • Firebase project with Admin SDK credentials

Installation

  1. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On macOS/Linux
    # or
    venv\Scripts\activate     # On Windows
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up environment variables:

    cp .env.example .env

    Edit .env and add your credentials:

    • GEMINI_API_KEY: Get from Google AI Studio
    • FIREBASE_CREDENTIALS_PATH: Path to your Firebase Admin SDK JSON file
  4. Add Firebase credentials:

    • Go to Firebase Console → Project Settings → Service Accounts
    • Generate new private key
    • Save as firebase-credentials.json in the backend root folder

Running the Server

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

The API will be available at http://localhost:8000

📚 API Documentation

Once the server is running, visit:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

🔌 API Endpoints

Public Endpoints

  • GET / - Root endpoint
  • GET /api/health - Health check
  • GET /api/chat/test - Test chat endpoint

Protected Endpoints (Require Authentication)

  • POST /api/chat/message - Send message to AI

Example Request:

curl -X POST http://localhost:8000/api/chat/message \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_FIREBASE_ID_TOKEN" \
  -d '{"message": "Hello, how are you?"}'

🏗️ Project Structure

backend/
├── app/
│   ├── api/              # API route handlers
│   ├── middleware/       # Authentication middleware
│   ├── models/          # Pydantic schemas
│   ├── services/        # Business logic
│   ├── config.py        # Configuration
│   ├── dependencies.py  # Dependency injection
│   └── main.py         # FastAPI app entry point
├── requirements.txt
├── .env.example
└── README.md

🔐 Authentication

This API uses Firebase Authentication. All protected endpoints require a valid Firebase ID token in the Authorization header:

Authorization: Bearer <firebase_id_token>

🧪 Testing

Test the API without authentication:

curl http://localhost:8000/api/chat/test

📝 Environment Variables

Variable Description Required
GEMINI_API_KEY Google Gemini API key Yes
FIREBASE_CREDENTIALS_PATH Path to Firebase Admin SDK JSON Yes
CORS_ORIGINS Allowed CORS origins (comma-separated) Yes
DEBUG Enable debug mode No

🛠️ Development

Code Style

This project follows PEP 8 guidelines. Format code with:

black app/

Type Checking

mypy app/

📄 License

MIT License