Skip to content

Commit

Permalink
Merge pull request #146 from rgbkrk/bubble-exceptions-explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
rgbkrk authored Mar 9, 2024
2 parents e6d30e6 + b2e46a6 commit 9873fc9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion chatlab/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions chatlab/views/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9873fc9

Please sign in to comment.