Commit
•
38c818a
1
Parent(s):
d0eeb69
chore: Refactor comment posting functionality and improve performance
Browse files
app.py
CHANGED
@@ -245,11 +245,11 @@ def return_recommendations(
|
|
245 |
arxiv_id = parse_arxiv_id_from_paper_url(url)
|
246 |
recommendations = get_recommendations_from_semantic_scholar(f"ArXiv:{arxiv_id}")
|
247 |
filtered_recommendations = filter_recommendations(recommendations)
|
|
|
|
|
|
|
248 |
|
249 |
if post_to_paper:
|
250 |
-
formatted_recommendation = format_recommendation_into_markdown(
|
251 |
-
arxiv_id, filtered_recommendations
|
252 |
-
)
|
253 |
comment = format_comment(formatted_recommendation)
|
254 |
|
255 |
# Check if a librarian-bot comment already exists.
|
@@ -258,27 +258,26 @@ def return_recommendations(
|
|
258 |
gr.Info(
|
259 |
f"Librarian-bot already commented on this paper. Comment ID: {existing_comment_id}. No further action will be taken."
|
260 |
)
|
261 |
-
return formatted_recommendation # Return formatted recommendation without posting.
|
262 |
-
|
263 |
-
# If no existing librarian-bot comment, check if a specific comment_id is provided for replying.
|
264 |
-
if comment_id:
|
265 |
-
comment_status, posted_comment_id = post_comment(
|
266 |
-
url, comment, comment_id, token=HF_TOKEN
|
267 |
-
)
|
268 |
-
if comment_status:
|
269 |
-
log_comments(url, comment)
|
270 |
-
gr.Info(f"Posted reply to comment {posted_comment_id}")
|
271 |
else:
|
272 |
-
# If no
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
|
280 |
-
|
281 |
-
|
282 |
|
283 |
return formatted_recommendation
|
284 |
|
|
|
245 |
arxiv_id = parse_arxiv_id_from_paper_url(url)
|
246 |
recommendations = get_recommendations_from_semantic_scholar(f"ArXiv:{arxiv_id}")
|
247 |
filtered_recommendations = filter_recommendations(recommendations)
|
248 |
+
formatted_recommendation = format_recommendation_into_markdown(
|
249 |
+
arxiv_id, filtered_recommendations
|
250 |
+
) # Assign early
|
251 |
|
252 |
if post_to_paper:
|
|
|
|
|
|
|
253 |
comment = format_comment(formatted_recommendation)
|
254 |
|
255 |
# Check if a librarian-bot comment already exists.
|
|
|
258 |
gr.Info(
|
259 |
f"Librarian-bot already commented on this paper. Comment ID: {existing_comment_id}. No further action will be taken."
|
260 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
261 |
else:
|
262 |
+
# If no existing librarian-bot comment, check if a specific comment_id is provided for replying.
|
263 |
+
if comment_id:
|
264 |
+
comment_status, posted_comment_id = post_comment(
|
265 |
+
url, comment, comment_id, token=HF_TOKEN
|
266 |
+
)
|
267 |
+
if comment_status:
|
268 |
+
log_comments(url, comment)
|
269 |
+
gr.Info(f"Posted reply to comment {posted_comment_id}")
|
270 |
+
else:
|
271 |
+
# If no comment_id is provided, post a new comment.
|
272 |
+
comment_status, posted_comment_id = post_comment(
|
273 |
+
url, comment, token=HF_TOKEN
|
274 |
+
)
|
275 |
+
if comment_status:
|
276 |
+
log_comments(url, comment)
|
277 |
+
gr.Info(f"Posted new comment {posted_comment_id}")
|
278 |
|
279 |
+
if not comment_status:
|
280 |
+
gr.Info("Failed to post comment")
|
281 |
|
282 |
return formatted_recommendation
|
283 |
|