2.8 KiB
2.8 KiB
Fix Chat Assistant 500 Error
Issue
Getting 500 Internal Server Error when calling /api/v1/chat endpoint.
Root Causes
-
Model Name Mismatch ✅ FIXED
- Code was using
gemma3:27bbut entrypoint pullsgemma3:270M - Fixed: Updated code to use
gemma3:270M
- Code was using
-
Ollama Not Running
- Ollama service might not be started in the container
- Network connectivity issues
-
Model Not Available
- Model might not be pulled yet
- Model name incorrect
Solutions
Solution 1: Restart the Container
# Stop and restart the backend container
docker-compose down
docker-compose up -d be0
# Wait for Ollama to start (check logs)
docker-compose logs -f be0
Solution 2: Check Ollama Status
# Check if container is running
docker ps | grep be0
# Check Ollama inside container
docker exec be0 ollama list
# If Ollama is not running, start it
docker exec be0 ollama serve &
Solution 3: Pull the Model
# Pull the required model
docker exec be0 ollama pull gemma3:270M
# Verify it's available
docker exec be0 ollama list | grep gemma3
Solution 4: Test the Health Endpoint
# Check health endpoint (includes Ollama status)
curl http://localhost:4402/health
# Should show:
# {
# "status": "healthy",
# "ollama": {
# "status": "connected",
# "available_models": ["gemma3:270M", ...]
# }
# }
Solution 5: Check Backend Logs
# View recent logs
docker-compose logs be0 | tail -50
# View ChatAssistant specific logs
tail -f be0/logs/ChatAssistant.log
Quick Fix Commands
# 1. Restart everything
docker-compose restart be0
# 2. Check Ollama
docker exec be0 ollama list
# 3. Test health
curl http://localhost:4402/health
# 4. Test chat endpoint
curl -X POST http://localhost:4402/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message": "Hello"}'
What Was Fixed
- ✅ Model name changed from
gemma3:27btogemma3:270M - ✅ Added better error handling with specific error messages
- ✅ Added Ollama connection check on initialization
- ✅ Added health endpoint with Ollama status
- ✅ Improved logging for debugging
Expected Behavior After Fix
- Container starts and Ollama service runs
- Model
gemma3:270Mis available - Health endpoint shows Ollama as "connected"
- Chat endpoint returns 200 with AI response
If Still Not Working
-
Check container logs:
docker-compose logs be0 -
Check if Ollama is accessible:
docker exec be0 curl http://localhost:11434/api/tags -
Manually start Ollama:
docker exec -d be0 ollama serve sleep 2 docker exec be0 ollama list -
Rebuild container:
docker-compose down docker-compose build be0 docker-compose up be0