[split-required] Split 500-850 LOC files (batch 2)
backend-lehrer (10 files): - game/database.py (785 → 5), correction_api.py (683 → 4) - classroom_engine/antizipation.py (676 → 5) - llm_gateway schools/edu_search already done in prior batch klausur-service (12 files): - orientation_crop_api.py (694 → 5), pdf_export.py (677 → 4) - zeugnis_crawler.py (676 → 5), grid_editor_api.py (671 → 5) - eh_templates.py (658 → 5), mail/api.py (651 → 5) - qdrant_service.py (638 → 5), training_api.py (625 → 4) website (6 pages): - middleware (696 → 8), mail (733 → 6), consent (628 → 8) - compliance/risks (622 → 5), export (502 → 5), brandbook (629 → 7) studio-v2 (3 components): - B2BMigrationWizard (848 → 3), CleanupPanel (765 → 2) - dashboard-experimental (739 → 2) admin-lehrer (4 files): - uebersetzungen (769 → 4), manager (670 → 2) - ChunkBrowserQA (675 → 6), dsfa/page (674 → 5) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
69
klausur-service/backend/mail/api_ai.py
Normal file
69
klausur-service/backend/mail/api_ai.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Mail API — AI analysis and response suggestion endpoints.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
|
||||
from .models import (
|
||||
EmailAnalysisResult,
|
||||
ResponseSuggestion,
|
||||
)
|
||||
from .mail_db import get_email
|
||||
from .ai_service import get_ai_email_service
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/v1/mail", tags=["Mail"])
|
||||
|
||||
|
||||
@router.post("/analyze/{email_id}", response_model=EmailAnalysisResult)
|
||||
async def analyze_email(
|
||||
email_id: str,
|
||||
user_id: str = Query(..., description="User ID"),
|
||||
):
|
||||
"""Run AI analysis on an email."""
|
||||
email_data = await get_email(email_id, user_id)
|
||||
if not email_data:
|
||||
raise HTTPException(status_code=404, detail="Email not found")
|
||||
|
||||
ai_service = get_ai_email_service()
|
||||
result = await ai_service.analyze_email(
|
||||
email_id=email_id,
|
||||
sender_email=email_data.get("sender_email", ""),
|
||||
sender_name=email_data.get("sender_name"),
|
||||
subject=email_data.get("subject", ""),
|
||||
body_text=email_data.get("body_text"),
|
||||
body_preview=email_data.get("body_preview"),
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/suggestions/{email_id}", response_model=List[ResponseSuggestion])
|
||||
async def get_response_suggestions(
|
||||
email_id: str,
|
||||
user_id: str = Query(..., description="User ID"),
|
||||
):
|
||||
"""Get AI-generated response suggestions for an email."""
|
||||
email_data = await get_email(email_id, user_id)
|
||||
if not email_data:
|
||||
raise HTTPException(status_code=404, detail="Email not found")
|
||||
|
||||
ai_service = get_ai_email_service()
|
||||
|
||||
# Use stored analysis if available
|
||||
from .models import SenderType, EmailCategory as EC
|
||||
sender_type = SenderType(email_data.get("sender_type", "unbekannt"))
|
||||
category = EC(email_data.get("category", "sonstiges"))
|
||||
|
||||
suggestions = await ai_service.suggest_response(
|
||||
subject=email_data.get("subject", ""),
|
||||
body_text=email_data.get("body_text", ""),
|
||||
sender_type=sender_type,
|
||||
category=category,
|
||||
)
|
||||
|
||||
return suggestions
|
||||
Reference in New Issue
Block a user