Skip to content

Commit

Permalink
API: Fix error reporting
Browse files Browse the repository at this point in the history
Make a disconnect on load error consistently. It should be safer to
warn the user to run unload (or re-run load) if a model does not
load correctly.

Also don't log the traceback for request errors that don't have one.

Signed-off-by: kingbri <[email protected]>
  • Loading branch information
bdashore3 committed Mar 5, 2024
1 parent 165cc6f commit 0b25c20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class TabbyRequestError(BaseModel):
error: TabbyRequestErrorMessage


def get_generator_error(message: str):
def get_generator_error(message: str, exc_info: bool = True):
"""Get a generator error."""

generator_error = handle_request_error(message)

return get_sse_packet(generator_error.model_dump_json())


def handle_request_error(message: str):
def handle_request_error(message: str, exc_info: bool = True):
"""Log a request error to the console."""

error_message = TabbyRequestErrorMessage(
Expand All @@ -45,7 +45,7 @@ def handle_request_error(message: str):
request_error = TabbyRequestError(error=error_message)

# Log the error and provided message to the console
if error_message.trace:
if error_message.trace and exc_info:
logger.error(error_message.trace)

logger.error(f"Sent to request: {message}")
Expand Down
11 changes: 9 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@


async def _check_model_container():
"""Checks if a model isn't loading or loaded."""

if MODEL_CONTAINER is None or not (
MODEL_CONTAINER.model_is_loading or MODEL_CONTAINER.model_loaded
):
error_message = handle_request_error(
"No models are currently loaded."
"No models are currently loaded.",
exc_info=False,
).error.message

raise HTTPException(400, error_message)
Expand Down Expand Up @@ -221,6 +224,7 @@ async def generator():

# Unload the existing model
if MODEL_CONTAINER and MODEL_CONTAINER.model:
logger.info("Unloading existing model.")
await unload_model()

MODEL_CONTAINER = ExllamaV2Container(model_path.resolve(), False, **load_data)
Expand All @@ -231,7 +235,10 @@ async def generator():
try:
for module, modules in load_status:
if await request.is_disconnected():
await unload_model()
logger.error(
"Model load cancelled by user. "
"Please make sure to run unload to free up resources."
)
break

if module == 0:
Expand Down

0 comments on commit 0b25c20

Please sign in to comment.