Skip to content

Zotero Review Helper

Utility for reviewing papers and saving them to Zotero.

ReviewData

Helper class to organize review-related data.

Source code in aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py
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
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)."
            ),
        }

_create_papers_summary()

Create a summary of papers for review.

Source code in aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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

_create_review_info()

Create the review information dictionary.

Source code in aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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)."
        ),
    }

get_approval_message()

Get the formatted approval message for the review.

Source code in aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py
34
35
36
37
38
39
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}'."
    )

get_custom_path_approval_message(custom_path)

Get the formatted approval message for a custom collection path.

Source code in aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py
41
42
43
44
45
46
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}'."
    )