Welcome to the api repository! This repository hosts the core API infrastructure for my web services, built using Python 3.13 and FastAPI. The API is designed to serve essential utilities and functionalities across all my web services, accessible under the domain api.mathislambert.fr.
- FastAPI: A modern, fast (high-performance) web framework for building APIs with Python 3.13 based on standard Python type hints.
- MongoDB: A NoSQL database used for storing application data, offering flexibility and scalability.
- Qdrant: A vector database used for implementing Retrieval-Augmented Generation (RAG) features, enhancing information retrieval capabilities.
- LLM Integration: OpenAI-compatible chat completions proxied to OpenRouter.
- Versioning: A systematic versioning approach with endpoints like
/v1,/v2, etc., to manage API changes and ensure backward compatibility.
- Python 3.13
- MongoDB instance
- Qdrant instance
- OpenRouter API key
-
Clone the Repository:
git clone https://github.com/your-username/api.git self_api cd self_api -
Set Up a Virtual Environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install Dependencies:
pip install -r requirements.txt
-
Configure Environment Variables: Create a
.envfile in the root directory and add the following variables:MONGODB_URI=your_mongodb_connection_string QDRANT_URI=your_qdrant_connection_string OPENROUTER_API_KEY=your_openrouter_api_key OPENROUTER_BASE_URL=https://openrouter.ai/api/v1 OPENROUTER_SITE_URL=https://your-site.example OPENROUTER_APP_NAME=your-app-name
Start the FastAPI server using:
uvicorn main:app --host 0.0.0.0 --port 3001 --reloadThe API will be accessible at http://127.0.0.1:3001.
- Base URL:
https://api.mathislambert.fr - Versioning Structure:
/v1,/v2, etc.
-
Health Check:
GET /v1/health: Check the status of the API.
-
LLM Routes:
POST /v1/chat/completions: OpenAI-compatible chat completions proxied to OpenRouter (metadata-only logging to MongoDB).POST /v1/responses: OpenAI-compatible responses proxied to OpenRouter (metadata-only logging to MongoDB).
-
Data Routes:
GET /v1/data: Retrieve data from MongoDB.POST /v1/data: Insert data into MongoDB.
-
RAG Features:
POST /v1/rag/query: Query the Qdrant database for enhanced information retrieval using RAG.
Contributions are welcome! If you have any ideas, suggestions, or bug reports, please open an issue or submit a pull request. Let's build something amazing together!
This project is licensed under the MIT License. Feel free to explore, modify, and share!
Have questions or want to chat? Feel free to reach out!
- LinkedIn 🔗
Happy coding! 💻✨
