Skip to content

danrixd/smartbaseai

Repository files navigation

SmartBaseAI Logo

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.

Environment setup

Before running the API create a .env file in the project root. You can start by copying the provided example:

cp .env.example .env

Edit 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.

Backend setup

Install Python dependencies and run the API server:

pip install -r requirements.txt
python scripts/run_server.py --reload

The server listens on port 8000 by default.

Frontend setup

Two Next.js applications are provided. Each must be started separately.

Chat interface

cd ui/web
npm install
npm run dev

Admin panel

cd ui/admin_panel
npm install
npm run dev

Run the web app

Start 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 dev

The 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 3001

Visit http://localhost:3001 for administrative tasks.

Utility scripts

Create a tenant

python scripts/setup_tenant.py tenant1 --name "Tenant 1" --db-type postgres \
    --db-config '{"host": "localhost", "user": "app"}'
    --model-type ollama --model-name llama3

Build embeddings

python scripts/build_embeddings.py --source docs/ --output embeddings.json \
    --embedder local

Example API usage

Authenticate

curl -X POST -H "Content-Type: application/json" \
     -d '{"username": "admin", "password": "ChangeThis123!"}' \
     http://localhost:8000/auth/login

Use the access_token returned above when calling other endpoints.

Send a chat message

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"}'

Tenant operations

# 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/t1

Testing

Install the Python dependencies before running the test suite:

pip install -r requirements.txt

Run all unit tests with:

pytest -q

Extending the response generator

The 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.

Contributing

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.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors