diff --git a/chatbot/infrastructura.md b/chatbot/infrastructura.md new file mode 100644 index 0000000..bd4c7eb --- /dev/null +++ b/chatbot/infrastructura.md @@ -0,0 +1,141 @@ +# Infrastructura Chatbot Maria + +## Componente + +| Componenta | Locație | IP | Port | +|------------|---------|-----|------| +| Flowise | LXC 104 | 10.0.20.161 | 3000 | +| ngrok tunnel | LXC 104 | 10.0.20.161 | - | +| Pagina chatbot | romfast.ro | - | 443 | + +## Configurare Flowise + +**Serviciu systemd**: `/etc/systemd/system/flowise.service` + +```ini +[Unit] +Description=Flowise Service +After=network.target + +[Service] +User=root +Group=root +ExecStart=/usr/bin/npx flowise start +Restart=always +Environment=PORT=3000 +Environment=FLOWISE_USERNAME=admin +Environment=FLOWISE_PASSWORD=parola28 +Environment=CORS_ORIGINS=https://www.romfast.ro,https://romfast.ro +WorkingDirectory=/root/.flowise +Environment=FLOWISE_DATABASE_PATH=/root/.flowise/database.sqlite + +[Install] +WantedBy=multi-user.target +``` + +**Comenzi utile**: +```bash +# Status +pct exec 104 -- systemctl status flowise + +# Restart +pct exec 104 -- systemctl restart flowise + +# Logs +pct exec 104 -- journalctl -u flowise -f +``` + +## Configurare ngrok + +**Configurare**: `/root/.config/ngrok/ngrok.yml` + +```yaml +version: "2" +authtoken: 2mo9quiDc23B6U3TtTqWJEleEfM_jYeD1KYe9u7njaaQMZg2 +tunnels: + web: + proto: http + addr: http://10.0.20.161:3000 + domain: mutual-special-koala.ngrok-free.app +``` + +**Serviciu systemd**: `/etc/systemd/system/ngrok.service` + +**URL public**: https://mutual-special-koala.ngrok-free.app + +**API endpoint chatbot**: +``` +POST https://mutual-special-koala.ngrok-free.app/api/v1/prediction/d4911620-07fe-41f8-adb4-f2f52d6ec766 +``` + +**Comenzi utile**: +```bash +# Status +pct exec 104 -- systemctl status ngrok + +# Restart +pct exec 104 -- systemctl restart ngrok + +# Verificare tunel activ +pct exec 104 -- curl -s http://localhost:4040/api/tunnels + +# Verificare versiune +pct exec 104 -- /usr/local/bin/ngrok --version + +# Actualizare ngrok +pct exec 104 -- /usr/local/bin/ngrok update +``` + +## Troubleshooting + +### Eroare CORS +**Simptom**: Browser-ul afișează eroare CORS când se încarcă chatbot-ul. + +**Cauza**: Flowise nu are configurată variabila `CORS_ORIGINS`. + +**Soluție**: Adaugă în `/etc/systemd/system/flowise.service`: +``` +Environment=CORS_ORIGINS=https://www.romfast.ro,https://romfast.ro +``` +Apoi: `systemctl daemon-reload && systemctl restart flowise` + +### Eroare ngrok versiune veche (ERR_NGROK_121) +**Simptom**: În logs apare: +``` +Your ngrok-agent version "3.16.0" is too old. The minimum supported agent version is "3.19.0" +``` + +**Cauza**: ngrok a fost actualizat dar serviciul nu a fost restartat. Procesul vechi continuă să ruleze. + +**Soluție**: +```bash +# Actualizare (dacă nu e deja făcută) +pct exec 104 -- /usr/local/bin/ngrok update + +# IMPORTANT: Restart după actualizare +pct exec 104 -- systemctl restart ngrok +``` + +### Verificare rapidă că totul funcționează +```bash +# Test local Flowise +pct exec 104 -- curl -s http://localhost:3000/ | head -5 + +# Test tunel ngrok +curl -s "https://mutual-special-koala.ngrok-free.app/api/v1/prediction/d4911620-07fe-41f8-adb4-f2f52d6ec766" \ + -X POST -H "Content-Type: application/json" \ + -d '{"question":"test"}' +``` + +## Pagina web + +URL: https://www.romfast.ro/chatbot_maria.html + +Pagina încarcă widget-ul Flowise care se conectează la endpoint-ul ngrok. + +## Istoric incidente + +### 2025-12-30: Chatbot nu funcționa (CORS + ngrok versiune) +- **Problemă 1**: Flowise nu avea CORS configurat +- **Problemă 2**: ngrok rula versiunea 3.16.0 (actualizată dar nerestartat din octombrie) +- **Soluție**: Adăugat CORS_ORIGINS și restart la ambele servicii