An AI-powered customer support chatbot with REST API.
- Create conda environment and install dependencies:
conda env create -f environment-cpu.yml
conda activate chatbot- Fix PyTorch DLL issue (Windows only):
pip uninstall torch torchvision torchaudio -y
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118- Install API dependencies:
pip install fastapi uvicorn[standard] pydantic python-multipartconda activate chatbot
python scripts/start_api.pyThe server will start at:
- API: http://localhost:8000
- Docs: http://localhost:8000/docs
- Health: http://localhost:8000/health
python scripts/run_chat.pypython scripts/train_model.pyOption 1: Use the built-in test client (Recommended)
# Start API in one terminal
python scripts/start_api.py
# Run test client in another terminal
python test_api_client.pyOption 2: Use Python requests
import requests
# Health check
response = requests.get("http://localhost:8000/health")
print(response.json())
# Multi-turn conversation
session_id = "user123"
# First message
response1 = requests.post(
"http://localhost:8000/chat",
json={"message": "Hi, I'm having trouble logging in", "session_id": session_id}
)
print("Bot:", response1.json()["response"])
# Follow-up (bot remembers the context)
response2 = requests.post(
"http://localhost:8000/chat",
json={"message": "My email is user@example.com", "session_id": session_id}
)
print("Bot:", response2.json()["response"])- Multi-turn Conversations: The API maintains conversation history per
session_id - Automatic Escalation: Detects when human intervention is needed
- Session Management: Each conversation keeps its own context
- Metrics Tracking: Monitor response times, escalation rates, and satisfaction scores
Edit config.py to modify model settings and parameters.
Note: For Windows users, quantization is disabled by default in config.py (USE_4BIT_QUANTIZATION = False). If you need to restart the API after changing config, press Ctrl+C in the terminal running the API server and start it again.