diff --git a/core/cat/routes/embedder.py b/core/cat/routes/embedder.py index 2300ce53..4b4cfee9 100644 --- a/core/cat/routes/embedder.py +++ b/core/cat/routes/embedder.py @@ -5,6 +5,7 @@ from cat.factory.embedder import EMBEDDER_SCHEMAS, SUPPORTED_EMDEDDING_MODELS from cat.db import crud, models from cat.log import log +from cat import utils router = APIRouter() @@ -150,7 +151,7 @@ def upsert_embedder_setting( raise HTTPException( status_code=400, detail={ - "error": str(e) + "error": utils.explicit_error_message(e) } ) # recreate tools embeddings diff --git a/core/cat/routes/llm.py b/core/cat/routes/llm.py index 58ac3f8d..45718833 100644 --- a/core/cat/routes/llm.py +++ b/core/cat/routes/llm.py @@ -5,6 +5,7 @@ from cat.factory.llm import LLM_SCHEMAS from cat.db import crud, models from cat.log import log +from cat import utils router = APIRouter() @@ -129,7 +130,7 @@ def upsert_llm_setting( raise HTTPException( status_code=400, detail={ - "error": str(e) + "error": utils.explicit_error_message(e) } ) # recreate tools embeddings diff --git a/core/cat/routes/websocket.py b/core/cat/routes/websocket.py index 76f75b90..e6c26a23 100644 --- a/core/cat/routes/websocket.py +++ b/core/cat/routes/websocket.py @@ -6,6 +6,7 @@ from cat.looking_glass.stray_cat import StrayCat from cat.log import log +from cat import utils router = APIRouter() @@ -79,10 +80,14 @@ async def websocket_endpoint(websocket: WebSocket, user_id: str = "user"): # Log any unexpected errors and send an error message back to the user. log.error(e) traceback.print_exc() + await websocket.send_json({ "type": "error", "name": type(e).__name__, - "description": str(e) + "description": utils.explicit_error_message(e) }) # finally: # del strays[user_id] + + + diff --git a/core/cat/utils.py b/core/cat/utils.py index 94a8f821..2886b7d6 100644 --- a/core/cat/utils.py +++ b/core/cat/utils.py @@ -100,6 +100,18 @@ def get_static_path(): return os.path.join(get_base_path(), "static/") +def explicit_error_message(e): + # add more explicit info on "RateLimitError" by OpenAI, 'cause people can't get it + error_description = str(e) + if "billing details" in error_description: + # happens both when there are no credits or the key is not active + error_description = """Your OpenAI key is not active or you did not add a payment method. +You need a credit card - and money in it - to use OpenAI api. +HOW TO FIX: go to your OpenAI accont and add a credit card""" + + return error_description + + # This is our masterwork during tea time class singleton: