Nutzung von .env für Timeout
This commit is contained in:
parent
987e297c07
commit
bbc1e589f5
|
|
@ -4,13 +4,23 @@ import uuid
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
# --- CONFIGURATION ---
|
# --- 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")
|
API_BASE_URL = os.getenv("MINDNET_API_URL", "http://localhost:8002")
|
||||||
CHAT_ENDPOINT = f"{API_BASE_URL}/chat"
|
CHAT_ENDPOINT = f"{API_BASE_URL}/chat"
|
||||||
FEEDBACK_ENDPOINT = f"{API_BASE_URL}/feedback"
|
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 ---
|
# --- PAGE SETUP ---
|
||||||
st.set_page_config(
|
st.set_page_config(
|
||||||
page_title="mindnet v2.3.1",
|
page_title="mindnet v2.3.1",
|
||||||
|
|
@ -57,11 +67,14 @@ def send_chat_message(message: str, top_k: int, explain: bool):
|
||||||
"explain": explain
|
"explain": explain
|
||||||
}
|
}
|
||||||
try:
|
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()
|
response.raise_for_status()
|
||||||
return response.json()
|
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:
|
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:
|
except Exception as e:
|
||||||
return {"error": str(e)}
|
return {"error": str(e)}
|
||||||
|
|
||||||
|
|
@ -87,6 +100,7 @@ def render_sidebar():
|
||||||
with st.sidebar:
|
with st.sidebar:
|
||||||
st.header("⚙️ Konfiguration")
|
st.header("⚙️ Konfiguration")
|
||||||
st.markdown(f"**Backend:** `{API_BASE_URL}`")
|
st.markdown(f"**Backend:** `{API_BASE_URL}`")
|
||||||
|
st.caption(f"⏱️ Timeout: {int(API_TIMEOUT)}s")
|
||||||
|
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
st.subheader("Retrieval Settings")
|
st.subheader("Retrieval Settings")
|
||||||
|
|
@ -171,9 +185,6 @@ for msg in st.session_state.messages:
|
||||||
if "latency_ms" in msg:
|
if "latency_ms" in msg:
|
||||||
st.caption(f"⏱️ Antwortzeit: {msg['latency_ms']}ms | Query-ID: `{msg.get('query_id')}`")
|
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:
|
else:
|
||||||
st.markdown(msg["content"])
|
st.markdown(msg["content"])
|
||||||
|
|
||||||
|
|
@ -187,7 +198,6 @@ if prompt := st.chat_input("Was beschäftigt dich?"):
|
||||||
# Generate Response
|
# Generate Response
|
||||||
with st.chat_message("assistant"):
|
with st.chat_message("assistant"):
|
||||||
message_placeholder = st.empty()
|
message_placeholder = st.empty()
|
||||||
# Placeholder for intent badge
|
|
||||||
status_placeholder = st.empty()
|
status_placeholder = st.empty()
|
||||||
|
|
||||||
with st.spinner("Thinking... (Decision Engine Active)"):
|
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
|
# 4. Show Latency & Feedback UI
|
||||||
st.caption(f"⏱️ {latency}ms | ID: `{query_id}`")
|
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])
|
col1, col2, col3, col4 = st.columns([1,1,1,4])
|
||||||
with col1:
|
with col1:
|
||||||
if st.button("👍", key=f"up_{query_id}"):
|
if st.button("👍", key=f"up_{query_id}"):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user