aiagents4pharma 0.0.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/__init__.py +11 -0
- aiagents4pharma/talk2aiagents4pharma/.dockerignore +13 -0
- aiagents4pharma/talk2aiagents4pharma/Dockerfile +133 -0
- aiagents4pharma/talk2aiagents4pharma/README.md +1 -0
- aiagents4pharma/talk2aiagents4pharma/__init__.py +5 -0
- aiagents4pharma/talk2aiagents4pharma/agents/__init__.py +6 -0
- aiagents4pharma/talk2aiagents4pharma/agents/main_agent.py +70 -0
- aiagents4pharma/talk2aiagents4pharma/configs/__init__.py +5 -0
- aiagents4pharma/talk2aiagents4pharma/configs/agents/__init__.py +5 -0
- aiagents4pharma/talk2aiagents4pharma/configs/agents/main_agent/default.yaml +29 -0
- aiagents4pharma/talk2aiagents4pharma/configs/app/__init__.py +0 -0
- aiagents4pharma/talk2aiagents4pharma/configs/app/frontend/__init__.py +0 -0
- aiagents4pharma/talk2aiagents4pharma/configs/app/frontend/default.yaml +102 -0
- aiagents4pharma/talk2aiagents4pharma/configs/config.yaml +4 -0
- aiagents4pharma/talk2aiagents4pharma/docker-compose/cpu/.env.example +23 -0
- aiagents4pharma/talk2aiagents4pharma/docker-compose/cpu/docker-compose.yml +93 -0
- aiagents4pharma/talk2aiagents4pharma/docker-compose/gpu/.env.example +23 -0
- aiagents4pharma/talk2aiagents4pharma/docker-compose/gpu/docker-compose.yml +108 -0
- aiagents4pharma/talk2aiagents4pharma/install.md +154 -0
- aiagents4pharma/talk2aiagents4pharma/states/__init__.py +5 -0
- aiagents4pharma/talk2aiagents4pharma/states/state_talk2aiagents4pharma.py +18 -0
- aiagents4pharma/talk2aiagents4pharma/tests/__init__.py +3 -0
- aiagents4pharma/talk2aiagents4pharma/tests/test_main_agent.py +312 -0
- aiagents4pharma/talk2biomodels/.dockerignore +13 -0
- aiagents4pharma/talk2biomodels/Dockerfile +104 -0
- aiagents4pharma/talk2biomodels/README.md +1 -0
- aiagents4pharma/talk2biomodels/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/agents/__init__.py +6 -0
- aiagents4pharma/talk2biomodels/agents/t2b_agent.py +104 -0
- aiagents4pharma/talk2biomodels/api/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/api/ols.py +75 -0
- aiagents4pharma/talk2biomodels/api/uniprot.py +36 -0
- aiagents4pharma/talk2biomodels/configs/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/configs/agents/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/configs/agents/t2b_agent/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/configs/agents/t2b_agent/default.yaml +14 -0
- aiagents4pharma/talk2biomodels/configs/app/__init__.py +0 -0
- aiagents4pharma/talk2biomodels/configs/app/frontend/__init__.py +0 -0
- aiagents4pharma/talk2biomodels/configs/app/frontend/default.yaml +72 -0
- aiagents4pharma/talk2biomodels/configs/config.yaml +7 -0
- aiagents4pharma/talk2biomodels/configs/tools/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/configs/tools/ask_question/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/configs/tools/ask_question/default.yaml +30 -0
- aiagents4pharma/talk2biomodels/configs/tools/custom_plotter/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/configs/tools/custom_plotter/default.yaml +8 -0
- aiagents4pharma/talk2biomodels/configs/tools/get_annotation/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/configs/tools/get_annotation/default.yaml +8 -0
- aiagents4pharma/talk2biomodels/install.md +63 -0
- aiagents4pharma/talk2biomodels/models/__init__.py +5 -0
- aiagents4pharma/talk2biomodels/models/basico_model.py +125 -0
- aiagents4pharma/talk2biomodels/models/sys_bio_model.py +60 -0
- aiagents4pharma/talk2biomodels/states/__init__.py +6 -0
- aiagents4pharma/talk2biomodels/states/state_talk2biomodels.py +49 -0
- aiagents4pharma/talk2biomodels/tests/BIOMD0000000449_url.xml +1585 -0
- aiagents4pharma/talk2biomodels/tests/__init__.py +3 -0
- aiagents4pharma/talk2biomodels/tests/article_on_model_537.pdf +0 -0
- aiagents4pharma/talk2biomodels/tests/test_api.py +31 -0
- aiagents4pharma/talk2biomodels/tests/test_ask_question.py +42 -0
- aiagents4pharma/talk2biomodels/tests/test_basico_model.py +67 -0
- aiagents4pharma/talk2biomodels/tests/test_get_annotation.py +190 -0
- aiagents4pharma/talk2biomodels/tests/test_getmodelinfo.py +92 -0
- aiagents4pharma/talk2biomodels/tests/test_integration.py +116 -0
- aiagents4pharma/talk2biomodels/tests/test_load_biomodel.py +35 -0
- aiagents4pharma/talk2biomodels/tests/test_param_scan.py +71 -0
- aiagents4pharma/talk2biomodels/tests/test_query_article.py +184 -0
- aiagents4pharma/talk2biomodels/tests/test_save_model.py +47 -0
- aiagents4pharma/talk2biomodels/tests/test_search_models.py +35 -0
- aiagents4pharma/talk2biomodels/tests/test_simulate_model.py +44 -0
- aiagents4pharma/talk2biomodels/tests/test_steady_state.py +86 -0
- aiagents4pharma/talk2biomodels/tests/test_sys_bio_model.py +67 -0
- aiagents4pharma/talk2biomodels/tools/__init__.py +17 -0
- aiagents4pharma/talk2biomodels/tools/ask_question.py +125 -0
- aiagents4pharma/talk2biomodels/tools/custom_plotter.py +165 -0
- aiagents4pharma/talk2biomodels/tools/get_annotation.py +342 -0
- aiagents4pharma/talk2biomodels/tools/get_modelinfo.py +159 -0
- aiagents4pharma/talk2biomodels/tools/load_arguments.py +134 -0
- aiagents4pharma/talk2biomodels/tools/load_biomodel.py +44 -0
- aiagents4pharma/talk2biomodels/tools/parameter_scan.py +310 -0
- aiagents4pharma/talk2biomodels/tools/query_article.py +64 -0
- aiagents4pharma/talk2biomodels/tools/save_model.py +98 -0
- aiagents4pharma/talk2biomodels/tools/search_models.py +96 -0
- aiagents4pharma/talk2biomodels/tools/simulate_model.py +137 -0
- aiagents4pharma/talk2biomodels/tools/steady_state.py +187 -0
- aiagents4pharma/talk2biomodels/tools/utils.py +23 -0
- aiagents4pharma/talk2cells/README.md +1 -0
- aiagents4pharma/talk2cells/__init__.py +5 -0
- aiagents4pharma/talk2cells/agents/__init__.py +6 -0
- aiagents4pharma/talk2cells/agents/scp_agent.py +87 -0
- aiagents4pharma/talk2cells/states/__init__.py +6 -0
- aiagents4pharma/talk2cells/states/state_talk2cells.py +15 -0
- aiagents4pharma/talk2cells/tests/scp_agent/test_scp_agent.py +22 -0
- aiagents4pharma/talk2cells/tools/__init__.py +6 -0
- aiagents4pharma/talk2cells/tools/scp_agent/__init__.py +6 -0
- aiagents4pharma/talk2cells/tools/scp_agent/display_studies.py +27 -0
- aiagents4pharma/talk2cells/tools/scp_agent/search_studies.py +78 -0
- aiagents4pharma/talk2knowledgegraphs/.dockerignore +13 -0
- aiagents4pharma/talk2knowledgegraphs/Dockerfile +131 -0
- aiagents4pharma/talk2knowledgegraphs/README.md +1 -0
- aiagents4pharma/talk2knowledgegraphs/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/agents/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/agents/t2kg_agent.py +99 -0
- aiagents4pharma/talk2knowledgegraphs/configs/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/configs/agents/t2kg_agent/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/agents/t2kg_agent/default.yaml +62 -0
- aiagents4pharma/talk2knowledgegraphs/configs/app/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/configs/app/frontend/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/app/frontend/default.yaml +79 -0
- aiagents4pharma/talk2knowledgegraphs/configs/config.yaml +13 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/graphrag_reasoning/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/graphrag_reasoning/default.yaml +24 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/multimodal_subgraph_extraction/__init__.py +0 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/multimodal_subgraph_extraction/default.yaml +33 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_extraction/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_extraction/default.yaml +43 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_summarization/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/tools/subgraph_summarization/default.yaml +9 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/database/milvus/__init__.py +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/database/milvus/default.yaml +61 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/ols_terms/default.yaml +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/reactome_pathways/default.yaml +3 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/enrichments/uniprot_proteins/default.yaml +6 -0
- aiagents4pharma/talk2knowledgegraphs/configs/utils/pubchem_utils/default.yaml +5 -0
- aiagents4pharma/talk2knowledgegraphs/datasets/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/datasets/biobridge_primekg.py +607 -0
- aiagents4pharma/talk2knowledgegraphs/datasets/dataset.py +25 -0
- aiagents4pharma/talk2knowledgegraphs/datasets/primekg.py +212 -0
- aiagents4pharma/talk2knowledgegraphs/datasets/starkqa_primekg.py +210 -0
- aiagents4pharma/talk2knowledgegraphs/docker-compose/cpu/.env.example +23 -0
- aiagents4pharma/talk2knowledgegraphs/docker-compose/cpu/docker-compose.yml +93 -0
- aiagents4pharma/talk2knowledgegraphs/docker-compose/gpu/.env.example +23 -0
- aiagents4pharma/talk2knowledgegraphs/docker-compose/gpu/docker-compose.yml +108 -0
- aiagents4pharma/talk2knowledgegraphs/entrypoint.sh +180 -0
- aiagents4pharma/talk2knowledgegraphs/install.md +165 -0
- aiagents4pharma/talk2knowledgegraphs/milvus_data_dump.py +886 -0
- aiagents4pharma/talk2knowledgegraphs/states/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/states/state_talk2knowledgegraphs.py +40 -0
- aiagents4pharma/talk2knowledgegraphs/tests/__init__.py +0 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_agents_t2kg_agent.py +318 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_biobridge_primekg.py +248 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_dataset.py +33 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_primekg.py +86 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_datasets_starkqa_primekg.py +125 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_tools_graphrag_reasoning.py +257 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_tools_milvus_multimodal_subgraph_extraction.py +1444 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_tools_multimodal_subgraph_extraction.py +159 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_tools_subgraph_extraction.py +152 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_tools_subgraph_summarization.py +201 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_database_milvus_connection_manager.py +812 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_embeddings.py +51 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_huggingface.py +49 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_nim_molmim.py +59 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_ollama.py +63 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_embeddings_sentencetransformer.py +47 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_enrichments.py +40 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ollama.py +94 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_ols.py +70 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_pubchem.py +45 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_reactome.py +44 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_enrichments_uniprot.py +48 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_extractions_milvus_multimodal_pcst.py +759 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_kg_utils.py +78 -0
- aiagents4pharma/talk2knowledgegraphs/tests/test_utils_pubchem_utils.py +123 -0
- aiagents4pharma/talk2knowledgegraphs/tools/__init__.py +11 -0
- aiagents4pharma/talk2knowledgegraphs/tools/graphrag_reasoning.py +138 -0
- aiagents4pharma/talk2knowledgegraphs/tools/load_arguments.py +22 -0
- aiagents4pharma/talk2knowledgegraphs/tools/milvus_multimodal_subgraph_extraction.py +965 -0
- aiagents4pharma/talk2knowledgegraphs/tools/multimodal_subgraph_extraction.py +374 -0
- aiagents4pharma/talk2knowledgegraphs/tools/subgraph_extraction.py +291 -0
- aiagents4pharma/talk2knowledgegraphs/tools/subgraph_summarization.py +123 -0
- aiagents4pharma/talk2knowledgegraphs/utils/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/utils/database/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/utils/database/milvus_connection_manager.py +586 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/embeddings.py +81 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/huggingface.py +111 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/nim_molmim.py +54 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/ollama.py +87 -0
- aiagents4pharma/talk2knowledgegraphs/utils/embeddings/sentence_transformer.py +73 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/__init__.py +12 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/enrichments.py +37 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ollama.py +129 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/ols_terms.py +89 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/pubchem_strings.py +78 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/reactome_pathways.py +71 -0
- aiagents4pharma/talk2knowledgegraphs/utils/enrichments/uniprot_proteins.py +98 -0
- aiagents4pharma/talk2knowledgegraphs/utils/extractions/__init__.py +5 -0
- aiagents4pharma/talk2knowledgegraphs/utils/extractions/milvus_multimodal_pcst.py +762 -0
- aiagents4pharma/talk2knowledgegraphs/utils/extractions/multimodal_pcst.py +298 -0
- aiagents4pharma/talk2knowledgegraphs/utils/extractions/pcst.py +229 -0
- aiagents4pharma/talk2knowledgegraphs/utils/kg_utils.py +67 -0
- aiagents4pharma/talk2knowledgegraphs/utils/pubchem_utils.py +104 -0
- aiagents4pharma/talk2scholars/.dockerignore +13 -0
- aiagents4pharma/talk2scholars/Dockerfile +104 -0
- aiagents4pharma/talk2scholars/README.md +1 -0
- aiagents4pharma/talk2scholars/__init__.py +7 -0
- aiagents4pharma/talk2scholars/agents/__init__.py +13 -0
- aiagents4pharma/talk2scholars/agents/main_agent.py +89 -0
- aiagents4pharma/talk2scholars/agents/paper_download_agent.py +96 -0
- aiagents4pharma/talk2scholars/agents/pdf_agent.py +101 -0
- aiagents4pharma/talk2scholars/agents/s2_agent.py +135 -0
- aiagents4pharma/talk2scholars/agents/zotero_agent.py +127 -0
- aiagents4pharma/talk2scholars/configs/__init__.py +7 -0
- aiagents4pharma/talk2scholars/configs/agents/__init__.py +7 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/__init__.py +7 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/main_agent/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/main_agent/default.yaml +52 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/paper_download_agent/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/paper_download_agent/default.yaml +19 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/pdf_agent/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/pdf_agent/default.yaml +19 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/s2_agent/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/s2_agent/default.yaml +44 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/zotero_agent/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/agents/talk2scholars/zotero_agent/default.yaml +19 -0
- aiagents4pharma/talk2scholars/configs/app/__init__.py +7 -0
- aiagents4pharma/talk2scholars/configs/app/frontend/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/app/frontend/default.yaml +72 -0
- aiagents4pharma/talk2scholars/configs/config.yaml +16 -0
- aiagents4pharma/talk2scholars/configs/tools/__init__.py +21 -0
- aiagents4pharma/talk2scholars/configs/tools/multi_paper_recommendation/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/multi_paper_recommendation/default.yaml +26 -0
- aiagents4pharma/talk2scholars/configs/tools/paper_download/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/paper_download/default.yaml +124 -0
- aiagents4pharma/talk2scholars/configs/tools/question_and_answer/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/question_and_answer/default.yaml +62 -0
- aiagents4pharma/talk2scholars/configs/tools/retrieve_semantic_scholar_paper_id/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/retrieve_semantic_scholar_paper_id/default.yaml +12 -0
- aiagents4pharma/talk2scholars/configs/tools/search/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/search/default.yaml +26 -0
- aiagents4pharma/talk2scholars/configs/tools/single_paper_recommendation/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/single_paper_recommendation/default.yaml +26 -0
- aiagents4pharma/talk2scholars/configs/tools/zotero_read/__init__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/zotero_read/default.yaml +57 -0
- aiagents4pharma/talk2scholars/configs/tools/zotero_write/__inti__.py +3 -0
- aiagents4pharma/talk2scholars/configs/tools/zotero_write/default.yaml +55 -0
- aiagents4pharma/talk2scholars/docker-compose/cpu/.env.example +21 -0
- aiagents4pharma/talk2scholars/docker-compose/cpu/docker-compose.yml +90 -0
- aiagents4pharma/talk2scholars/docker-compose/gpu/.env.example +21 -0
- aiagents4pharma/talk2scholars/docker-compose/gpu/docker-compose.yml +105 -0
- aiagents4pharma/talk2scholars/install.md +122 -0
- aiagents4pharma/talk2scholars/state/__init__.py +7 -0
- aiagents4pharma/talk2scholars/state/state_talk2scholars.py +98 -0
- aiagents4pharma/talk2scholars/tests/__init__.py +3 -0
- aiagents4pharma/talk2scholars/tests/test_agents_main_agent.py +256 -0
- aiagents4pharma/talk2scholars/tests/test_agents_paper_agents_download_agent.py +139 -0
- aiagents4pharma/talk2scholars/tests/test_agents_pdf_agent.py +114 -0
- aiagents4pharma/talk2scholars/tests/test_agents_s2_agent.py +198 -0
- aiagents4pharma/talk2scholars/tests/test_agents_zotero_agent.py +160 -0
- aiagents4pharma/talk2scholars/tests/test_s2_tools_display_dataframe.py +91 -0
- aiagents4pharma/talk2scholars/tests/test_s2_tools_query_dataframe.py +191 -0
- aiagents4pharma/talk2scholars/tests/test_states_state.py +38 -0
- aiagents4pharma/talk2scholars/tests/test_tools_paper_downloader.py +507 -0
- aiagents4pharma/talk2scholars/tests/test_tools_question_and_answer_tool.py +105 -0
- aiagents4pharma/talk2scholars/tests/test_tools_s2_multi.py +307 -0
- aiagents4pharma/talk2scholars/tests/test_tools_s2_retrieve.py +67 -0
- aiagents4pharma/talk2scholars/tests/test_tools_s2_search.py +286 -0
- aiagents4pharma/talk2scholars/tests/test_tools_s2_single.py +298 -0
- aiagents4pharma/talk2scholars/tests/test_utils_arxiv_downloader.py +469 -0
- aiagents4pharma/talk2scholars/tests/test_utils_base_paper_downloader.py +598 -0
- aiagents4pharma/talk2scholars/tests/test_utils_biorxiv_downloader.py +669 -0
- aiagents4pharma/talk2scholars/tests/test_utils_medrxiv_downloader.py +500 -0
- aiagents4pharma/talk2scholars/tests/test_utils_nvidia_nim_reranker.py +117 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_answer_formatter.py +67 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_batch_processor.py +92 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_collection_manager.py +173 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_document_processor.py +68 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_generate_answer.py +72 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_gpu_detection.py +129 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_paper_loader.py +116 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_rag_pipeline.py +88 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_retrieve_chunks.py +190 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_singleton_manager.py +159 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_vector_normalization.py +121 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pdf_vector_store.py +406 -0
- aiagents4pharma/talk2scholars/tests/test_utils_pubmed_downloader.py +1007 -0
- aiagents4pharma/talk2scholars/tests/test_utils_read_helper_utils.py +106 -0
- aiagents4pharma/talk2scholars/tests/test_utils_s2_utils_ext_ids.py +403 -0
- aiagents4pharma/talk2scholars/tests/test_utils_tool_helper_utils.py +85 -0
- aiagents4pharma/talk2scholars/tests/test_utils_zotero_human_in_the_loop.py +266 -0
- aiagents4pharma/talk2scholars/tests/test_utils_zotero_path.py +496 -0
- aiagents4pharma/talk2scholars/tests/test_utils_zotero_pdf_downloader_utils.py +46 -0
- aiagents4pharma/talk2scholars/tests/test_utils_zotero_read.py +743 -0
- aiagents4pharma/talk2scholars/tests/test_utils_zotero_write.py +151 -0
- aiagents4pharma/talk2scholars/tools/__init__.py +9 -0
- aiagents4pharma/talk2scholars/tools/paper_download/__init__.py +12 -0
- aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py +442 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/__init__.py +22 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/arxiv_downloader.py +207 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/base_paper_downloader.py +336 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/biorxiv_downloader.py +313 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/medrxiv_downloader.py +196 -0
- aiagents4pharma/talk2scholars/tools/paper_download/utils/pubmed_downloader.py +323 -0
- aiagents4pharma/talk2scholars/tools/pdf/__init__.py +7 -0
- aiagents4pharma/talk2scholars/tools/pdf/question_and_answer.py +170 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/__init__.py +37 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/answer_formatter.py +62 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/batch_processor.py +198 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/collection_manager.py +172 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/document_processor.py +76 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/generate_answer.py +97 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/get_vectorstore.py +59 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/gpu_detection.py +150 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/nvidia_nim_reranker.py +97 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/paper_loader.py +123 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/rag_pipeline.py +113 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/retrieve_chunks.py +197 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/singleton_manager.py +140 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/tool_helper.py +86 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/vector_normalization.py +150 -0
- aiagents4pharma/talk2scholars/tools/pdf/utils/vector_store.py +327 -0
- aiagents4pharma/talk2scholars/tools/s2/__init__.py +21 -0
- aiagents4pharma/talk2scholars/tools/s2/display_dataframe.py +110 -0
- aiagents4pharma/talk2scholars/tools/s2/multi_paper_rec.py +111 -0
- aiagents4pharma/talk2scholars/tools/s2/query_dataframe.py +233 -0
- aiagents4pharma/talk2scholars/tools/s2/retrieve_semantic_scholar_paper_id.py +128 -0
- aiagents4pharma/talk2scholars/tools/s2/search.py +101 -0
- aiagents4pharma/talk2scholars/tools/s2/single_paper_rec.py +102 -0
- aiagents4pharma/talk2scholars/tools/s2/utils/__init__.py +5 -0
- aiagents4pharma/talk2scholars/tools/s2/utils/multi_helper.py +223 -0
- aiagents4pharma/talk2scholars/tools/s2/utils/search_helper.py +205 -0
- aiagents4pharma/talk2scholars/tools/s2/utils/single_helper.py +216 -0
- aiagents4pharma/talk2scholars/tools/zotero/__init__.py +7 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/__init__.py +7 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/read_helper.py +270 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/review_helper.py +74 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/write_helper.py +194 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_path.py +180 -0
- aiagents4pharma/talk2scholars/tools/zotero/utils/zotero_pdf_downloader.py +133 -0
- aiagents4pharma/talk2scholars/tools/zotero/zotero_read.py +105 -0
- aiagents4pharma/talk2scholars/tools/zotero/zotero_review.py +162 -0
- aiagents4pharma/talk2scholars/tools/zotero/zotero_write.py +91 -0
- aiagents4pharma-0.0.0.dist-info/METADATA +335 -0
- aiagents4pharma-0.0.0.dist-info/RECORD +336 -0
- aiagents4pharma-0.0.0.dist-info/WHEEL +4 -0
- aiagents4pharma-0.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for S2 tools functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from types import SimpleNamespace
|
|
7
|
+
|
|
8
|
+
import hydra
|
|
9
|
+
import pytest
|
|
10
|
+
import requests
|
|
11
|
+
from langchain_core.messages import ToolMessage
|
|
12
|
+
from langgraph.types import Command
|
|
13
|
+
|
|
14
|
+
from aiagents4pharma.talk2scholars.tools.s2.multi_paper_rec import (
|
|
15
|
+
get_multi_paper_recommendations,
|
|
16
|
+
)
|
|
17
|
+
from aiagents4pharma.talk2scholars.tools.s2.utils import multi_helper
|
|
18
|
+
|
|
19
|
+
# --- Dummy Hydra Config Setup ---
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class DummyHydraContext:
|
|
23
|
+
"""dummy context manager for mocking Hydra's initialize and compose functions."""
|
|
24
|
+
|
|
25
|
+
def __enter__(self):
|
|
26
|
+
"""enter function that returns None."""
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
def __exit__(self, exc_type, exc_val, traceback):
|
|
30
|
+
"""exit function that does nothing."""
|
|
31
|
+
return None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Create a dummy configuration that mimics the expected hydra config.
|
|
35
|
+
dummy_config = SimpleNamespace(
|
|
36
|
+
tools=SimpleNamespace(
|
|
37
|
+
multi_paper_recommendation=SimpleNamespace(
|
|
38
|
+
api_endpoint="http://dummy.endpoint/multi",
|
|
39
|
+
headers={"Content-Type": "application/json"},
|
|
40
|
+
api_fields=["paperId", "title", "authors"],
|
|
41
|
+
request_timeout=10,
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# --- Dummy Response Classes and Functions for requests.post ---
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class DummyResponse:
|
|
50
|
+
"""A dummy response class for mocking HTTP responses."""
|
|
51
|
+
|
|
52
|
+
def __init__(self, json_data, status_code=200):
|
|
53
|
+
"""Initialize a DummyResponse with the given JSON data and status code."""
|
|
54
|
+
self._json_data = json_data
|
|
55
|
+
self.status_code = status_code
|
|
56
|
+
|
|
57
|
+
def json(self):
|
|
58
|
+
"""Return the JSON data from the response."""
|
|
59
|
+
return self._json_data
|
|
60
|
+
|
|
61
|
+
def raise_for_status(self):
|
|
62
|
+
"""raise an HTTP error for status codes >= 400."""
|
|
63
|
+
if self.status_code >= 400:
|
|
64
|
+
raise requests.HTTPError("HTTP Error")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_dummy_response_no_error():
|
|
68
|
+
"""Test that raise_for_status does not raise an exception for a successful response."""
|
|
69
|
+
# Create a DummyResponse with a successful status code.
|
|
70
|
+
response = DummyResponse({"data": "success"}, status_code=200)
|
|
71
|
+
# Calling raise_for_status should not raise an exception and should return None.
|
|
72
|
+
assert response.raise_for_status() is None
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_dummy_response_raise_error():
|
|
76
|
+
"""Test that raise_for_status raises an exception for a failing response."""
|
|
77
|
+
# Create a DummyResponse with a failing status code.
|
|
78
|
+
response = DummyResponse({"error": "fail"}, status_code=400)
|
|
79
|
+
# Calling raise_for_status should raise an HTTPError.
|
|
80
|
+
with pytest.raises(requests.HTTPError):
|
|
81
|
+
response.raise_for_status()
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def dummy_requests_post_success(url, headers, params, data, timeout):
|
|
85
|
+
"""dummy_requests_post_success"""
|
|
86
|
+
# Record call parameters for assertions.
|
|
87
|
+
dummy_requests_post_success.called_url = url
|
|
88
|
+
dummy_requests_post_success.called_headers = headers
|
|
89
|
+
dummy_requests_post_success.called_params = params
|
|
90
|
+
dummy_requests_post_success.called_data = data
|
|
91
|
+
dummy_requests_post_success.called_timeout = timeout
|
|
92
|
+
|
|
93
|
+
# Simulate a valid API response with three recommended papers;
|
|
94
|
+
# one paper missing authors should be filtered out.
|
|
95
|
+
dummy_data = {
|
|
96
|
+
"recommendedPapers": [
|
|
97
|
+
{
|
|
98
|
+
"paperId": "paperA",
|
|
99
|
+
"title": "Multi Rec Paper A",
|
|
100
|
+
"authors": [{"name": "Author X", "authorId": "AX"}],
|
|
101
|
+
"year": 2019,
|
|
102
|
+
"citationCount": 12,
|
|
103
|
+
"url": "http://paperA",
|
|
104
|
+
"externalIds": {"ArXiv": "arxivA"},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"paperId": "paperB",
|
|
108
|
+
"title": "Multi Rec Paper B",
|
|
109
|
+
"authors": [{"name": "Author Y", "authorId": "AY"}],
|
|
110
|
+
"year": 2020,
|
|
111
|
+
"citationCount": 18,
|
|
112
|
+
"url": "http://paperB",
|
|
113
|
+
"externalIds": {},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"paperId": "paperC",
|
|
117
|
+
"title": "Multi Rec Paper C",
|
|
118
|
+
"authors": None, # This paper should be filtered out.
|
|
119
|
+
"year": 2021,
|
|
120
|
+
"citationCount": 25,
|
|
121
|
+
"url": "http://paperC",
|
|
122
|
+
"externalIds": {"ArXiv": "arxivC"},
|
|
123
|
+
},
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
return DummyResponse(dummy_data)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def dummy_requests_post_unexpected(url, headers, params, data, timeout):
|
|
130
|
+
"""dummy_requests_post_unexpected"""
|
|
131
|
+
dummy_requests_post_unexpected.called_url = url
|
|
132
|
+
dummy_requests_post_unexpected.called_headers = headers
|
|
133
|
+
dummy_requests_post_unexpected.called_params = params
|
|
134
|
+
dummy_requests_post_unexpected.called_data = data
|
|
135
|
+
dummy_requests_post_unexpected.called_timeout = timeout
|
|
136
|
+
# Simulate a response missing the 'recommendedPapers' key.
|
|
137
|
+
return DummyResponse({"error": "Invalid format"})
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def dummy_requests_post_no_recs(url, headers, params, data, timeout):
|
|
141
|
+
"""dummy_requests_post_no_recs"""
|
|
142
|
+
dummy_requests_post_no_recs.called_url = url
|
|
143
|
+
dummy_requests_post_no_recs.called_headers = headers
|
|
144
|
+
dummy_requests_post_no_recs.called_params = params
|
|
145
|
+
dummy_requests_post_no_recs.called_data = data
|
|
146
|
+
dummy_requests_post_no_recs.called_timeout = timeout
|
|
147
|
+
# Simulate a response with an empty recommendations list.
|
|
148
|
+
return DummyResponse({"recommendedPapers": []})
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def dummy_requests_post_exception(url, headers, params, data, timeout):
|
|
152
|
+
"""dummy_requests_post_exception"""
|
|
153
|
+
dummy_requests_post_exception.called_url = url
|
|
154
|
+
dummy_requests_post_exception.called_headers = headers
|
|
155
|
+
dummy_requests_post_exception.called_params = params
|
|
156
|
+
dummy_requests_post_exception.called_data = data
|
|
157
|
+
dummy_requests_post_exception.called_timeout = timeout
|
|
158
|
+
# Simulate a network exception.
|
|
159
|
+
raise requests.exceptions.RequestException("Connection error")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# --- Pytest Fixture to Patch Hydra ---
|
|
163
|
+
@pytest.fixture(autouse=True)
|
|
164
|
+
def patch_hydra(monkeypatch):
|
|
165
|
+
"""Patch Hydra's initialize and compose functions to return dummy objects."""
|
|
166
|
+
# Patch hydra.initialize to return our dummy context manager.
|
|
167
|
+
monkeypatch.setattr(hydra, "initialize", lambda version_base, config_path: DummyHydraContext())
|
|
168
|
+
# Patch hydra.compose to return our dummy config.
|
|
169
|
+
monkeypatch.setattr(hydra, "compose", lambda config_name, overrides: dummy_config)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
# --- Test Cases ---
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def test_multi_paper_rec_success(monkeypatch):
|
|
176
|
+
"""
|
|
177
|
+
Test that get_multi_paper_recommendations returns a valid Command object
|
|
178
|
+
when the API response is successful. Also, ensure that recommendations missing
|
|
179
|
+
required fields (like authors) are filtered out.
|
|
180
|
+
"""
|
|
181
|
+
monkeypatch.setattr(requests, "post", dummy_requests_post_success)
|
|
182
|
+
|
|
183
|
+
tool_call_id = "test_tool_call_id"
|
|
184
|
+
input_data = {
|
|
185
|
+
"paper_ids": ["p1", "p2"],
|
|
186
|
+
"tool_call_id": tool_call_id,
|
|
187
|
+
"limit": 2,
|
|
188
|
+
"year": "2020",
|
|
189
|
+
}
|
|
190
|
+
# Call the tool using .run() with a dictionary input.
|
|
191
|
+
result = get_multi_paper_recommendations.run(input_data)
|
|
192
|
+
|
|
193
|
+
# Validate that the result is a Command with the expected update structure.
|
|
194
|
+
assert isinstance(result, Command)
|
|
195
|
+
update = result.update
|
|
196
|
+
assert "multi_papers" in update
|
|
197
|
+
|
|
198
|
+
papers = update["multi_papers"]
|
|
199
|
+
# Papers with valid 'title' and 'authors' should be included.
|
|
200
|
+
assert "paperA" in papers
|
|
201
|
+
assert "paperB" in papers
|
|
202
|
+
# Paper "paperC" is missing authors and should be filtered out.
|
|
203
|
+
assert "paperC" not in papers
|
|
204
|
+
|
|
205
|
+
# Check that a ToolMessage is included in the messages.
|
|
206
|
+
messages = update.get("messages", [])
|
|
207
|
+
assert len(messages) == 1
|
|
208
|
+
msg = messages[0]
|
|
209
|
+
assert isinstance(msg, ToolMessage)
|
|
210
|
+
assert "Recommendations based on multiple papers were successful" in msg.content
|
|
211
|
+
|
|
212
|
+
# Verify that the correct parameters were sent to requests.post.
|
|
213
|
+
called_params = dummy_requests_post_success.called_params
|
|
214
|
+
assert called_params["limit"] == 2 # Should be min(limit, 500)
|
|
215
|
+
assert called_params["fields"] == "paperId,title,authors"
|
|
216
|
+
# The year parameter should be present.
|
|
217
|
+
assert called_params["year"] == "2020"
|
|
218
|
+
|
|
219
|
+
# Also check the payload sent in the data.
|
|
220
|
+
sent_payload = json.loads(dummy_requests_post_success.called_data)
|
|
221
|
+
assert sent_payload["positivePaperIds"] == ["p1", "p2"]
|
|
222
|
+
assert sent_payload["negativePaperIds"] == []
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def test_multi_paper_rec_unexpected_format(monkeypatch):
|
|
226
|
+
"""
|
|
227
|
+
Test that get_multi_paper_recommendations raises a RuntimeError when the API
|
|
228
|
+
response does not include the expected 'recommendedPapers' key.
|
|
229
|
+
"""
|
|
230
|
+
monkeypatch.setattr(requests, "post", dummy_requests_post_unexpected)
|
|
231
|
+
tool_call_id = "test_tool_call_id"
|
|
232
|
+
input_data = {
|
|
233
|
+
"paper_ids": ["p1", "p2"],
|
|
234
|
+
"tool_call_id": tool_call_id,
|
|
235
|
+
}
|
|
236
|
+
with pytest.raises(
|
|
237
|
+
RuntimeError,
|
|
238
|
+
match=(
|
|
239
|
+
"Unexpected response from Semantic Scholar API. The results could not be "
|
|
240
|
+
"retrieved due to an unexpected format. "
|
|
241
|
+
"Please modify your search query and try again."
|
|
242
|
+
),
|
|
243
|
+
):
|
|
244
|
+
get_multi_paper_recommendations.run(input_data)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def test_multi_paper_rec_no_recommendations(monkeypatch):
|
|
248
|
+
"""
|
|
249
|
+
Test that get_multi_paper_recommendations raises a RuntimeError when the API
|
|
250
|
+
returns no recommendations.
|
|
251
|
+
"""
|
|
252
|
+
monkeypatch.setattr(requests, "post", dummy_requests_post_no_recs)
|
|
253
|
+
tool_call_id = "test_tool_call_id"
|
|
254
|
+
input_data = {
|
|
255
|
+
"paper_ids": ["p1", "p2"],
|
|
256
|
+
"tool_call_id": tool_call_id,
|
|
257
|
+
}
|
|
258
|
+
with pytest.raises(
|
|
259
|
+
RuntimeError,
|
|
260
|
+
match=(
|
|
261
|
+
"No recommendations were found for your query. Consider refining your search "
|
|
262
|
+
"by using more specific keywords or different terms."
|
|
263
|
+
),
|
|
264
|
+
):
|
|
265
|
+
get_multi_paper_recommendations.run(input_data)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def test_multi_paper_rec_requests_exception(monkeypatch):
|
|
269
|
+
"""
|
|
270
|
+
Test that get_multi_paper_recommendations raises a RuntimeError when requests.post
|
|
271
|
+
throws an exception.
|
|
272
|
+
"""
|
|
273
|
+
monkeypatch.setattr(requests, "post", dummy_requests_post_exception)
|
|
274
|
+
tool_call_id = "test_tool_call_id"
|
|
275
|
+
input_data = {
|
|
276
|
+
"paper_ids": ["p1", "p2"],
|
|
277
|
+
"tool_call_id": tool_call_id,
|
|
278
|
+
}
|
|
279
|
+
with pytest.raises(
|
|
280
|
+
RuntimeError,
|
|
281
|
+
match="Failed to connect to Semantic Scholar API after 10 attempts."
|
|
282
|
+
"Please retry the same query.",
|
|
283
|
+
):
|
|
284
|
+
get_multi_paper_recommendations.run(input_data)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def test_multi_paper_rec_no_response(monkeypatch):
|
|
288
|
+
"""
|
|
289
|
+
Test that get_multi_paper_recommendations raises a RuntimeError
|
|
290
|
+
when no response is obtained. This is simulated by patching 'range'
|
|
291
|
+
in the module namespace of multi_helper to return an empty iterator,
|
|
292
|
+
so that the for loop in _fetch_recommendations never iterates and
|
|
293
|
+
self.response remains None.
|
|
294
|
+
"""
|
|
295
|
+
# Inject a patched 'range' into the multi_helper module's dictionary.
|
|
296
|
+
monkeypatch.setitem(multi_helper.__dict__, "range", lambda x: iter([]))
|
|
297
|
+
|
|
298
|
+
tool_call_id = "test_tool_call_id"
|
|
299
|
+
input_data = {
|
|
300
|
+
"paper_ids": ["p1", "p2"],
|
|
301
|
+
"tool_call_id": tool_call_id,
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
with pytest.raises(
|
|
305
|
+
RuntimeError, match="Failed to obtain a response from the Semantic Scholar API."
|
|
306
|
+
):
|
|
307
|
+
get_multi_paper_recommendations.run(input_data)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for S2 tools functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from unittest.mock import patch
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
from langgraph.types import Command
|
|
9
|
+
|
|
10
|
+
from ..tools.s2.retrieve_semantic_scholar_paper_id import (
|
|
11
|
+
retrieve_semantic_scholar_paper_id,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
# Fixed test data for deterministic results
|
|
15
|
+
MOCK_SEARCH_RESPONSE = {
|
|
16
|
+
"data": [
|
|
17
|
+
{
|
|
18
|
+
"paperId": "123",
|
|
19
|
+
"title": "Machine Learning Basics",
|
|
20
|
+
"abstract": "An introduction to ML",
|
|
21
|
+
"year": 2023,
|
|
22
|
+
"citationCount": 100,
|
|
23
|
+
"url": "https://example.com/paper1",
|
|
24
|
+
"authors": [{"name": "Test Author"}],
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
MOCK_STATE_PAPER = {
|
|
30
|
+
"123": {
|
|
31
|
+
"Title": "Machine Learning Basics",
|
|
32
|
+
"Abstract": "An introduction to ML",
|
|
33
|
+
"Year": 2023,
|
|
34
|
+
"Citation Count": 100,
|
|
35
|
+
"URL": "https://example.com/paper1",
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class TestS2Tools:
|
|
41
|
+
"""Unit tests for individual S2 tools"""
|
|
42
|
+
|
|
43
|
+
@patch("requests.get")
|
|
44
|
+
def test_retrieve_semantic_scholar_paper_id(self, mock_get):
|
|
45
|
+
"""Tests retrieving a paper ID from Semantic Scholar."""
|
|
46
|
+
mock_get.return_value.json.return_value = MOCK_SEARCH_RESPONSE
|
|
47
|
+
mock_get.return_value.status_code = 200
|
|
48
|
+
|
|
49
|
+
result = retrieve_semantic_scholar_paper_id.invoke(
|
|
50
|
+
input={"paper_title": "Machine Learning Basics", "tool_call_id": "test123"}
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
assert isinstance(result, Command)
|
|
54
|
+
assert "messages" in result.update
|
|
55
|
+
# The tool now returns the raw paper ID as the message content
|
|
56
|
+
content = result.update["messages"][0].content
|
|
57
|
+
assert content == "123"
|
|
58
|
+
|
|
59
|
+
@patch("requests.get")
|
|
60
|
+
def test_retrieve_semantic_scholar_paper_id_no_results(self, mock_get):
|
|
61
|
+
"""Test retrieving a paper ID when no results are found."""
|
|
62
|
+
mock_get.return_value.json.return_value = {"data": []}
|
|
63
|
+
mock_get.return_value.status_code = 200
|
|
64
|
+
with pytest.raises(ValueError, match="No papers found for query: UnknownPaper"):
|
|
65
|
+
retrieve_semantic_scholar_paper_id.invoke(
|
|
66
|
+
input={"paper_title": "UnknownPaper", "tool_call_id": "test123"}
|
|
67
|
+
)
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Unit tests for S2 tools functionality.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from types import SimpleNamespace
|
|
6
|
+
|
|
7
|
+
import hydra
|
|
8
|
+
import pytest
|
|
9
|
+
import requests
|
|
10
|
+
from langchain_core.messages import ToolMessage
|
|
11
|
+
from langgraph.types import Command
|
|
12
|
+
|
|
13
|
+
from aiagents4pharma.talk2scholars.tools.s2.search import search_tool
|
|
14
|
+
from aiagents4pharma.talk2scholars.tools.s2.utils import search_helper
|
|
15
|
+
|
|
16
|
+
# --- Dummy Hydra Config Setup ---
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DummyHydraContext:
|
|
20
|
+
"""hydra.initialize context manager that does nothing."""
|
|
21
|
+
|
|
22
|
+
def __enter__(self):
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
def __exit__(self, exc_type, exc_val, traceback):
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Create a dummy configuration that mimics the expected hydra config
|
|
30
|
+
dummy_config = SimpleNamespace(
|
|
31
|
+
tools=SimpleNamespace(
|
|
32
|
+
search=SimpleNamespace(
|
|
33
|
+
api_endpoint="http://dummy.endpoint",
|
|
34
|
+
api_fields=["paperId", "title", "authors"],
|
|
35
|
+
)
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# --- Dummy Response Classes and Functions for requests.get ---
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class DummyResponse:
|
|
43
|
+
"""A dummy response class for mocking HTTP responses."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, json_data, status_code=200):
|
|
46
|
+
"""initialize a DummyResponse with the given JSON data and status code."""
|
|
47
|
+
self._json_data = json_data
|
|
48
|
+
self.status_code = status_code
|
|
49
|
+
|
|
50
|
+
def json(self):
|
|
51
|
+
"""access the JSON data from the response."""
|
|
52
|
+
return self._json_data
|
|
53
|
+
|
|
54
|
+
def raise_for_status(self):
|
|
55
|
+
"""Raise an HTTP error for status codes >= 400."""
|
|
56
|
+
if self.status_code >= 400:
|
|
57
|
+
raise requests.HTTPError("HTTP Error")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_dummy_response_no_error():
|
|
61
|
+
"""Test that raise_for_status does not raise an exception for a successful response."""
|
|
62
|
+
# Create a DummyResponse with a successful status code.
|
|
63
|
+
response = DummyResponse({"data": "success"}, status_code=200)
|
|
64
|
+
# Calling raise_for_status should not raise an exception and should return None.
|
|
65
|
+
assert response.raise_for_status() is None
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_dummy_response_raise_error():
|
|
69
|
+
"""Test that raise_for_status raises an exception for a failing response."""
|
|
70
|
+
# Create a DummyResponse with a failing status code.
|
|
71
|
+
response = DummyResponse({"error": "fail"}, status_code=400)
|
|
72
|
+
# Calling raise_for_status should raise an HTTPError.
|
|
73
|
+
with pytest.raises(requests.HTTPError):
|
|
74
|
+
response.raise_for_status()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def dummy_requests_get_success(url, params, timeout):
|
|
78
|
+
"""A dummy requests.get function that returns a successful response."""
|
|
79
|
+
# Record call parameters for assertions
|
|
80
|
+
dummy_requests_get_success.called_url = url
|
|
81
|
+
dummy_requests_get_success.called_params = params
|
|
82
|
+
dummy_requests_get_success.called_timeout = timeout
|
|
83
|
+
|
|
84
|
+
# Simulate a valid API response with three papers;
|
|
85
|
+
# one paper missing authors should be filtered out.
|
|
86
|
+
dummy_data = {
|
|
87
|
+
"data": [
|
|
88
|
+
{
|
|
89
|
+
"paperId": "1",
|
|
90
|
+
"title": "Paper 1",
|
|
91
|
+
"authors": [{"name": "Author A", "authorId": "A1"}],
|
|
92
|
+
"year": 2020,
|
|
93
|
+
"citationCount": 10,
|
|
94
|
+
"url": "http://paper1",
|
|
95
|
+
"externalIds": {"ArXiv": "arxiv1"},
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"paperId": "2",
|
|
99
|
+
"title": "Paper 2",
|
|
100
|
+
"authors": [{"name": "Author B", "authorId": "B1"}],
|
|
101
|
+
"year": 2021,
|
|
102
|
+
"citationCount": 20,
|
|
103
|
+
"url": "http://paper2",
|
|
104
|
+
"externalIds": {},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"paperId": "3",
|
|
108
|
+
"title": "Paper 3",
|
|
109
|
+
"authors": None, # This paper should be filtered out.
|
|
110
|
+
"year": 2022,
|
|
111
|
+
"citationCount": 30,
|
|
112
|
+
"url": "http://paper3",
|
|
113
|
+
"externalIds": {"ArXiv": "arxiv3"},
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
}
|
|
117
|
+
return DummyResponse(dummy_data)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def dummy_requests_get_no_data(url, params, timeout):
|
|
121
|
+
"""A dummy requests.get function that returns a response without the expected 'data' key."""
|
|
122
|
+
dummy_requests_get_no_data.called_url = url
|
|
123
|
+
dummy_requests_get_no_data.called_params = params
|
|
124
|
+
dummy_requests_get_no_data.called_timeout = timeout
|
|
125
|
+
# Simulate a response with an unexpected format (missing "data" key)
|
|
126
|
+
return DummyResponse({"error": "Invalid format"})
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def dummy_requests_get_no_papers(url, params, timeout):
|
|
130
|
+
"""A dummy requests.get function that returns a response with an empty papers list."""
|
|
131
|
+
dummy_requests_get_no_papers.called_url = url
|
|
132
|
+
dummy_requests_get_no_papers.called_params = params
|
|
133
|
+
dummy_requests_get_no_papers.called_timeout = timeout
|
|
134
|
+
# Simulate a response with an empty papers list.
|
|
135
|
+
return DummyResponse({"data": []})
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def dummy_requests_get_exception(url, params, timeout):
|
|
139
|
+
"""A dummy requests.get function that raises an exception."""
|
|
140
|
+
dummy_requests_get_exception.called_url = url
|
|
141
|
+
dummy_requests_get_exception.called_params = params
|
|
142
|
+
dummy_requests_get_exception.called_timeout = timeout
|
|
143
|
+
# Simulate a network/connection exception.
|
|
144
|
+
raise requests.exceptions.RequestException("Connection error")
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
# --- Pytest Fixture to Patch Hydra ---
|
|
148
|
+
@pytest.fixture(autouse=True)
|
|
149
|
+
def patch_hydra(monkeypatch):
|
|
150
|
+
"""hydra patch to mock initialize and compose functions."""
|
|
151
|
+
# Patch hydra.initialize to return our dummy context manager.
|
|
152
|
+
monkeypatch.setattr(hydra, "initialize", lambda version_base, config_path: DummyHydraContext())
|
|
153
|
+
# Patch hydra.compose to return our dummy config.
|
|
154
|
+
monkeypatch.setattr(hydra, "compose", lambda config_name, overrides: dummy_config)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# --- Test Cases ---
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_search_tool_success(monkeypatch):
|
|
161
|
+
"""
|
|
162
|
+
Test that search_tool returns a valid Command object when the API response is successful.
|
|
163
|
+
Also checks that papers without required fields are filtered out.
|
|
164
|
+
"""
|
|
165
|
+
monkeypatch.setattr(requests, "get", dummy_requests_get_success)
|
|
166
|
+
|
|
167
|
+
tool_call_id = "test_tool_call_id"
|
|
168
|
+
# Invoke using .run() with a dictionary input.
|
|
169
|
+
result = search_tool.run(
|
|
170
|
+
{
|
|
171
|
+
"query": "machine learning",
|
|
172
|
+
"tool_call_id": tool_call_id,
|
|
173
|
+
"limit": 3,
|
|
174
|
+
"year": "2020",
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
# Check that a Command is returned with the expected update structure.
|
|
179
|
+
assert isinstance(result, Command)
|
|
180
|
+
update = result.update
|
|
181
|
+
assert "papers" in update
|
|
182
|
+
|
|
183
|
+
papers = update["papers"]
|
|
184
|
+
# Papers with valid 'title' and 'authors' should be included.
|
|
185
|
+
assert "1" in papers
|
|
186
|
+
assert "2" in papers
|
|
187
|
+
# Paper "3" is missing authors and should be filtered out.
|
|
188
|
+
assert "3" not in papers
|
|
189
|
+
|
|
190
|
+
# Check that a ToolMessage is included in the messages.
|
|
191
|
+
messages = update.get("messages", [])
|
|
192
|
+
assert len(messages) == 1
|
|
193
|
+
msg = messages[0]
|
|
194
|
+
assert isinstance(msg, ToolMessage)
|
|
195
|
+
assert "Number of papers found:" in msg.content
|
|
196
|
+
|
|
197
|
+
# Verify that the correct parameters were sent to requests.get.
|
|
198
|
+
called_params = dummy_requests_get_success.called_params
|
|
199
|
+
assert called_params["query"] == "machine learning"
|
|
200
|
+
# The "year" parameter should have been added.
|
|
201
|
+
assert called_params["year"] == "2020"
|
|
202
|
+
# The limit is set to min(limit, 100) so it should be 3.
|
|
203
|
+
assert called_params["limit"] == 3
|
|
204
|
+
# The fields should be a comma-separated string from the dummy config.
|
|
205
|
+
assert called_params["fields"] == "paperId,title,authors"
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def test_search_tool_unexpected_format(monkeypatch):
|
|
209
|
+
"""
|
|
210
|
+
Test that search_tool raises a RuntimeError when the API response
|
|
211
|
+
does not include the expected 'data' key.
|
|
212
|
+
"""
|
|
213
|
+
monkeypatch.setattr(requests, "get", dummy_requests_get_no_data)
|
|
214
|
+
tool_call_id = "test_tool_call_id"
|
|
215
|
+
with pytest.raises(
|
|
216
|
+
RuntimeError,
|
|
217
|
+
match=(
|
|
218
|
+
"Unexpected response from Semantic Scholar API. The results could not be "
|
|
219
|
+
"retrieved due to an unexpected format. "
|
|
220
|
+
"Please modify your search query and try again."
|
|
221
|
+
),
|
|
222
|
+
):
|
|
223
|
+
search_tool.run(
|
|
224
|
+
{
|
|
225
|
+
"query": "test",
|
|
226
|
+
"tool_call_id": tool_call_id,
|
|
227
|
+
}
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def test_search_tool_no_papers(monkeypatch):
|
|
232
|
+
"""
|
|
233
|
+
Test that search_tool raises a RuntimeError when the API returns no papers.
|
|
234
|
+
"""
|
|
235
|
+
monkeypatch.setattr(requests, "get", dummy_requests_get_no_papers)
|
|
236
|
+
tool_call_id = "test_tool_call_id"
|
|
237
|
+
with pytest.raises(
|
|
238
|
+
RuntimeError,
|
|
239
|
+
match=(
|
|
240
|
+
"No papers were found for your query. Consider refining your search "
|
|
241
|
+
"by using more specific keywords or different terms."
|
|
242
|
+
),
|
|
243
|
+
):
|
|
244
|
+
search_tool.run(
|
|
245
|
+
{
|
|
246
|
+
"query": "test",
|
|
247
|
+
"tool_call_id": tool_call_id,
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def test_search_tool_requests_exception(monkeypatch):
|
|
253
|
+
"""
|
|
254
|
+
Test that search_tool raises a RuntimeError when requests.get throws an exception.
|
|
255
|
+
"""
|
|
256
|
+
monkeypatch.setattr(requests, "get", dummy_requests_get_exception)
|
|
257
|
+
tool_call_id = "test_tool_call_id"
|
|
258
|
+
with pytest.raises(
|
|
259
|
+
RuntimeError,
|
|
260
|
+
match="Failed to connect to Semantic Scholar API after 10 attempts."
|
|
261
|
+
"Please retry the same query.",
|
|
262
|
+
):
|
|
263
|
+
search_tool.run(
|
|
264
|
+
{
|
|
265
|
+
"query": "test",
|
|
266
|
+
"tool_call_id": tool_call_id,
|
|
267
|
+
}
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def test_search_tool_no_response(monkeypatch):
|
|
272
|
+
"""
|
|
273
|
+
Test that search_tool raises a RuntimeError when no response
|
|
274
|
+
is obtained. This is simulated by patching 'range' in the
|
|
275
|
+
module namespace of search_helper to return an empty iterator,
|
|
276
|
+
so that the for-loop in _fetch_papers never iterates and self.response
|
|
277
|
+
remains None.
|
|
278
|
+
"""
|
|
279
|
+
# Patch 'range' in the module globals of search_helper.
|
|
280
|
+
monkeypatch.setitem(search_helper.__dict__, "range", lambda x: iter([]))
|
|
281
|
+
|
|
282
|
+
tool_call_id = "test_tool_call_id"
|
|
283
|
+
with pytest.raises(
|
|
284
|
+
RuntimeError, match="Failed to obtain a response from the Semantic Scholar API."
|
|
285
|
+
):
|
|
286
|
+
search_tool.run({"query": "test", "tool_call_id": tool_call_id})
|