Skip to content
Merged
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
detect_sentiment api has limits of input size of 5kb
Code has been updated to make sure the api does not failed
  • Loading branch information
Prabath Peiris committed Mar 21, 2025
commit c3b4fc0377ee67db8c930fb92483db0b9a2db7d7
8 changes: 8 additions & 0 deletions pca-server/src/pca/pca-aws-sf-process-turn-by-turn.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,16 @@ def comprehend_single_sentiment(self, text, client):
Perform sentiment analysis, but try and avert throttling by trying one more time if this exceptions.
It is not a replacement for limit increases, but will help limit failures if usage suddenly grows
"""

MAX_TEXT_SIZE = 5000 # This is limited by the AWS comprehend services: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/comprehend/client/detect_sentiment.html
sentimentResponse = {}
counter = 0

if isinstance(text, str):
text = text.encode('utf-8') # Convert to bytes
text = text[:MAX_TEXT_SIZE] # Truncate if too long for AWS Comprehend
text = text.decode('utf-8', 'ignore') # Convert back to string

while sentimentResponse == {}:
try:
# Get the sentiment, and strip off the MIXED response (as we won't be using it)
Expand Down