Files
letta-server/letta/errors.py
2024-10-03 14:46:36 -07:00

110 lines
3.2 KiB
Python

from typing import TYPE_CHECKING
# Avoid circular imports
if TYPE_CHECKING:
from letta.schemas.message import Message
class LettaError(Exception):
"""Base class for all Letta related errors."""
class LLMError(LettaError):
pass
class LLMJSONParsingError(LettaError):
"""Exception raised for errors in the JSON parsing process."""
def __init__(self, message="Error parsing JSON generated by LLM"):
self.message = message
super().__init__(self.message)
class LocalLLMError(LettaError):
"""Generic catch-all error for local LLM problems"""
def __init__(self, message="Encountered an error while running local LLM"):
self.message = message
super().__init__(self.message)
class LocalLLMConnectionError(LettaError):
"""Error for when local LLM cannot be reached with provided IP/port"""
def __init__(self, message="Could not connect to local LLM"):
self.message = message
super().__init__(self.message)
class MissingFunctionCallError(LettaError):
message: "Message"
""" The message that caused this error.
This error should be raised when a message that we expect to have a function call does not.
"""
def __init__(self, *, message: "Message") -> None:
error_msg = "The message is missing a function call: \n\n"
# Pretty print out message
message_json = message.model_dump_json(indent=4)
error_msg += f"{message_json}"
super().__init__(error_msg)
self.message = message
class InvalidFunctionCallError(LettaError):
message: "Message"
""" The message that caused this error.
This error should be raised when a message uses a function that is unexpected or invalid, or if the usage is incorrect.
"""
def __init__(self, *, message: "Message") -> None:
error_msg = "The message uses an invalid function call or has improper usage of a function call: \n\n"
# Pretty print out message
message_json = message.model_dump_json(indent=4)
error_msg += f"{message_json}"
super().__init__(error_msg)
self.message = message
class MissingInnerMonologueError(LettaError):
message: "Message"
""" The message that caused this error.
This error should be raised when a message that we expect to have an inner monologue does not.
"""
def __init__(self, *, message: "Message") -> None:
error_msg = "The message is missing an inner monologue: \n\n"
# Pretty print out message
message_json = message.model_dump_json(indent=4)
error_msg += f"{message_json}"
super().__init__(error_msg)
self.message = message
class InvalidInnerMonologueError(LettaError):
message: "Message"
""" The message that caused this error.
This error should be raised when a message has an improperly formatted inner monologue.
"""
def __init__(self, *, message: "Message") -> None:
error_msg = "The message has a malformed inner monologue: \n\n"
# Pretty print out message
message_json = message.model_dump_json(indent=4)
error_msg += f"{message_json}"
super().__init__(error_msg)
self.message = message