Files
ALwrity/backend/api/writing_assistant.py
ajaysi 928c2f20aa fix: WYSIWYG editor, content generation, and writing assistant bug fixes
- Fix text selection menu not showing: wire contentRef via inputRef on multiline TextField
- Fix blog title not truncating: add min-w-0 for flex item overflow
- Fix outline generation 500: escape curly braces in f-string prompt template
- Fix content generation 'NoneType not callable': replace SessionLocal() with get_session_for_user(), add db param to MediumBlogGenerator, fix signature mismatch in database_task_manager
- Fix writing assistant suggest 500: add auth + user_id to API endpoint and service, replace sync requests with httpx.AsyncClient
- Fix hallucination detector 404: explicitly include router in main.py and app.py
- Fix missing error_data in task failure responses
- Hide CopilotKit web inspector button
- Remove hardcoded fallback suggestions from SmartTypingAssist
- Fix stale closure refs in SmartTypingAssist handleTypingChange
- Add two-column editor layout, stats bar, section hover menu
- Various subscription, billing, and research module improvements
2026-05-14 09:11:51 +05:30

63 lines
1.6 KiB
Python

from fastapi import APIRouter, Depends, HTTPException
from pydantic import BaseModel
from typing import List, Any, Dict
from loguru import logger
from services.writing_assistant import WritingAssistantService
from middleware.auth_middleware import get_current_user
router = APIRouter(prefix="/api/writing-assistant", tags=["writing-assistant"])
class SuggestRequest(BaseModel):
text: str
class SourceModel(BaseModel):
title: str
url: str
text: str | None = ""
author: str | None = ""
published_date: str | None = ""
score: float
class SuggestionModel(BaseModel):
text: str
confidence: float
sources: List[SourceModel]
class SuggestResponse(BaseModel):
success: bool
suggestions: List[SuggestionModel]
assistant_service = WritingAssistantService()
@router.post("/suggest", response_model=SuggestResponse)
async def suggest_endpoint(req: SuggestRequest, current_user: Dict[str, Any] = Depends(get_current_user)) -> SuggestResponse:
try:
user_id = current_user.get("id")
suggestions = await assistant_service.suggest(req.text, user_id=user_id)
return SuggestResponse(
success=True,
suggestions=[
SuggestionModel(
text=s.text,
confidence=s.confidence,
sources=[
SourceModel(**src) for src in s.sources
],
)
for s in suggestions
],
)
except Exception as e:
logger.error(f"Writing assistant error: {e}")
raise HTTPException(status_code=500, detail=str(e))