This is the backend for the dJetLawyer ChatBot, a sophisticated AI-powered legal assistant.
- Clone the repository
- Create a virtual environment:
python3.10 -m venv ChatBotBackend - Activate the virtual environment:
- On Windows:
venv\Scripts\activate - On macOS and Linux:
source ChatBotBackend/bin/activate
- On Windows:
- Install dependencies:
pip install -r requirements.txt - Copy
.env.exampleto.envand fill in the required environment variables - Set up the database:
- Create a PostgreSQL database
- Update the
DATABASE_URLin.envwith your database credentials
- Run database migrations:
alembic upgrade head - Start the server:
uvicorn main:app --reload
The system supports sharing chat conversations publicly:
- Authenticated users can share their chats with a public link
- Anonymous users can also share their chats, which will be saved from Redis to the permanent database
- Shared chats are accessible to anyone with the link without requiring authentication
- Shared chats maintain all original messages and source references
- Users can continue the conversation from a shared chat
- The system creates a separate copy of the shared chat for each user who continues it
- For anonymous users, the conversation history is stored in Redis with the regular usage limits
- For authenticated users, a new chat is created in their account with the shared chat's history
- API supports passing previous messages as context when creating a new chat
To share a chat:
- API endpoint:
POST /api/v1/chat/chats/{chat_id}/share(for authenticated users) - API endpoint:
POST /api/v1/chatbot/share-anonymous-chat(for anonymous users)
To view a shared chat:
- API endpoint:
GET /api/v1/chat/shared/{chat_id}
To continue a shared chat:
- API endpoint:
POST /api/v1/chatbot/chatwith theprevious_messagesparameter
Once the server is running, you can access the API documentation at http://localhost:8000/docs.
To run tests, use the command: ./run_tests.sh
For production deployment, consider the following:
- Use a production WSGI server like Gunicorn
- Set up HTTPS
- Use environment variables for all sensitive information
- Set up proper logging
- Configure a production-ready database
- Set up monitoring and error tracking