XQ commited on
Commit
9a11ef7
·
1 Parent(s): 75d5d3a

Update UI:Add error info

Browse files
Files changed (2) hide show
  1. src/api/routes.py +11 -1
  2. src/ui/app.py +6 -1
src/api/routes.py CHANGED
@@ -164,7 +164,17 @@ async def query_documents(request: QueryRequest) -> QueryResponse:
164
  """
165
  logger.info("Received query: %s", request.question)
166
 
167
- response = _query_router.route(query=request.question, top_k=request.top_k)
 
 
 
 
 
 
 
 
 
 
168
 
169
  sources = [
170
  {
 
164
  """
165
  logger.info("Received query: %s", request.question)
166
 
167
+ try:
168
+ response = _query_router.route(query=request.question, top_k=request.top_k)
169
+ except Exception as exc:
170
+ exc_str = str(exc)
171
+ if "429" in exc_str or "RESOURCE_EXHAUSTED" in exc_str or "rate" in exc_str.lower():
172
+ logger.warning("Rate limit / quota exhausted: %s", exc_str)
173
+ raise HTTPException(
174
+ status_code=429,
175
+ detail="API-kvoten er midlertidigt opbrugt. Vent venligst et øjeblik, og prøv igen.",
176
+ ) from exc
177
+ raise
178
 
179
  sources = [
180
  {
src/ui/app.py CHANGED
@@ -83,6 +83,7 @@ TEXTS: dict[str, dict[str, str]] = {
83
  "Kontroller at backend korer paa http://localhost:8000."
84
  ),
85
  "err_api": "API-fejl",
 
86
  "err_timeout": "Forespoorgslen tog for lang tid. Prøv igen.",
87
  "unknown": "ukendt",
88
  "model_heading": "Aktuel model",
@@ -154,6 +155,7 @@ TEXTS: dict[str, dict[str, str]] = {
154
  "Make sure the backend is running at http://localhost:8000."
155
  ),
156
  "err_api": "API error",
 
157
  "err_timeout": "The request took too long. Please try again.",
158
  "unknown": "unknown",
159
  "model_heading": "Current model",
@@ -454,7 +456,10 @@ if search_clicked and question.strip():
454
  st.error(t["err_connection"])
455
  st.stop()
456
  except requests.HTTPError as exc:
457
- st.error(f'{t["err_api"]}: {exc.response.status_code} -- {exc.response.text}')
 
 
 
458
  st.stop()
459
  except requests.Timeout:
460
  st.error(t["err_timeout"])
 
83
  "Kontroller at backend korer paa http://localhost:8000."
84
  ),
85
  "err_api": "API-fejl",
86
+ "err_rate_limit": "API-kvoten er midlertidigt opbrugt. Vent venligst et øjeblik, og prøv igen.",
87
  "err_timeout": "Forespoorgslen tog for lang tid. Prøv igen.",
88
  "unknown": "ukendt",
89
  "model_heading": "Aktuel model",
 
155
  "Make sure the backend is running at http://localhost:8000."
156
  ),
157
  "err_api": "API error",
158
+ "err_rate_limit": "The API quota is temporarily exhausted. Please wait a moment and try again.",
159
  "err_timeout": "The request took too long. Please try again.",
160
  "unknown": "unknown",
161
  "model_heading": "Current model",
 
456
  st.error(t["err_connection"])
457
  st.stop()
458
  except requests.HTTPError as exc:
459
+ if exc.response.status_code == 429:
460
+ st.warning(t["err_rate_limit"])
461
+ else:
462
+ st.error(f'{t["err_api"]}: {exc.response.status_code} -- {exc.response.text}')
463
  st.stop()
464
  except requests.Timeout:
465
  st.error(t["err_timeout"])