feat: show budget limit message with MatrixHost link instead of generic error
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
15
bot.py
15
bot.py
@@ -15,6 +15,7 @@ import docx
|
||||
import fitz # pymupdf
|
||||
import httpx
|
||||
from openai import AsyncOpenAI
|
||||
import openai as _openai
|
||||
from olm import sas as olm_sas
|
||||
import olm.pk
|
||||
import canonicaljson
|
||||
@@ -3298,6 +3299,20 @@ class Bot:
|
||||
await self._auto_rename_room(room, user_message, reply)
|
||||
|
||||
return reply
|
||||
except _openai.APIStatusError as e:
|
||||
body = getattr(e, "body", None) or {}
|
||||
msg = body.get("message", "") if isinstance(body, dict) else str(body)
|
||||
if "BudgetGuard" in msg or "exceed budget" in msg:
|
||||
logger.warning("LLM budget exceeded: %s", msg)
|
||||
portal = PORTAL_URL.rstrip("/")
|
||||
await self._send_text(
|
||||
room.room_id,
|
||||
f"⚠️ AI budget limit reached. Please check your plan at {portal}/settings/billing",
|
||||
)
|
||||
else:
|
||||
logger.exception("LLM API error")
|
||||
await self._send_text(room.room_id, "Sorry, I couldn't generate a response.")
|
||||
return None
|
||||
except Exception:
|
||||
logger.exception("LLM call failed")
|
||||
await self._send_text(room.room_id, "Sorry, I couldn't generate a response.")
|
||||
|
||||
Reference in New Issue
Block a user