From b2e46a66b95b70941fdb80f970093829cea0daae Mon Sep 17 00:00:00 2001 From: Kyle Kelley Date: Thu, 7 Mar 2024 11:26:00 -0800 Subject: [PATCH] show chat models exceptions by default --- chatlab/decorators.py | 14 +++++++++++++- chatlab/views/tools.py | 3 +-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/chatlab/decorators.py b/chatlab/decorators.py index 00c8a03..779ced4 100644 --- a/chatlab/decorators.py +++ b/chatlab/decorators.py @@ -36,8 +36,20 @@ class ChatlabMetadata(BaseModel): """ChatLab metadata for a function.""" - expose_exception_to_llm: bool = False + expose_exception_to_llm: bool = True render: Optional[Callable] = None + bubble_exceptions: bool = False + +def bubble_exceptions(func): + if not hasattr(func, "chatlab_metadata"): + func.chatlab_metadata = ChatlabMetadata() + + # Make sure that chatlab_metadata is an instance of ChatlabMetadata + if not isinstance(func.chatlab_metadata, ChatlabMetadata): + raise Exception("func.chatlab_metadata must be an instance of ChatlabMetadata") + + func.chatlab_metadata.bubble_exceptions = True + return func def expose_exception_to_llm(func): """Expose exceptions from calling the function to the LLM. diff --git a/chatlab/views/tools.py b/chatlab/views/tools.py index 87a7db1..133b7df 100644 --- a/chatlab/views/tools.py +++ b/chatlab/views/tools.py @@ -145,8 +145,7 @@ async def call(self, function_registry: FunctionRegistry) -> 'ToolCalled': # If not, then we just raise it and let the user handle it. chatlab_metadata = function_registry.get_chatlab_metadata(function_name) - if not chatlab_metadata.expose_exception_to_llm: - # Bubble up the exception to the user + if chatlab_metadata.bubble_exceptions: raise repr_llm = repr(e)