Skip to content

Commit

Permalink
DH-4863 Limit nl response + sql characters (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
DishenWang2023 committed May 7, 2024
1 parent 737ed9e commit 7a1cb7c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions apps/ai/server/modules/query/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

CONFIDENCE_CAP = 0.95
CORRECT_RESPONSE_COUNT = 2
SLACK_CHARACTER_LIMIT = 2700


class QueryService:
Expand Down Expand Up @@ -122,6 +123,17 @@ async def answer_question(
else:
is_above_confidence_threshold = True

# error handling for response longer than character limit
if len(answer.response + answer.sql_query) >= SLACK_CHARACTER_LIMIT:
answer.response = (
":warning: The generated response has been truncated due to exceeding character limit. "
+ "A full response will be returned once reviewed by the data-team admins: \n\n"
+ answer.response[
: max(SLACK_CHARACTER_LIMIT - len(answer.sql_query), 0)
]
+ "..."
)

return QuerySlackResponse(
id=query_id,
display_id=query.display_id,
Expand Down

0 comments on commit 7a1cb7c

Please sign in to comment.