Skip to content

Commit

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

update gibberish response
  • Loading branch information
Hlamallama authored Oct 22, 2024
2 parents 46c61c1 + 7b0fc7f commit 292612a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
11 changes: 2 additions & 9 deletions aaq/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,8 @@ def post_search(self, request):

def post_search_return_empty(self, request):
resp_body = {
"debug_info": {"example": "debug-info"},
"feedback_secret_key": "secret-key-12345-abcde",
"llm_response": None,
"query_id": 1,
"search_results": {
"status": 400,
"error": {"detail": "Gibberish text detected: gyugsywgshfsthg"},
},
"state": "final",
"status": 400,
"error": {"detail": "Gibberish text detected: vyjhftgdfdgt"},
}

return (200, {}, json.dumps(resp_body))
Expand Down
3 changes: 0 additions & 3 deletions aaq/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,4 @@ def test_search_gibberish(self):

assert response.data == {
"message": "Gibberish Detected",
"body": {},
"feedback_secret_key": "secret-key-12345-abcde",
"query_id": 1,
}
14 changes: 5 additions & 9 deletions aaq/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,17 @@ def search(query_text, generate_llm_response, query_metadata):
response = requests.request("POST", url, json=payload, headers=headers)
response.raise_for_status()

query_id = response.json()["query_id"]
feedback_secret_key = response.json()["feedback_secret_key"]
search_results = response.json()["search_results"]

if "error" in search_results:
error_detail = search_results["error"].get("detail", "")
if "error" in response.json():
error_detail = response.json()["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)

query_id = response.json()["query_id"]
feedback_secret_key = response.json()["feedback_secret_key"]
search_results = response.json()["search_results"]
json_msg = {}
body_content = {}
message_titles = []
Expand Down

0 comments on commit 292612a

Please sign in to comment.