GuXiaopeng commited on
Commit
4decb72
·
verified ·
1 Parent(s): 5594dff

Update core/pipeline_agent.py

Browse files
Files changed (1) hide show
  1. core/pipeline_agent.py +11 -4
core/pipeline_agent.py CHANGED
@@ -136,12 +136,20 @@ class SSciPipelineAgent:
136
  @retry(stop=stop_after_attempt(3), wait=wait_random_exponential(multiplier=1, max=10), retry=retry_if_exception_type((requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.HTTPError)))
137
  def _requests_get_with_retry(self, url, headers=None, params=None, timeout=15):
138
  resp = requests.get(url, headers=headers, params=params, timeout=timeout)
 
139
  if resp.status_code == 429:
140
  logging.warning(f"⚠️ [API 限流] 触发 429,当前线程进入随机休眠退避。URL: {url}")
141
  resp.raise_for_status()
 
 
 
 
 
 
142
  if resp.status_code != 200:
143
  logging.error(f"❌ [API 错误] 状态码: {resp.status_code}, 响应: {resp.text}")
144
  resp.raise_for_status()
 
145
  return resp
146
 
147
  def _is_english_dominant(self, text):
@@ -380,7 +388,6 @@ class SSciPipelineAgent:
380
 
381
  if not papers: raise ValueError("Extracted JSON is null or invalid")
382
 
383
- # 修复可能包裹在 dict 中的情况 (e.g., {"papers": [...]})
384
  if isinstance(papers, dict):
385
  for v in papers.values():
386
  if isinstance(v, list):
@@ -563,7 +570,7 @@ class SSciPipelineAgent:
563
  else: author_str = formatted_authors[0]
564
 
565
  apa_full = f"{author_str} ({year_str}). {title}. {venue}."
566
- if doi: apa_full += f" [https://doi.org/](https://doi.org/){doi}"
567
 
568
  with self.lock:
569
  cite_tag = f"[CITE-{len(self.citation_map)+1:02d}]"
@@ -622,7 +629,7 @@ class SSciPipelineAgent:
622
  seen_identifiers.add(identifier)
623
 
624
  venue = ((item.get("primary_location") or {}).get("source") or {}).get("display_name", "Journal")
625
- doi_clean = (item.get("doi") or "").replace("[https://doi.org/](https://doi.org/)", "")
626
  formatted_authors, last_names = [], []
627
  for a in item.get("authorships", []):
628
  name_raw = a.get("author", {}).get("display_name", "")
@@ -646,7 +653,7 @@ class SSciPipelineAgent:
646
  else: author_str = formatted_authors[0]
647
 
648
  apa_full = f"{author_str} ({year_str}). {title}. {venue}."
649
- if doi_clean: apa_full += f" [https://doi.org/](https://doi.org/){doi_clean}"
650
 
651
  with self.lock:
652
  cite_tag = f"[CITE-{len(self.citation_map)+1:02d}]"
 
136
  @retry(stop=stop_after_attempt(3), wait=wait_random_exponential(multiplier=1, max=10), retry=retry_if_exception_type((requests.exceptions.Timeout, requests.exceptions.ConnectionError, requests.exceptions.HTTPError)))
137
  def _requests_get_with_retry(self, url, headers=None, params=None, timeout=15):
138
  resp = requests.get(url, headers=headers, params=params, timeout=timeout)
139
+
140
  if resp.status_code == 429:
141
  logging.warning(f"⚠️ [API 限流] 触发 429,当前线程进入随机休眠退避。URL: {url}")
142
  resp.raise_for_status()
143
+
144
+ # 🚨 核心修复:豁免 S2 因为翻页越界导致的 400 错误,保护引擎不被熔断
145
+ if resp.status_code == 400 and "not available" in resp.text:
146
+ logging.info(f"ℹ️ [API 翻页边界] 该关键词搜索结果已触底,停止翻页。")
147
+ return resp
148
+
149
  if resp.status_code != 200:
150
  logging.error(f"❌ [API 错误] 状态码: {resp.status_code}, 响应: {resp.text}")
151
  resp.raise_for_status()
152
+
153
  return resp
154
 
155
  def _is_english_dominant(self, text):
 
388
 
389
  if not papers: raise ValueError("Extracted JSON is null or invalid")
390
 
 
391
  if isinstance(papers, dict):
392
  for v in papers.values():
393
  if isinstance(v, list):
 
570
  else: author_str = formatted_authors[0]
571
 
572
  apa_full = f"{author_str} ({year_str}). {title}. {venue}."
573
+ if doi: apa_full += f" https://doi.org/{doi}"
574
 
575
  with self.lock:
576
  cite_tag = f"[CITE-{len(self.citation_map)+1:02d}]"
 
629
  seen_identifiers.add(identifier)
630
 
631
  venue = ((item.get("primary_location") or {}).get("source") or {}).get("display_name", "Journal")
632
+ doi_clean = (item.get("doi") or "").replace("https://doi.org/", "")
633
  formatted_authors, last_names = [], []
634
  for a in item.get("authorships", []):
635
  name_raw = a.get("author", {}).get("display_name", "")
 
653
  else: author_str = formatted_authors[0]
654
 
655
  apa_full = f"{author_str} ({year_str}). {title}. {venue}."
656
+ if doi_clean: apa_full += f" https://doi.org/{doi_clean}"
657
 
658
  with self.lock:
659
  cite_tag = f"[CITE-{len(self.citation_map)+1:02d}]"