[9d3784]: / aiagents4pharma / talk2scholars / tools / zotero / utils / review_helper.py

Download this file

79 lines (67 with data), 2.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""
Utility for reviewing papers and saving them to Zotero.
"""
import logging
from typing import List
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
class ReviewData:
"""Helper class to organize review-related data."""
def __init__(
self,
collection_path: str,
fetched_papers: dict,
tool_call_id: str,
state: dict,
):
self.collection_path = collection_path
self.fetched_papers = fetched_papers
self.tool_call_id = tool_call_id
self.state = state
self.total_papers = len(fetched_papers)
self.papers_summary = self._create_papers_summary()
self.papers_preview = "\n".join(self.papers_summary)
self.review_info = self._create_review_info()
def get_approval_message(self) -> str:
"""Get the formatted approval message for the review."""
return (
f"Human approved saving {self.total_papers} papers to Zotero "
f"collection '{self.collection_path}'."
)
def get_custom_path_approval_message(self, custom_path: str) -> str:
"""Get the formatted approval message for a custom collection path."""
return (
f"Human approved saving papers to custom Zotero "
f"collection '{custom_path}'."
)
def _create_papers_summary(self) -> List[str]:
"""Create a summary of papers for review."""
summary = []
for paper_id, paper in list(self.fetched_papers.items())[:5]:
logger.info("Paper ID: %s", paper_id)
title = paper.get("Title", "N/A")
authors = ", ".join(
[author.split(" (ID: ")[0] for author in paper.get("Authors", [])[:2]]
)
if len(paper.get("Authors", [])) > 2:
authors += " et al."
summary.append(f"- {title} by {authors}")
if self.total_papers > 5:
summary.append(f"... and {self.total_papers - 5} more papers")
return summary
def _create_review_info(self) -> dict:
"""Create the review information dictionary."""
return {
"action": "save_to_zotero",
"collection_path": self.collection_path,
"total_papers": self.total_papers,
"papers_preview": self.papers_preview,
"message": (
f"Would you like to save {self.total_papers} papers to Zotero "
f"collection '{self.collection_path}'? Please respond with a "
f"structured decision using one of the following options: 'approve', "
f"'reject', or 'custom' (with a custom_path)."
),
}