Skip to content

Commit

Permalink
Merge pull request #640 from praekeltfoundation/update-gobberish-dete…
Browse files Browse the repository at this point in the history
…ction-function

update gibberish detection function
  • Loading branch information
Hlamallama authored Oct 22, 2024
2 parents 33d90e3 + 87d8eb9 commit 46c61c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion aaq/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ def post_search_return_empty(self, request):
"feedback_secret_key": "secret-key-12345-abcde",
"llm_response": None,
"query_id": 1,
"search_results": {},
"search_results": {
"status": 400,
"error": {"detail": "Gibberish text detected: gyugsywgshfsthg"},
},
"state": "final",
}

Expand Down
18 changes: 10 additions & 8 deletions aaq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ def search(query_text, generate_llm_response, query_metadata):
feedback_secret_key = response.json()["feedback_secret_key"]
search_results = response.json()["search_results"]

if search_results == {}:
json_msg = {
"message": "Gibberish Detected",
"body": {},
"feedback_secret_key": feedback_secret_key,
"query_id": query_id,
}
return Response(json_msg, status=status.HTTP_200_OK)
if "error" in search_results:
error_detail = search_results["error"].get("detail", "")
if "Gibberish text detected" in error_detail:
json_msg = {
"message": "Gibberish Detected",
"body": {},
"feedback_secret_key": feedback_secret_key,
"query_id": query_id,
}
return Response(json_msg, status=status.HTTP_200_OK)

json_msg = {}
body_content = {}
Expand Down

0 comments on commit 46c61c1

Please sign in to comment.