Spaces:
Running
Running
Upload run.py with huggingface_hub
Browse files
run.py
CHANGED
|
@@ -218,10 +218,17 @@ def _mine_comparison_algorithms(arxiv_id: str, title: str, abstract: str) -> tup
|
|
| 218 |
|
| 219 |
def _search_s2_papers(query: str, limit: int = 5) -> list[dict]:
|
| 220 |
"""在 Semantic Scholar 中搜索论文,覆盖全工科领域(IEEE/ASME/ASCE 等期刊)。
|
|
|
|
| 221 |
|
| 222 |
Returns:
|
| 223 |
list[dict]: [{"title": ..., "abstract": ..., "year": ..., "citations": ..., "url": ...}, ...]
|
| 224 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
api_url = (
|
| 226 |
f"https://api.semanticscholar.org/graph/v1/paper/search"
|
| 227 |
f"?query={urllib.request.quote(query)}&limit={limit}"
|
|
@@ -248,6 +255,7 @@ def _search_s2_papers(query: str, limit: int = 5) -> list[dict]:
|
|
| 248 |
"arxiv_id": (p.get("externalIds") or {}).get("ArXiv", ""),
|
| 249 |
"doi": (p.get("externalIds") or {}).get("DOI", ""),
|
| 250 |
})
|
|
|
|
| 251 |
return papers
|
| 252 |
|
| 253 |
|
|
|
|
| 218 |
|
| 219 |
def _search_s2_papers(query: str, limit: int = 5) -> list[dict]:
|
| 220 |
"""在 Semantic Scholar 中搜索论文,覆盖全工科领域(IEEE/ASME/ASCE 等期刊)。
|
| 221 |
+
带 30 分钟 TTL 缓存,降低 S2 API 压力。
|
| 222 |
|
| 223 |
Returns:
|
| 224 |
list[dict]: [{"title": ..., "abstract": ..., "year": ..., "citations": ..., "url": ...}, ...]
|
| 225 |
"""
|
| 226 |
+
from cache import s2_cache
|
| 227 |
+
cache_key = f"s2_search:{query}:{limit}"
|
| 228 |
+
cached = s2_cache.get(cache_key)
|
| 229 |
+
if cached is not None:
|
| 230 |
+
return cached
|
| 231 |
+
|
| 232 |
api_url = (
|
| 233 |
f"https://api.semanticscholar.org/graph/v1/paper/search"
|
| 234 |
f"?query={urllib.request.quote(query)}&limit={limit}"
|
|
|
|
| 255 |
"arxiv_id": (p.get("externalIds") or {}).get("ArXiv", ""),
|
| 256 |
"doi": (p.get("externalIds") or {}).get("DOI", ""),
|
| 257 |
})
|
| 258 |
+
s2_cache.set(cache_key, papers)
|
| 259 |
return papers
|
| 260 |
|
| 261 |
|