Skip to content

Commit

Permalink
updated the mock data for summarization;
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjan-stha committed Jun 25, 2024
1 parent a53a01f commit e530250
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
32 changes: 22 additions & 10 deletions analysis_module/mockserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from core.models import NLPRequest
from core_server.settings import ENDPOINT_NAME
from .mock_templates import MOCK_ENTRY_CLASSIFICATION, MOCK_ENTRY_CLASSIFICATION_FORMATTED, MOCK_GEOLOCATION # noqa
from .utils import send_callback_url_request
from .utils import send_callback_url_request, send_callback_url_request_for_summarization


logger = logging.getLogger("__name__")
Expand All @@ -27,8 +27,8 @@
def get_entries_data(url: str, timeout: int=30) -> Any:
"""get data"""
response = requests.get(url, timeout=timeout)
entries_data = json.loads(response.text)
return entries_data
return response.json() #json.loads(response.text)
#return entries_data


def save_data_local_and_get_url(dir_name: str, client_id: str, data: Any) -> str:
Expand Down Expand Up @@ -135,23 +135,35 @@ def process_summarization(body: dict) -> Any:
input_payload = get_entries_data(entries_url)
excerpts = [x["excerpt"] for x in input_payload["data"]]
except Exception:
send_callback_url_request(
send_callback_url_request_for_summarization(
callback_url=callback_url,
client_id=client_id,
filepath="",
summary_filepath="",
analytical_statement_filepath="",
info_gaps_filepath="",
status=NLPRequest.RequestStatus.PROCESS_INPUT_URL_FAILED,
)
return

data = " ".join(["This is a fake response.\n"] + excerpts)
filepath = save_data_local_and_get_url(
dir_name="summarization", client_id=client_id, data=data
summary_data = " ".join(["This is a fake response.\n"] + excerpts)
summary_filepath = save_data_local_and_get_url(
dir_name="summarization", client_id=client_id, data=summary_data
)
analytical_statement_data = " ".join(["This is autogenerated Analytical Statement.\n"] + excerpts)
analytical_statement_filepath = save_data_local_and_get_url(
dir_name="summarization", client_id=client_id, data=analytical_statement_data
)
info_gaps_data = " ".join(["This is autogenerated info gaps.\n"] + excerpts)
info_gaps_filepath = save_data_local_and_get_url(
dir_name="summarization", client_id=client_id, data=info_gaps_data
)

send_callback_url_request(
send_callback_url_request_for_summarization(
callback_url=callback_url,
client_id=client_id,
filepath=filepath,
summary_filepath=summary_filepath,
analytical_statement_filepath=analytical_statement_filepath,
info_gaps_filepath=info_gaps_filepath,
status=NLPRequest.RequestStatus.SUCCESS,
)

Expand Down
40 changes: 40 additions & 0 deletions analysis_module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,46 @@ def send_callback_url_request(callback_url: str, client_id: str, filepath: str,
logging.error("No callback url found.")
return json.dumps({"status": "No callback url found."}), 400

@shared_task
def send_callback_url_request_for_summarization(
callback_url: str,
client_id: str,
summary_filepath: str,
analytical_statement_filepath: str,
info_gaps_filepath: str,
status: int
) -> Any:
"""send callback url"""

time.sleep(1)
if callback_url:
response_callback_url = requests.post(
callback_url,
json={
"client_id": client_id,
"summary_url": summary_filepath,
"analytical_statement_url": analytical_statement_filepath,
"info_gaps_url": info_gaps_filepath,
"status": status,
},
timeout=30,
)
if response_callback_url.status_code == 200:
logging.info("Request sent successfully.")
return json.dumps({"status": "Request sent successfully."})
else:
logging.info(
f"Some errors occurred. StatusCode: {response_callback_url.status_code}"
)
return json.dumps(
{
"status": f"Error occurred with statuscode: {response_callback_url.status_code}"
}
)

logging.error("No callback url found.")
return json.dumps({"status": "No callback url found."}), 400


def get_geolocations(excerpts: List[str], req_timeout: int = 60):
""" Get geolocations from excerpts by requesting from geolocation module """
Expand Down

0 comments on commit e530250

Please sign in to comment.