SmartBaseAI is an open-source starter kit for building multi-tenant chat applications. It includes a FastAPI backend, simple Next.js frontends and a collection of scripts for managing tenants and embeddings.
Before running the API create a .env file in the project root. You can start by copying the provided example:
cp .env.example .envEdit the file and set SECRET_KEY to a secure value that will be used for signing JWT tokens. Any variables defined in .env are read by the backend on startup.
Install Python dependencies and run the API server:
pip install -r requirements.txt
python scripts/run_server.py --reloadThe server listens on port 8000 by default.
Two Next.js applications are provided. Each must be started separately.
cd ui/web
npm install
npm run devcd ui/admin_panel
npm install
npm run devStart the API server and a frontend to use SmartBaseAI in the browser.
# terminal 1: backend
python scripts/run_server.py --reload
# terminal 2: chat interface
cd ui/web
npm install
npm run devThe chat interface is available at http://localhost:3000. To manage tenants, run the admin panel in another terminal:
cd ui/admin_panel
npm install
npm run dev -- -p 3001Visit http://localhost:3001 for administrative tasks.
python scripts/setup_tenant.py tenant1 --name "Tenant 1" --db-type postgres \
--db-config '{"host": "localhost", "user": "app"}'
--model-type ollama --model-name llama3python scripts/build_embeddings.py --source docs/ --output embeddings.json \
--embedder localcurl -X POST -H "Content-Type: application/json" \
-d '{"username": "admin", "password": "ChangeThis123!"}' \
http://localhost:8000/auth/loginUse the access_token returned above when calling other endpoints.
curl -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-X POST http://localhost:8000/chat/message \
-d '{"session_id": "s1", "tenant_id": "t1", "message": "hello"}'# list tenants
curl -H "Authorization: Bearer <token>" http://localhost:8000/admin/tenants
# get configuration for a tenant
curl -H "Authorization: Bearer <token>" http://localhost:8000/admin/tenants/t1Install the Python dependencies before running the test suite:
pip install -r requirements.txtRun all unit tests with:
pytest -qThe ResponseGenerator combines conversation history, structured data from a
tenant database and unstructured context from the vector store. Additional data
sources can be integrated by implementing new helper methods that fetch and
format their results before calling the language model. Each source should be
encapsulated in its own method and added to the prompt in
chatbot/response_generator.py.
Contributions are welcome! Please fork the repository and open a pull request
for any enhancements or bug fixes. For large changes, open an issue first to
discuss the proposed work. Make sure to run the test suite with pytest -q
before submitting a PR.
This project is licensed under the MIT License.
