Skip to content

Commit

Permalink
Merge pull request cheshire-cat-ai#611 from cheshire-cat-ai/develop
Browse files Browse the repository at this point in the history
Better error message for noobs + rabbithole bug fix
  • Loading branch information
pieroit authored Dec 7, 2023
2 parents b65c33c + 73306fc commit e6eabe6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/cat/looking_glass/stray_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def __call__(self, user_message_json):
index = MAX_TEXT_INPUT
self.working_memory["user_message_json"]["text"], to_declarative_memory = self.working_memory["user_message_json"]["text"][:index], self.working_memory["user_message_json"]["text"][index:]
docs = self.rabbit_hole.string_to_docs(stray=self, file_bytes=to_declarative_memory, content_type="text/plain")
self.rabbit_hole.store_documents(docs=docs, source="")
self.rabbit_hole.store_documents(self, docs=docs, source="")


# recall episodic and declarative memories from vector collections
Expand Down
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]



15 changes: 15 additions & 0 deletions core/cat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import inspect
from datetime import timedelta
from cat.log import log


def to_camel_case(text: str) -> str:
Expand Down Expand Up @@ -100,6 +101,20 @@ 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"""

log.error(error_description) # just to make sure the message is read both front and backend

return error_description


# This is our masterwork during tea time
class singleton:

Expand Down
2 changes: 1 addition & 1 deletion core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "Cheshire-Cat"
description = "Production ready AI assistant framework"
version = "1.4.2"
version = "1.4.3"
requires-python = ">=3.10"
license = { file="LICENSE" }
authors = [
Expand Down

0 comments on commit e6eabe6

Please sign in to comment.