Main chat endpoint that receives files and instructions Args: message: User's text message content: 'paper' or 'general' output_type: 'slides' or 'poster' style: 'academic', 'doraemon', or custom description length: 'short', 'medium', 'long' (for
(
background_tasks: BackgroundTasks,
message: str = Form(""),
content: str = Form("paper"), # 'paper' or 'general'
output_type: str = Form("slides"), # 'slides' or 'poster'
style: str = Form("doraemon"), # 'academic', 'doraemon', or custom description
length: Optional[str] = Form(None), # 'short', 'medium', 'long' (for slides)
density: Optional[str] = Form(None), # 'sparse', 'medium', 'dense' (for poster)
fast_mode: Optional[str] = Form(None), # 'true' or 'false' - fast mode for paper content
session_id: Optional[str] = Form(None), # Existing session ID to reuse files
files: List[UploadFile] = File([])
)
| 144 | |
| 145 | @app.post("/api/chat", response_model=ChatResponse) |
| 146 | async def chat( |
| 147 | background_tasks: BackgroundTasks, |
| 148 | message: str = Form(""), |
| 149 | content: str = Form("paper"), # 'paper' or 'general' |
| 150 | output_type: str = Form("slides"), # 'slides' or 'poster' |
| 151 | style: str = Form("doraemon"), # 'academic', 'doraemon', or custom description |
| 152 | length: Optional[str] = Form(None), # 'short', 'medium', 'long' (for slides) |
| 153 | density: Optional[str] = Form(None), # 'sparse', 'medium', 'dense' (for poster) |
| 154 | fast_mode: Optional[str] = Form(None), # 'true' or 'false' - fast mode for paper content |
| 155 | session_id: Optional[str] = Form(None), # Existing session ID to reuse files |
| 156 | files: List[UploadFile] = File([]) |
| 157 | ): |
| 158 | """ |
| 159 | Main chat endpoint that receives files and instructions |
| 160 | |
| 161 | Args: |
| 162 | message: User's text message |
| 163 | content: 'paper' or 'general' |
| 164 | output_type: 'slides' or 'poster' |
| 165 | style: 'academic', 'doraemon', or custom description |
| 166 | length: 'short', 'medium', 'long' (for slides) |
| 167 | density: 'sparse', 'medium', 'dense' (for poster) |
| 168 | fast_mode: 'true' or 'false' - fast mode for paper content (no RAG indexing) |
| 169 | session_id: Optional existing session ID to reuse files (for regeneration) |
| 170 | files: List of uploaded files (PDF, MD, etc.) |
| 171 | |
| 172 | Returns: |
| 173 | Response with session ID - actual generation happens in background |
| 174 | """ |
| 175 | try: |
| 176 | # Check if another session is already running |
| 177 | running_session = session_manager.get_running_session() |
| 178 | |
| 179 | # Check if reusing existing session |
| 180 | reusing_session = False |
| 181 | if session_id and not files: |
| 182 | # Reuse existing session |
| 183 | session_dir = UPLOAD_DIR / session_id |
| 184 | if session_dir.exists(): |
| 185 | reusing_session = True |
| 186 | print(f"Reusing existing session: {session_id[:8]}") |
| 187 | |
| 188 | # Check if this is a different session from the running one |
| 189 | if running_session and running_session != session_id: |
| 190 | raise HTTPException( |
| 191 | status_code=409, |
| 192 | detail=f"Another session is already running. Please wait for it to complete. Running session: {running_session[:8]}" |
| 193 | ) |
| 194 | else: |
| 195 | raise HTTPException(status_code=404, detail=f"Session {session_id} not found") |
| 196 | else: |
| 197 | # Generate new session ID |
| 198 | if running_session: |
| 199 | raise HTTPException( |
| 200 | status_code=409, |
| 201 | detail=f"Another session is already running. Please wait for it to complete. Running session: {running_session[:8]}" |
| 202 | ) |
| 203 |
nothing calls this directly
no test coverage detected