Skip to content

Commit

Permalink
improve OpenAI account error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Dec 7, 2023
1 parent 16616c0 commit 7899962
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion core/cat/routes/embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/cat/routes/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion core/cat/routes/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from cat.looking_glass.stray_cat import StrayCat
from cat.log import log
from cat import utils

router = APIRouter()

Expand Down Expand Up @@ -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]



12 changes: 12 additions & 0 deletions core/cat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 7899962

Please sign in to comment.