Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation Export Bug Fix #230

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ai_ta_backend/service/export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ def export_documents_json(self, course_name: str, from_date='', to_date=''):

response = self.sql.getDocumentsBetweenDates(course_name, from_date, to_date, 'documents')
# add a condition to route to direct download or s3 download
if response.count > 1000:
if response.count > 500:
# call background task to upload to s3

filename = course_name + '_' + str(uuid.uuid4()) + '_documents.zip'
s3_filepath = f"courses/{course_name}/{filename}"
# background task of downloading data - map it with above ID
executor = ProcessPoolExecutor()
executor.submit(self.export_data_in_bg, response, "documents", course_name, s3_filepath)
return {"response": 'Download from S3', "s3_path": s3_filepath}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the response as Download from S3. The user message will be created on frontend on the basis of this response.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted!

return {"response": 'There are 500+ documents in the export. You will receive an email with the download link shortly!',
"s3_path": s3_filepath}

else:
# Fetch data
Expand Down Expand Up @@ -206,11 +207,11 @@ def export_convo_history_json(self, course_name: str, from_date='', to_date=''):
from_date (str, optional): The start date for the data export. Defaults to ''.
to_date (str, optional): The end date for the data export. Defaults to ''.
"""
print("Exporting conversation history to csv file...")
print("Exporting conversation history to json file...")

response = self.sql.getDocumentsBetweenDates(course_name, from_date, to_date, 'llm-convo-monitor')

if response.count > 1000:
if response.count > 500:
# call background task to upload to s3
filename = course_name + '_' + str(uuid.uuid4()) + '_convo_history.zip'
s3_filepath = f"courses/{course_name}/{filename}"
Expand All @@ -226,7 +227,7 @@ def export_convo_history_json(self, course_name: str, from_date='', to_date=''):
last_id = response.data[-1]['id']
total_count = response.count

filename = course_name + '_' + str(uuid.uuid4()) + '_convo_history.csv'
filename = course_name + '_' + str(uuid.uuid4()) + '_convo_history.json'
file_path = os.path.join(os.getcwd(), filename)
curr_count = 0
# Fetch data in batches of 25 from first_id to last_id
Expand Down