Skip to content

Commit 0948f16

Browse files
committed
docs: add Streaming API & Fallback section, usage, troubleshooting
1 parent f24cbc1 commit 0948f16

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,59 @@ ollama serve &
8282

8383
---
8484

85+
## 🌐 Streaming API & Fallback
86+
87+
BasicChat supports real-time streaming chat via a FastAPI backend, with robust fallback to local inference for maximum reliability and privacy.
88+
89+
### 🔌 Enabling Streaming API
90+
- By default, the app uses the streaming API backend for chat.
91+
- Control this with the `USE_API` environment variable:
92+
- `USE_API=true` (default): Use the API backend (WebSocket streaming, REST fallback)
93+
- `USE_API=false`: Use local Ollama inference only (no API required)
94+
- Set this in your `.env.local` file:
95+
```env
96+
USE_API=true
97+
API_BASE_URL=http://localhost:8080
98+
OLLAMA_API_URL=http://localhost:11434/api
99+
OLLAMA_MODEL=mistral
100+
```
101+
102+
### 🚀 Starting the Streaming Backend
103+
1. **Start the API backend:**
104+
```sh
105+
./backend/start.sh &
106+
```
107+
2. **Start the Streamlit app:**
108+
```sh
109+
./start_basicchat.sh &
110+
```
111+
3. **Run E2E tests:**
112+
```sh
113+
bunx playwright test tests/e2e/specs/basic-e2e.spec.ts --project=chromium --headed
114+
```
115+
116+
### 🔄 How Fallback Works
117+
- If the API backend is unavailable or `USE_API=false`, BasicChat automatically falls back to local Ollama inference.
118+
- WebSocket streaming is preferred; if it fails, REST API is used; if both fail, local inference is used.
119+
- This ensures chat always works, even if the backend is down or misconfigured.
120+
121+
### 🩺 Health Checks & Troubleshooting
122+
- **Check API health:**
123+
```sh
124+
curl http://localhost:8080/health
125+
```
126+
- **Run all service health checks before E2E:**
127+
```sh
128+
poetry run python scripts/e2e_health_check.py
129+
```
130+
- **If chat is not streaming:**
131+
- Ensure the backend is running on port 8080
132+
- Check `.env.local` for correct `USE_API` and `API_BASE_URL`
133+
- Review logs in `app.log` and backend console for errors
134+
- Try setting `USE_API=false` to use local inference as a workaround
135+
136+
---
137+
85138
## 🏆 Best Practices & Pro Tips
86139

87140
<div style="background:#e3f2fd; padding:1em; border-radius:8px; border-left:5px solid #1976d2;">

0 commit comments

Comments
 (0)