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