feat: add admin routes, summarizer service, and CLI summarize command
- Add /admin routes for manual trigger and status inspection - Add summarizer service with batch/single summary support - Add summarize CLI command (single arxiv_id or batch pending) - Register admin router in main app - Add tests for summarizer
This commit is contained in:
+40
@@ -49,6 +49,46 @@ def crawl(
|
||||
db.close()
|
||||
|
||||
|
||||
@cli_app.command()
|
||||
def summarize(
|
||||
arxiv_id: str = typer.Argument(
|
||||
None,
|
||||
help="指定论文 arXiv ID;留空则批量处理所有 pending",
|
||||
),
|
||||
):
|
||||
"""手动触发 AI 总结。"""
|
||||
from app.config import settings
|
||||
from app.database import SessionLocal, engine
|
||||
from app.models import init_db as _init
|
||||
from app.services.summarizer import summarize_batch, summarize_single
|
||||
|
||||
import os
|
||||
os.makedirs(settings.db_path.parent, exist_ok=True)
|
||||
_init(engine)
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
if arxiv_id:
|
||||
typer.echo(f"🤖 开始总结 {arxiv_id} ...")
|
||||
result = asyncio.run(summarize_single(db, arxiv_id))
|
||||
else:
|
||||
typer.echo("🤖 开始批量总结 pending 论文 ...")
|
||||
result = asyncio.run(summarize_batch(db))
|
||||
|
||||
if result.get("status") in ("success", "done"):
|
||||
typer.echo(f"✅ 总结完成:{result}")
|
||||
elif result.get("status") == "conflict":
|
||||
typer.echo("⚠️ 已有批量总结任务在运行中", err=True)
|
||||
raise typer.Exit(code=1)
|
||||
elif result.get("status") == "not_found":
|
||||
typer.echo(f"❌ 论文未找到:{arxiv_id}", err=True)
|
||||
raise typer.Exit(code=1)
|
||||
else:
|
||||
typer.echo(f"⚠️ 总结结果:{result}", err=True)
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
@cli_app.command()
|
||||
def init_db():
|
||||
"""初始化数据库表。"""
|
||||
|
||||
Reference in New Issue
Block a user