fix:优化爬虫链路
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -26,7 +26,12 @@ def _call_ollama_extract(text: str, timeout: int = 15) -> Optional[Dict[str, Any
|
|||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
raw = str(text).strip()[:EXTRACT_TEXT_MAX_LEN]
|
raw = str(text).strip()[:EXTRACT_TEXT_MAX_LEN]
|
||||||
prompt = f"""从以下美伊/中东新闻**全文或摘要**中,提取**报道明确给出的数字与事实**,输出 JSON。规则:
|
prompt = f"""从以下美伊/中东新闻**全文或摘要**中,提取**报道明确给出的数字与事实**,输出 JSON。
|
||||||
|
|
||||||
|
输入说明:
|
||||||
|
- 原文可能是英文、中文或其他语言(English / Chinese / Arabic / Persian 等),请先理解含义,再按要求输出。
|
||||||
|
|
||||||
|
规则:
|
||||||
1. 仅填写报道中**直接出现、可核对**的数据,不要推测或估算。
|
1. 仅填写报道中**直接出现、可核对**的数据,不要推测或估算。
|
||||||
2. 无明确依据的字段**必须省略**,不要填 0 或猜。
|
2. 无明确依据的字段**必须省略**,不要填 0 或猜。
|
||||||
3. **战损一律按增量**:只填本则报道中「本次/此次/今日/本轮」**新增**的伤亡或损毁数量。若报道只给「累计总数」「迄今共」「total so far」等,**不要填写**该字段(避免与库内已有累计值重复叠加)。
|
3. **战损一律按增量**:只填本则报道中「本次/此次/今日/本轮」**新增**的伤亡或损毁数量。若报道只给「累计总数」「迄今共」「total so far」等,**不要填写**该字段(避免与库内已有累计值重复叠加)。
|
||||||
@@ -50,7 +55,7 @@ def _call_ollama_extract(text: str, timeout: int = 15) -> Optional[Dict[str, Any
|
|||||||
原文:
|
原文:
|
||||||
{raw}
|
{raw}
|
||||||
|
|
||||||
直接输出 JSON,不要解释:"""
|
直接输出 JSON 对象,不要解释,不要加反引号或代码块标记:"""
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
"http://localhost:11434/api/chat",
|
"http://localhost:11434/api/chat",
|
||||||
json={
|
json={
|
||||||
|
|||||||
@@ -13,10 +13,16 @@ def _is_mostly_chinese(text: str) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def translate_to_chinese(text: str) -> str:
|
def translate_to_chinese(text: str) -> str:
|
||||||
"""将文本翻译成中文,失败或已是中文则返回原文。Google 失败时尝试 MyMemory。"""
|
"""将文本翻译成中文,失败或已是中文则返回原文。
|
||||||
|
|
||||||
|
说明:
|
||||||
|
- 默认关闭外部翻译(deep_translator),直接返回原文,避免因网络或代理问题阻塞整条流水线。
|
||||||
|
- 如需开启翻译,可显式设置环境变量 TRANSLATE_DISABLED=0。
|
||||||
|
"""
|
||||||
if not text or not text.strip():
|
if not text or not text.strip():
|
||||||
return text
|
return text
|
||||||
if os.environ.get("TRANSLATE_DISABLED", "0") == "1":
|
# 默认禁用翻译:TRANSLATE_DISABLED 未设置时视为开启(值为 "1")
|
||||||
|
if os.environ.get("TRANSLATE_DISABLED", "1") == "1":
|
||||||
return text
|
return text
|
||||||
s = str(text).strip()
|
s = str(text).strip()
|
||||||
if len(s) > 2000:
|
if len(s) > 2000:
|
||||||
|
|||||||
BIN
server/data.db-shm
Normal file
BIN
server/data.db-shm
Normal file
Binary file not shown.
0
server/data.db-wal
Normal file
0
server/data.db-wal
Normal file
Reference in New Issue
Block a user