Paper Downloader
Unified paper download tool for LangGraph. Supports downloading papers from arXiv, medRxiv, bioRxiv, and PubMed through a single interface.
PaperDownloaderFactory
Factory class for creating paper downloader instances.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
_apply_config(config_obj, source_config, config_type)
staticmethod
Apply configuration from source to target object using multiple fallback methods. This preserves all the original logic but reduces branches in the main method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_obj
|
Any
|
Target configuration object |
required |
source_config
|
Any
|
Source configuration to extract from |
required |
config_type
|
str
|
Type description for logging |
required |
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
_build_service_config(unified_config, service)
staticmethod
Build service-specific configuration by merging common and service settings. Handles Hydra's OmegaConf objects properly.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unified_config
|
Any
|
The unified configuration object |
required |
service
|
str
|
Service name |
required |
Returns:
Type | Description |
---|---|
Any
|
Service-specific configuration object |
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
_extract_from_dict(config_obj, config_dict)
staticmethod
Extract configuration from dictionary.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
264 265 266 267 268 269 |
|
_extract_from_dir(config_obj, source_config)
staticmethod
Extract configuration using dir() approach as fallback.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
278 279 280 281 282 283 284 285 |
|
_extract_from_items(config_obj, source_config)
staticmethod
Extract configuration using items() method.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
271 272 273 274 275 276 |
|
_extract_from_omegaconf(config_obj, source_config)
staticmethod
Extract configuration from OmegaConf object.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
255 256 257 258 259 260 261 262 |
|
_get_unified_config()
staticmethod
Load unified paper download configuration using Hydra with caching. This avoids the GlobalHydra reinitialization issue by caching the config.
Returns:
Type | Description |
---|---|
Any
|
Unified configuration object |
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
_try_config_extraction(config_obj, source_config)
staticmethod
Try different methods to extract configuration data.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
clear_cache()
classmethod
Clear cached configuration.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
59 60 61 62 |
|
create(service)
staticmethod
Create appropriate downloader instance for the specified service.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
Literal['arxiv', 'medrxiv', 'biorxiv', 'pubmed']
|
Service name ('arxiv', 'medrxiv', 'biorxiv', 'pubmed') |
required |
Returns:
Type | Description |
---|---|
BasePaperDownloader
|
Configured downloader instance |
Raises:
Type | Description |
---|---|
ValueError
|
If service is not supported |
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
get_default_service()
staticmethod
Get the default service from configuration.
Returns:
Type | Description |
---|---|
Literal['arxiv', 'medrxiv', 'biorxiv', 'pubmed']
|
Default service name from config, fallback to 'pubmed' |
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
UnifiedPaperDownloadInput
Bases: BaseModel
Input schema for the unified paper download tool.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
_download_papers_impl(service, identifiers, tool_call_id)
Internal implementation function that contains the actual download logic. This is called by both the decorated tool and the convenience functions.
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
download_arxiv_papers(arxiv_ids, tool_call_id)
Convenience function for downloading arXiv papers (explicitly uses arXiv service).
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
336 337 338 339 340 |
|
download_biorxiv_papers(dois, tool_call_id)
Convenience function for downloading bioRxiv papers (explicitly uses bioRxiv service).
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
350 351 352 353 354 |
|
download_medrxiv_papers(dois, tool_call_id)
Convenience function for downloading medRxiv papers (explicitly uses medRxiv service).
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
343 344 345 346 347 |
|
download_papers(service, identifiers, tool_call_id)
Universal paper download tool supporting multiple academic paper services.
Downloads paper metadata and PDFs from arXiv, medRxiv, bioRxiv, or PubMed and stores them in temporary files for further processing. The downloaded PDFs can be accessed using the temp_file_path in the returned metadata.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
service
|
Optional[Literal['arxiv', 'medrxiv', 'biorxiv', 'pubmed']]
|
Paper service to download from (optional, uses configured default if not specified) - 'arxiv': For arXiv preprints (requires arXiv IDs) - 'medrxiv': For medRxiv preprints (requires DOIs) - 'biorxiv': For bioRxiv preprints (requires DOIs) - 'pubmed': For PubMed papers (requires PMIDs) |
required |
identifiers
|
List[str]
|
List of paper identifiers in the format expected by the service |
required |
Returns:
Type | Description |
---|---|
Command[Any]
|
Command with article_data containing paper metadata and local file paths |
Examples:
Download from arXiv
download_papers("arxiv", ["1234.5678", "2301.12345"])
Download from medRxiv
download_papers("medrxiv", ["10.1101/2020.09.09.20191205"])
Download from bioRxiv
download_papers("biorxiv", ["10.1101/2020.09.09.20191205"])
Download from PubMed
download_papers("pubmed", ["12345678", "87654321"])
Use default service (configured in default.yaml)
download_papers(None, ["12345678", "87654321"])
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
download_pubmed_papers(pmids, tool_call_id)
Convenience function for downloading PubMed papers (explicitly uses PubMed service).
Source code in aiagents4pharma/talk2scholars/tools/paper_download/paper_downloader.py
357 358 359 360 361 |
|