Skip to content

Commit

Permalink
Merge pull request #97 from AI4Bharat/minor_fix_empty_prompt
Browse files Browse the repository at this point in the history
added response for empty prompt or output
  • Loading branch information
aparna-aa committed Aug 1, 2024
2 parents b64fa4f + f584af7 commit c94bafa
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion backend/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,12 @@ def partial_update(self, request, pk=None):
annotation_obj,
annotation_obj.task.project_id.metadata_json,
)
if output_result == -1:
ret_dict = {
"message": "Please make sure you have entered a prompt and the system has responded with an answer"
}
ret_status = status.HTTP_403_FORBIDDEN
return Response(ret_dict, status=ret_status)
# store the result of all checks as well
annotation_obj.result.append(
{
Expand Down Expand Up @@ -1671,6 +1677,12 @@ def partial_update(self, request, pk=None):
annotation_obj,
annotation_obj.task.project_id.metadata_json,
)
if output_result == -1:
ret_dict = {
"message": "Please make sure you have entered a prompt and the system has responded with an answer"
}
ret_status = status.HTTP_403_FORBIDDEN
return Response(ret_dict, status=ret_status)
# store the result of all checks as well
annotation_obj.result.append(
{
Expand Down Expand Up @@ -1881,6 +1893,12 @@ def partial_update(self, request, pk=None):
annotation_obj,
annotation_obj.task.project_id.metadata_json,
)
if output_result == -1:
ret_dict = {
"message": "Please make sure you have entered a prompt and the system has responded with an answer"
}
ret_status = status.HTTP_403_FORBIDDEN
return Response(ret_dict, status=ret_status)
# store the result of all checks as well
annotation_obj.result.append(
{
Expand Down Expand Up @@ -2328,6 +2346,8 @@ def get_llm_output(prompt, task, annotation, project_metadata_json):
if isinstance(project_metadata_json, str)
else project_metadata_json
)
if prompt in [None, "Null", 0, "None", "", " "]:
return -1
intentDomain_test, lang_test, duplicate_test = False, False, False
if project_metadata:
if (
Expand Down Expand Up @@ -2365,7 +2385,10 @@ def get_llm_output(prompt, task, annotation, project_metadata_json):
history,
model,
)
return format_model_output(model_output)
res = format_model_output(model_output)
if res in [None, "Null", 0, "None", "", " "]:
return -1
return res


def format_model_output(model_output):
Expand Down

0 comments on commit c94bafa

Please sign in to comment.