Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ErrorResponse User Messages #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion fireworks_poe_bot/fw_poe_image_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,20 @@ async def get_response(
)
if "prompt is too long" in str(e):
error_type = "user_message_too_long"
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The user message is too long. Please try again with a shorter message."
)
else:
error_type = None
yield ErrorResponse(allow_retry=False, error_type=error_type, text=str(e))
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The bot encountered an unexpected error."
)
return
finally:
fireworks.client.api_key = orig_api_key
Expand Down
13 changes: 12 additions & 1 deletion fireworks_poe_bot/fw_poe_qr_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,20 @@ async def get_response(
)
if "prompt is too long" in str(e):
error_type = "user_message_too_long"
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The user message is too long. Please try again with a shorter message."
)
else:
error_type = None
yield ErrorResponse(allow_retry=False, error_type=error_type, text=str(e))
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The bot encountered an unexpected error."
)
return
finally:
fireworks.client.api_key = orig_api_key
Expand Down
13 changes: 12 additions & 1 deletion fireworks_poe_bot/fw_poe_stability_image_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,20 @@ async def fetch_image():
)
if "prompt is too long" in str(e):
error_type = "user_message_too_long"
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The user message is too long. Please try again with a shorter message."
)
else:
error_type = None
yield ErrorResponse(allow_retry=False, error_type=error_type, text=str(e))
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The bot encountered an unexpected error."
)
return

# Function to upload a PIL Image to an S3 bucket with a presigned URL
Expand Down
25 changes: 20 additions & 5 deletions fireworks_poe_bot/fw_poe_text_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,19 @@ async def get_response(
protocol_message.attachments[0].url
)
except Exception as e:
yield ErrorResponse(allow_retry=False, text=str(e))
yield ErrorResponse(
allow_retry=False,
raw_response=e,
text="The bot encountered an error while processing an attached image."
)
raise RuntimeError(str(e))

if img_buffer:
num_images += 1
if cumulative_image_size_mb > 8:
# Apigee has a limit of 10MB for payload, we set image total limit to 8MB
yield ErrorResponse(
allow_retry=False, text="The total image size is too big"
allow_retry=False, text="The total image size is too big. Limit is 8MB."
)
raise RuntimeError("The total image size is too big")
messages.append(
Expand Down Expand Up @@ -306,8 +310,8 @@ async def get_response(
)
yield ErrorResponse(
allow_retry=False,
text="Error performing image safety check: "
+ str(e),
text="Error performing image safety check.",
raw_response=e,
)
return
last_image_kept = True
Expand Down Expand Up @@ -493,9 +497,20 @@ def merge_messages_groups(
)
if "prompt is too long" in str(e):
error_type = "user_message_too_long"
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The user message is too long. Please try again with a shorter message."
)
else:
error_type = None
yield ErrorResponse(allow_retry=False, error_type=error_type, text=str(e))
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The bot encountered an unexpected error."
)
return
finally:
fireworks.client.api_key = orig_api_key
Expand Down
19 changes: 17 additions & 2 deletions fireworks_poe_bot/fw_poe_video_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ async def get_response(
protocol_message.attachments[0].url
)
except Exception as e:
yield ErrorResponse(allow_retry=False, text=str(e))
yield ErrorResponse(
allow_retry=False,
raw_response=e,
text="The bot encountered an error while processing an attached image."
)
raise RuntimeError(str(e))
else:
yield self.replace_response_event(
Expand Down Expand Up @@ -311,9 +315,20 @@ async def get_response(
)
if "prompt is too long" in str(e):
error_type = "user_message_too_long"
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The user message is too long. Please try again with a shorter message."
)
else:
error_type = None
yield ErrorResponse(allow_retry=False, error_type=error_type, text=str(e))
yield ErrorResponse(
allow_retry=False,
error_type=error_type,
raw_response=e,
text="The bot encountered an unexpected error."
)
return
finally:
fireworks.client.api_key = orig_api_key
Expand Down