aiagents4pharma 1.31.0__py3-none-any.whl → 1.33.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiagents4pharma/talk2knowledgegraphs/configs/config.yaml +1 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_uniprot.py +44 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py +1 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/uniprot_proteins.py +90 -0
- aiagents4pharma/talk2scholars/agents/main_agent.py +4 -3
- aiagents4pharma/talk2scholars/agents/paper_download_agent.py +3 -4
- aiagents4pharma/talk2scholars/agents/pdf_agent.py +6 -7
- aiagents4pharma/talk2scholars/agents/s2_agent.py +23 -20
- aiagents4pharma/talk2scholars/agents/zotero_agent.py +11 -11
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/main_agent/default.yaml +19 -19
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/s2_agent/default.yaml +20 -15
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/zotero_agent/default.yaml +27 -6
- aiagents4pharma/talk2scholars/state/state_talk2scholars.py +7 -7
- aiagents4pharma/talk2scholars/tests/test_main_agent.py +16 -16
- aiagents4pharma/talk2scholars/tests/test_paper_download_agent.py +17 -24
- aiagents4pharma/talk2scholars/tests/test_paper_download_tools.py +152 -135
- aiagents4pharma/talk2scholars/tests/test_pdf_agent.py +9 -16
- aiagents4pharma/talk2scholars/tests/test_question_and_answer_tool.py +790 -218
- aiagents4pharma/talk2scholars/tests/test_s2_agent.py +9 -9
- aiagents4pharma/talk2scholars/tests/test_s2_display.py +8 -8
- aiagents4pharma/talk2scholars/tests/test_s2_query.py +8 -8
- aiagents4pharma/talk2scholars/tests/test_zotero_agent.py +12 -12
- aiagents4pharma/talk2scholars/tests/test_zotero_path.py +11 -12
- aiagents4pharma/talk2scholars/tests/test_zotero_read.py +400 -22
- aiagents4pharma/talk2scholars/tools/paper_download/__init__.py +0 -6
- aiagents4pharma/talk2scholars/tools/paper_download/download_arxiv_input.py +89 -31
- aiagents4pharma/talk2scholars/tools/pdf/question_and_answer.py +540 -156
- aiagents4pharma/talk2scholars/tools/s2/__init__.py +4 -4
- aiagents4pharma/talk2scholars/tools/s2/{display_results.py → display_dataframe.py} +19 -21
- aiagents4pharma/talk2scholars/tools/s2/query_dataframe.py +71 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/read_helper.py +213 -35
- aiagents4pharma/talk2scholars/tools/zotero/zotero_read.py +3 -3
- {aiagents4pharma-1.31.0.dist-info → aiagents4pharma-1.33.0.dist-info}/METADATA +3 -1
- {aiagents4pharma-1.31.0.dist-info → aiagents4pharma-1.33.0.dist-info}/RECORD +37 -37
- {aiagents4pharma-1.31.0.dist-info → aiagents4pharma-1.33.0.dist-info}/WHEEL +1 -1
- aiagents4pharma/talk2scholars/tools/paper_download/abstract_downloader.py +0 -45
- aiagents4pharma/talk2scholars/tools/paper_download/arxiv_downloader.py +0 -115
- aiagents4pharma/talk2scholars/tools/s2/query_results.py +0 -61
- {aiagents4pharma-1.31.0.dist-info → aiagents4pharma-1.33.0.dist-info}/licenses/LICENSE +0 -0
- {aiagents4pharma-1.31.0.dist-info → aiagents4pharma-1.33.0.dist-info}/top_level.txt +0 -0
@@ -31,7 +31,7 @@ def mock_tools_fixture():
|
|
31
31
|
"aiagents4pharma.talk2scholars.tools.s2.search.search_tool"
|
32
32
|
) as mock_s2_search,
|
33
33
|
mock.patch(
|
34
|
-
"aiagents4pharma.talk2scholars.tools.s2.
|
34
|
+
"aiagents4pharma.talk2scholars.tools.s2.display_dataframe.display_dataframe"
|
35
35
|
) as mock_s2_display,
|
36
36
|
mock.patch(
|
37
37
|
"aiagents4pharma.talk2scholars.tools.s2.single_paper_rec."
|
@@ -41,8 +41,8 @@ def mock_tools_fixture():
|
|
41
41
|
"aiagents4pharma.talk2scholars.tools.s2.multi_paper_rec.get_multi_paper_recommendations"
|
42
42
|
) as mock_s2_multi_rec,
|
43
43
|
mock.patch(
|
44
|
-
"aiagents4pharma.talk2scholars.tools.s2.
|
45
|
-
) as
|
44
|
+
"aiagents4pharma.talk2scholars.tools.s2.query_dataframe.query_dataframe"
|
45
|
+
) as mock_s2_query_dataframe,
|
46
46
|
mock.patch(
|
47
47
|
"aiagents4pharma.talk2scholars.tools.s2.retrieve_semantic_scholar_paper_id."
|
48
48
|
"retrieve_semantic_scholar_paper_id"
|
@@ -52,7 +52,7 @@ def mock_tools_fixture():
|
|
52
52
|
mock_s2_display.return_value = {"result": "Mock Display Result"}
|
53
53
|
mock_s2_single_rec.return_value = {"result": "Mock Single Rec"}
|
54
54
|
mock_s2_multi_rec.return_value = {"result": "Mock Multi Rec"}
|
55
|
-
|
55
|
+
mock_s2_query_dataframe.return_value = {"result": "Mock Query Result"}
|
56
56
|
mock_s2_retrieve_id.return_value = {"paper_id": "MockPaper123"}
|
57
57
|
|
58
58
|
yield [
|
@@ -60,7 +60,7 @@ def mock_tools_fixture():
|
|
60
60
|
mock_s2_display,
|
61
61
|
mock_s2_single_rec,
|
62
62
|
mock_s2_multi_rec,
|
63
|
-
|
63
|
+
mock_s2_query_dataframe,
|
64
64
|
mock_s2_retrieve_id,
|
65
65
|
]
|
66
66
|
|
@@ -129,8 +129,8 @@ def test_s2_agent_tools_assignment(request):
|
|
129
129
|
assert len(mock_tool_instance.tools) == 6
|
130
130
|
|
131
131
|
|
132
|
-
def
|
133
|
-
"""Test if the
|
132
|
+
def test_s2_query_dataframe_tool():
|
133
|
+
"""Test if the query_dataframe tool is correctly utilized by the agent."""
|
134
134
|
thread_id = "test_thread"
|
135
135
|
mock_state = Talk2Scholars(
|
136
136
|
messages=[HumanMessage(content="Query results for AI papers")]
|
@@ -144,7 +144,7 @@ def test_s2_query_results_tool():
|
|
144
144
|
"messages": [HumanMessage(content="Query results for AI papers")],
|
145
145
|
"last_displayed_papers": {},
|
146
146
|
"papers": {
|
147
|
-
"
|
147
|
+
"query_dataframe": "Mock Query Result"
|
148
148
|
}, # Ensure the expected key is inside 'papers'
|
149
149
|
"multi_papers": {},
|
150
150
|
}
|
@@ -159,7 +159,7 @@ def test_s2_query_results_tool():
|
|
159
159
|
}
|
160
160
|
},
|
161
161
|
)
|
162
|
-
assert "
|
162
|
+
assert "query_dataframe" in result["papers"]
|
163
163
|
assert mock_agent.invoke.called
|
164
164
|
|
165
165
|
|
@@ -5,8 +5,8 @@ Unit tests for S2 tools functionality.
|
|
5
5
|
# pylint: disable=redefined-outer-name
|
6
6
|
import pytest
|
7
7
|
from langgraph.types import Command
|
8
|
-
from ..tools.s2.
|
9
|
-
|
8
|
+
from ..tools.s2.display_dataframe import (
|
9
|
+
display_dataframe,
|
10
10
|
NoPapersFoundError as raised_error,
|
11
11
|
)
|
12
12
|
|
@@ -46,21 +46,21 @@ MOCK_STATE_PAPER = {
|
|
46
46
|
class TestS2Tools:
|
47
47
|
"""Unit tests for individual S2 tools"""
|
48
48
|
|
49
|
-
def
|
50
|
-
"""Verifies
|
49
|
+
def test_display_dataframe_empty_state(self, initial_state):
|
50
|
+
"""Verifies display_dataframe tool behavior when state is empty and raises an exception"""
|
51
51
|
with pytest.raises(
|
52
52
|
raised_error,
|
53
53
|
match="No papers found. A search/rec needs to be performed first.",
|
54
54
|
):
|
55
|
-
|
55
|
+
display_dataframe.invoke({"state": initial_state, "tool_call_id": "test123"})
|
56
56
|
|
57
|
-
def
|
58
|
-
"""Verifies
|
57
|
+
def test_display_dataframe_shows_papers(self, initial_state):
|
58
|
+
"""Verifies display_dataframe tool correctly returns papers from state"""
|
59
59
|
state = initial_state.copy()
|
60
60
|
state["last_displayed_papers"] = "papers"
|
61
61
|
state["papers"] = MOCK_STATE_PAPER
|
62
62
|
|
63
|
-
result =
|
63
|
+
result = display_dataframe.invoke(
|
64
64
|
input={"state": state, "tool_call_id": "test123"}
|
65
65
|
)
|
66
66
|
|
@@ -6,7 +6,7 @@ Unit tests for S2 tools functionality.
|
|
6
6
|
from unittest.mock import patch
|
7
7
|
from unittest.mock import MagicMock
|
8
8
|
import pytest
|
9
|
-
from ..tools.s2.
|
9
|
+
from ..tools.s2.query_dataframe import query_dataframe, NoPapersFoundError
|
10
10
|
|
11
11
|
|
12
12
|
@pytest.fixture
|
@@ -44,20 +44,20 @@ MOCK_STATE_PAPER = {
|
|
44
44
|
class TestS2Tools:
|
45
45
|
"""Unit tests for individual S2 tools"""
|
46
46
|
|
47
|
-
def
|
48
|
-
"""Tests
|
47
|
+
def test_query_dataframe_empty_state(self, initial_state):
|
48
|
+
"""Tests query_dataframe tool behavior when no papers are found."""
|
49
49
|
with pytest.raises(
|
50
50
|
NoPapersFoundError,
|
51
51
|
match="No papers found. A search needs to be performed first.",
|
52
52
|
):
|
53
|
-
|
53
|
+
query_dataframe.invoke(
|
54
54
|
{"question": "List all papers", "state": initial_state}
|
55
55
|
)
|
56
56
|
|
57
57
|
@patch(
|
58
|
-
"aiagents4pharma.talk2scholars.tools.s2.
|
58
|
+
"aiagents4pharma.talk2scholars.tools.s2.query_dataframe.create_pandas_dataframe_agent"
|
59
59
|
)
|
60
|
-
def
|
60
|
+
def test_query_dataframe_with_papers(self, mock_create_agent, initial_state):
|
61
61
|
"""Tests querying papers when data is available."""
|
62
62
|
state = initial_state.copy()
|
63
63
|
state["last_displayed_papers"] = "papers"
|
@@ -71,8 +71,8 @@ class TestS2Tools:
|
|
71
71
|
mock_agent # Mock the function returning the agent
|
72
72
|
)
|
73
73
|
|
74
|
-
# Ensure that the output of
|
75
|
-
result =
|
74
|
+
# Ensure that the output of query_dataframe is correctly structured
|
75
|
+
result = query_dataframe.invoke({"question": "List all papers", "state": state})
|
76
76
|
|
77
77
|
assert isinstance(result, str) # Ensure output is a string
|
78
78
|
assert result == "Mocked response" # Validate the expected response
|
@@ -29,11 +29,11 @@ def mock_tools_fixture():
|
|
29
29
|
"""Mock tools to prevent execution of real API calls."""
|
30
30
|
with (
|
31
31
|
mock.patch(
|
32
|
-
"aiagents4pharma.talk2scholars.tools.s2.
|
32
|
+
"aiagents4pharma.talk2scholars.tools.s2.display_dataframe.display_dataframe"
|
33
33
|
) as mock_s2_display,
|
34
34
|
mock.patch(
|
35
|
-
"aiagents4pharma.talk2scholars.tools.s2.
|
36
|
-
) as
|
35
|
+
"aiagents4pharma.talk2scholars.tools.s2.query_dataframe.query_dataframe"
|
36
|
+
) as mock_s2_query_dataframe,
|
37
37
|
mock.patch(
|
38
38
|
"aiagents4pharma.talk2scholars.tools.s2."
|
39
39
|
"retrieve_semantic_scholar_paper_id."
|
@@ -41,18 +41,18 @@ def mock_tools_fixture():
|
|
41
41
|
) as mock_s2_retrieve_id,
|
42
42
|
mock.patch(
|
43
43
|
"aiagents4pharma.talk2scholars.tools.zotero.zotero_read.zotero_read"
|
44
|
-
) as
|
44
|
+
) as mock_zotero_query_dataframe,
|
45
45
|
):
|
46
46
|
mock_s2_display.return_value = {"result": "Mock Display Result"}
|
47
|
-
|
47
|
+
mock_s2_query_dataframe.return_value = {"result": "Mock Query Result"}
|
48
48
|
mock_s2_retrieve_id.return_value = {"paper_id": "MockPaper123"}
|
49
|
-
|
49
|
+
mock_zotero_query_dataframe.return_value = {"result": "Mock Search Result"}
|
50
50
|
|
51
51
|
yield [
|
52
52
|
mock_s2_display,
|
53
|
-
|
53
|
+
mock_s2_query_dataframe,
|
54
54
|
mock_s2_retrieve_id,
|
55
|
-
|
55
|
+
mock_zotero_query_dataframe,
|
56
56
|
]
|
57
57
|
|
58
58
|
|
@@ -120,8 +120,8 @@ def test_zotero_agent_tools_assignment(request):
|
|
120
120
|
assert len(mock_tool_instance.tools) == 4
|
121
121
|
|
122
122
|
|
123
|
-
def
|
124
|
-
"""Test if the
|
123
|
+
def test_s2_query_dataframe_tool():
|
124
|
+
"""Test if the query_dataframe tool is correctly utilized by the agent."""
|
125
125
|
thread_id = "test_thread"
|
126
126
|
mock_state = Talk2Scholars(
|
127
127
|
messages=[HumanMessage(content="Query results for AI papers")]
|
@@ -135,7 +135,7 @@ def test_s2_query_results_tool():
|
|
135
135
|
"messages": [HumanMessage(content="Query results for AI papers")],
|
136
136
|
"last_displayed_papers": {},
|
137
137
|
"papers": {
|
138
|
-
"
|
138
|
+
"query_dataframe": "Mock Query Result"
|
139
139
|
}, # Ensure the expected key is inside 'papers'
|
140
140
|
"multi_papers": {},
|
141
141
|
}
|
@@ -150,7 +150,7 @@ def test_s2_query_results_tool():
|
|
150
150
|
}
|
151
151
|
},
|
152
152
|
)
|
153
|
-
assert "
|
153
|
+
assert "query_dataframe" in result["papers"]
|
154
154
|
assert mock_agent.invoke.called
|
155
155
|
|
156
156
|
|
@@ -344,9 +344,7 @@ class TestZoteroWrite:
|
|
344
344
|
@patch(
|
345
345
|
"aiagents4pharma.talk2scholars.tools.zotero.utils.write_helper.find_or_create_collection"
|
346
346
|
)
|
347
|
-
def test_zotero_write_invalid_collection(
|
348
|
-
self, mock_find, mock_fetch, mock_zotero
|
349
|
-
):
|
347
|
+
def test_zotero_write_invalid_collection(self, mock_find, mock_fetch, mock_zotero):
|
350
348
|
"""Saving to a nonexistent Zotero collection returns an error Command."""
|
351
349
|
sample = {"paper1": {"Title": "Test Paper"}}
|
352
350
|
mock_fetch.return_value = sample
|
@@ -383,9 +381,7 @@ class TestZoteroWrite:
|
|
383
381
|
@patch(
|
384
382
|
"aiagents4pharma.talk2scholars.tools.zotero.utils.write_helper.find_or_create_collection"
|
385
383
|
)
|
386
|
-
def test_zotero_write_success(
|
387
|
-
self, mock_find, mock_fetch, mock_hydra, mock_zotero
|
388
|
-
):
|
384
|
+
def test_zotero_write_success(self, mock_find, mock_fetch, mock_hydra, mock_zotero):
|
389
385
|
"""A valid approved save returns a success Command with summary."""
|
390
386
|
sample = {"paper1": {"Title": "Test Paper", "Authors": ["Test Author"]}}
|
391
387
|
mock_fetch.return_value = sample
|
@@ -426,11 +422,14 @@ class TestZoteroRead:
|
|
426
422
|
@pytest.fixture
|
427
423
|
def mock_hydra(self):
|
428
424
|
"""Fixture to mock hydra configuration."""
|
429
|
-
with
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
425
|
+
with (
|
426
|
+
patch(
|
427
|
+
"aiagents4pharma.talk2scholars.tools.zotero.utils.write_helper.hydra.initialize"
|
428
|
+
),
|
429
|
+
patch(
|
430
|
+
"aiagents4pharma.talk2scholars.tools.zotero.utils.write_helper.hydra.compose"
|
431
|
+
) as mock_compose,
|
432
|
+
):
|
434
433
|
cfg = MagicMock()
|
435
434
|
cfg.tools.zotero_read.user_id = "test_user"
|
436
435
|
cfg.tools.zotero_read.library_type = "user"
|
@@ -486,4 +485,4 @@ class TestZoteroRead:
|
|
486
485
|
|
487
486
|
assert result is not None
|
488
487
|
assert isinstance(result.update, dict)
|
489
|
-
assert "
|
488
|
+
assert "article_data" in result.update
|