All checks were successful
news-summary-bot-cicd / build_push_deploy (push) Successful in 9m14s
- 요약을 JSON으로 구조화: oneliner, main_points, conclusion 분리 - Claude에게 JSON 형식으로만 응답하도록 프롬프트 변경 - n8n Discord 임베드: 섹션별 필드 분리, 이모지, 타임스탬프 추가 - JSON.stringify Expression으로 특수문자 이스케이프 처리 - 전체 문서 API 응답 형식 업데이트 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from fastapi import FastAPI, Header, HTTPException
|
|
from pydantic import BaseModel
|
|
|
|
from app.config import settings
|
|
from app.summarizer import summarize
|
|
from app.transcript import SkipVideo, extract_video_id, fetch_transcript
|
|
|
|
app = FastAPI(title="News Summary Bot")
|
|
|
|
|
|
class SummarizeRequest(BaseModel):
|
|
video_url: str
|
|
title: str = ""
|
|
channel_name: str = ""
|
|
|
|
|
|
@app.post("/summarize")
|
|
async def summarize_video(
|
|
req: SummarizeRequest,
|
|
x_api_secret: str = Header(default=""),
|
|
):
|
|
if settings.api_secret and x_api_secret != settings.api_secret:
|
|
raise HTTPException(status_code=401, detail="Unauthorized")
|
|
|
|
title = req.title or "제목 없음"
|
|
|
|
channel_name = req.channel_name or ""
|
|
base = {"video_url": req.video_url, "title": title, "channel_name": channel_name}
|
|
|
|
try:
|
|
video_id = extract_video_id(req.video_url)
|
|
transcript = fetch_transcript(video_id)
|
|
summary = summarize(transcript, title)
|
|
except SkipVideo as e:
|
|
return {**base, "status": "skipped", "reason": str(e)}
|
|
except Exception as e:
|
|
return {
|
|
**base,
|
|
"status": "error",
|
|
"error_type": type(e).__name__,
|
|
"error_message": str(e),
|
|
}
|
|
|
|
return {**base, "status": "ok", **summary}
|
|
|
|
|
|
@app.get("/health")
|
|
async def health():
|
|
return {"status": "ok"}
|