aishayousuf/humanoid-robotics-api
0
Humanoid Robotics Book RAG Chatbot API
This is the backend API for the Humanoid Robotics Book RAG chatbot, built with FastAPI.
Features
- RAG (Retrieval-Augmented Generation) for contextual responses
- Gemini API (primary) with OpenAI API fallback
- Qdrant vector database for semantic search
- PostgreSQL database for chat history
- Rate limiting and streaming responses
API Endpoints
GET /api/v1/health- Health check endpointPOST /api/v1/chat/query- Chat query endpointGET /api/v1/docs- Interactive API documentationGET /api/v1/redoc- ReDoc API documentation
Environment Variables
Create a .env file with the following variables:
# Database
DATABASE_URL=postgresql://user:password@host/database
# Vector Database
QDRANT_URL=https://your-cluster.qdrant.io
QDRANT_API_KEY=your_qdrant_api_key
QDRANT_COLLECTION_GEMINI=humanoid-robotics-gemini
QDRANT_COLLECTION_OPENAI=humanoid-robotic-book
# LLM Provider
LLM_PROVIDER=gemini
ENABLE_FALLBACK=true
# Gemini API
GEMINI_API_KEY=your_gemini_api_key
GEMINI_EMBEDDING_MODEL=models/text-embedding-004
GEMINI_CHAT_MODEL=gemini-2.5-flash
# OpenAI API (Fallback)
OPENAI_API_KEY=your_openai_api_key
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
OPENAI_CHAT_MODEL=gpt-4o-miniLocal Development
Install Dependencies
pip install -r requirements.txtRun Server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000Visit http://localhost:8000/api/v1/docs for interactive API documentation.
Docker Deployment
Build Image
docker build -t humanoid-robotics-api .Run Container
docker run -p 7860:7860 --env-file .env humanoid-robotics-apiHugging Face Spaces Deployment
This API is configured for deployment on Hugging Face Spaces with Docker runtime.
Steps:
- Create a new Space on Hugging Face (https://huggingface.co/spaces)
- Select "Docker" as the Space SDK
- Clone this repository or upload the
backendfolder - Add environment variables in Space Settings → Repository secrets
- The Space will automatically build and deploy
Required Secrets:
Add these in your Hugging Face Space settings:
DATABASE_URLQDRANT_URLQDRANT_API_KEYGEMINI_API_KEYOPENAI_API_KEY
License
CC-BY-NC-SA-4.0
