| import { NextResponse } from 'next/server'; |
| import { quickDetectErrors } from '@/lib/ollama'; |
| import type { QuickAnalyzeRequest } from '@/types'; |
|
|
| |
| export async function POST(request: Request) { |
| try { |
| const body: QuickAnalyzeRequest = await request.json(); |
|
|
| |
| if (!body.text || body.text.trim().length === 0) { |
| return NextResponse.json( |
| { |
| success: false, |
| error: 'Clinical note text is required', |
| }, |
| { status: 400 } |
| ); |
| } |
|
|
| if (!body.model) { |
| return NextResponse.json( |
| { |
| success: false, |
| error: 'Model selection is required', |
| }, |
| { status: 400 } |
| ); |
| } |
|
|
| |
| const result = await quickDetectErrors(body.text, body.model); |
|
|
| return NextResponse.json({ |
| success: true, |
| data: result, |
| }); |
| } catch (error) { |
| const message = error instanceof Error ? error.message : 'Quick analysis failed'; |
|
|
| |
| if (message.includes('timeout') || message.includes('Timeout')) { |
| return NextResponse.json( |
| { |
| success: false, |
| error: 'Quick analysis timed out.', |
| }, |
| { status: 504 } |
| ); |
| } |
|
|
| if (message.includes('connect') || message.includes('Connection')) { |
| return NextResponse.json( |
| { |
| success: false, |
| error: 'Cannot connect to Ollama server. Make sure Ollama is running.', |
| }, |
| { status: 503 } |
| ); |
| } |
|
|
| return NextResponse.json( |
| { |
| success: false, |
| error: message, |
| }, |
| { status: 500 } |
| ); |
| } |
| } |
|
|