Skip to content

Commit

Permalink
Merge branch 'zAlweNy26-updated-ws-error-message-fixed-434' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Sep 4, 2023
2 parents 1489630 + 64d845f commit 970693e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
35 changes: 20 additions & 15 deletions core/cat/looking_glass/cheshire_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cat.memory.long_term_memory import LongTermMemory
from cat.looking_glass.agent_manager import AgentManager

MSG_TYPES = Literal["notification", "chat"]
MSG_TYPES = Literal["notification", "chat", "error"]

# main class
class CheshireCat:
Expand Down Expand Up @@ -289,21 +289,28 @@ def send_ws_message(self, content: str, msg_type: MSG_TYPES = "notification"):
Parameters
----------
type : str
The type of the message. Should be either `notification` or `chat`
content : str
The content of the message.
msg_type : str
The type of the message. Should be either `notification`, `chat` or `error`
"""

options = get_args(MSG_TYPES)

if msg_type not in options:
raise ValueError(f"The message type `{msg_type}` is not valid. Valid types: {', '.join(options)}")

self.ws_messages.append({
"type": msg_type,
"content": content
})
if msg_type == "error":
self.ws_messages.append({
"type": msg_type,
"name": "GenericError",
"description": content
})
else:
self.ws_messages.append({
"type": msg_type,
"content": content
})

def get_base_url(self):
"""Allows the Cat expose the base url."""
Expand Down Expand Up @@ -375,16 +382,14 @@ def __call__(self, user_message_json):
traceback.print_exc(e)

err_message = (
"Vector memory error: you probably changed "
"Embedder and old vector memory is not compatible. "
"You probably changed Embedder and old vector memory is not compatible. "
"Please delete `core/long_term_memory` folder."
)

return {
"error": False,
# TODO: Otherwise the frontend gives notice of the error
# but does not show what the error is
"content": err_message,
"why": {},
"type": "error",
"name": "VectorMemoryError",
"description": err_message,
}

# prepare input to be passed to the agent.
Expand Down Expand Up @@ -434,8 +439,8 @@ def __call__(self, user_message_json):
procedural_report = [dict(d[0]) | {"score": float(d[1]), "id": d[3]} for d in self.working_memory["procedural_memories"]]

final_output = {
"error": False,
"type": "chat",
"user_id": user_id,
"content": cat_message.get("output"),
"why": {
"input": cat_message.get("input"),
Expand Down
1 change: 0 additions & 1 deletion core/cat/mad_hatter/core_plugin/hooks/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ def before_cat_sends_message(message: dict, cat) -> dict:
Default `message` is::
{
"error": False,
"type": "chat",
"content": cat_message["output"],
"why": {
Expand Down
4 changes: 2 additions & 2 deletions core/tests/routes/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def test_websocket(client):
"text": "Your bald aunt with a wooden leg"
}, client)

for k in ["error", "content", "why"]:
for k in ["type", "content", "why"]:
assert k in res.keys()

assert not res["error"]
assert res["type"] != "error"
assert type(res["content"]) == str
assert "You did not configure" in res["content"]
assert len(res["why"].keys()) > 0

0 comments on commit 970693e

Please sign in to comment.