Skip to content

Commit

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

update gibberish response dict
  • Loading branch information
Hlamallama authored Oct 22, 2024
2 parents ec656c7 + cacf785 commit b9cf776
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 2 additions & 5 deletions aaq/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ def post_search(self, request):
return (200, {}, json.dumps(resp_body))

def post_search_return_empty(self, request):
resp_body = {
"status": 400,
"error": {"detail": "Gibberish text detected: vyjhftgdfdgt"},
}
resp_body = {"detail": "Gibberish text detected: vyjhftgdfdgt"}

return (200, {}, json.dumps(resp_body))
return (400, {}, json.dumps(resp_body))


class FakeAaqUdV2Api:
Expand Down
3 changes: 3 additions & 0 deletions aaq/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def test_search_gibberish(self):
query_metadata = {}
response = search(query_text, generate_llm_response, query_metadata)

search_request = responses.calls[0]

assert search_request.response.status_code == 400
assert response.data == {
"message": "Gibberish Detected",
}
7 changes: 5 additions & 2 deletions aaq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def search(query_text, generate_llm_response, query_metadata):

response = requests.request("POST", url, json=payload, headers=headers)

if "error" in response.json():
error_detail = response.json()["error"].get("detail", "")
if (
response.status_code == status.HTTP_400_BAD_REQUEST
and "detail" in response.json()
):
error_detail = response.json().get("detail", "")
if "Gibberish text detected" in error_detail:
json_msg = {
"message": "Gibberish Detected",
Expand Down

0 comments on commit b9cf776

Please sign in to comment.