diff --git a/app/frontend/ui.py b/app/frontend/ui.py index 84043a5..dc80376 100644 --- a/app/frontend/ui.py +++ b/app/frontend/ui.py @@ -4,13 +4,23 @@ import uuid import os import json from datetime import datetime +from dotenv import load_dotenv # --- CONFIGURATION --- -# Default configuration taken from environment or fallback to localhost +# Load .env file explicitly to get timeouts and URLs +load_dotenv() + API_BASE_URL = os.getenv("MINDNET_API_URL", "http://localhost:8002") CHAT_ENDPOINT = f"{API_BASE_URL}/chat" FEEDBACK_ENDPOINT = f"{API_BASE_URL}/feedback" +# Timeout strategy: +# 1. Try MINDNET_API_TIMEOUT (specific for frontend) +# 2. Try MINDNET_LLM_TIMEOUT (backend setting) +# 3. Default to 300 seconds (5 minutes) for local inference safety +timeout_setting = os.getenv("MINDNET_API_TIMEOUT") or os.getenv("MINDNET_LLM_TIMEOUT") +API_TIMEOUT = float(timeout_setting) if timeout_setting else 300.0 + # --- PAGE SETUP --- st.set_page_config( page_title="mindnet v2.3.1", @@ -57,11 +67,14 @@ def send_chat_message(message: str, top_k: int, explain: bool): "explain": explain } try: - response = requests.post(CHAT_ENDPOINT, json=payload, timeout=60) + # Use the configured timeout from .env + response = requests.post(CHAT_ENDPOINT, json=payload, timeout=API_TIMEOUT) response.raise_for_status() return response.json() + except requests.exceptions.ReadTimeout: + return {"error": f"Timeout: Das Backend hat nicht innerhalb von {int(API_TIMEOUT)} Sekunden geantwortet. (Local LLM is busy)."} except requests.exceptions.ConnectionError: - return {"error": "Backend nicht erreichbar. Läuft der Server auf Port 8002?"} + return {"error": f"Backend nicht erreichbar unter {API_BASE_URL}. Läuft der Server?"} except Exception as e: return {"error": str(e)} @@ -87,6 +100,7 @@ def render_sidebar(): with st.sidebar: st.header("⚙️ Konfiguration") st.markdown(f"**Backend:** `{API_BASE_URL}`") + st.caption(f"⏱️ Timeout: {int(API_TIMEOUT)}s") st.markdown("---") st.subheader("Retrieval Settings") @@ -170,9 +184,6 @@ for msg in st.session_state.messages: # Render Latency info if "latency_ms" in msg: st.caption(f"⏱️ Antwortzeit: {msg['latency_ms']}ms | Query-ID: `{msg.get('query_id')}`") - - # Render Feedback Controls (Static for history items to prevent re-run issues) - # (Note: In a prod app, we would check if feedback was already given) else: st.markdown(msg["content"]) @@ -187,7 +198,6 @@ if prompt := st.chat_input("Was beschäftigt dich?"): # Generate Response with st.chat_message("assistant"): message_placeholder = st.empty() - # Placeholder for intent badge status_placeholder = st.empty() with st.spinner("Thinking... (Decision Engine Active)"): @@ -216,7 +226,7 @@ if prompt := st.chat_input("Was beschäftigt dich?"): # 4. Show Latency & Feedback UI st.caption(f"⏱️ {latency}ms | ID: `{query_id}`") - # Feedback Buttons (Directly here for the *new* message) + # Feedback Buttons col1, col2, col3, col4 = st.columns([1,1,1,4]) with col1: if st.button("👍", key=f"up_{query_id}"):