feat: Ollama qwen3:14b 기반 AI 뉴스 요약 + 텔레그램 통합 허브

- stock-lab: POST /api/stock/news/summarize 추가 (Ollama /api/generate 호출, 토큰/duration 추적)
- agent-office: telegram 패키지 분해 (client/formatter/messaging/webhook/router/agent_registry)
- send_agent_message 통합 API로 에이전트 중립 메시지 포맷 표준화
- 텔레그램 → 에이전트 명령 라우터 (/status, /stock news, /music credits 등)
- 토큰 사용량 집계 API 및 GET /agents/{id}/token-usage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-13 01:44:27 +09:00
parent de91f424a3
commit 86e7f727eb
17 changed files with 696 additions and 116 deletions

View File

@@ -23,6 +23,7 @@ from .db import (
)
from .scraper import fetch_market_news, fetch_major_indices
from .price_fetcher import get_current_prices
from .ai_summarizer import summarize_news, OllamaError
app = FastAPI()
@@ -144,6 +145,33 @@ def trigger_scrap():
run_scraping_job()
return {"ok": True}
class NewsSummarizeRequest(BaseModel):
limit: Optional[int] = 10
@app.post("/api/stock/news/summarize")
async def summarize_latest_news(req: NewsSummarizeRequest = NewsSummarizeRequest()):
"""최근 뉴스를 Ollama(qwen3:14b)로 요약"""
limit = req.limit if (req and req.limit) else 10
articles = get_latest_articles(limit)
if not articles:
raise HTTPException(status_code=404, detail="요약할 뉴스가 없습니다.")
try:
result = await summarize_news(articles)
except OllamaError as e:
logger.error(f"뉴스 요약 실패: {e}")
raise HTTPException(status_code=500, detail=f"Ollama 호출 실패: {e}")
except Exception as e:
logger.exception("뉴스 요약 중 예상치 못한 오류")
raise HTTPException(status_code=500, detail=f"뉴스 요약 실패: {e}")
return {
**result,
"article_count": len(articles),
}
# --- Trading API (Windows Proxy, 인증 필요) ---
@app.get("/api/trade/balance", dependencies=[Depends(verify_admin)])