Spaces:
Sleeping
Sleeping
v4.0: Add web /api/redline route for clause redlining
Browse files- web/app/api/redline/route.ts +37 -0
web/app/api/redline/route.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
|
| 3 |
+
const API_URL = process.env.CLAUSEGUARD_API_URL || "https://gaurv007-clauseguard-api.hf.space";
|
| 4 |
+
|
| 5 |
+
export async function POST(req: NextRequest) {
|
| 6 |
+
try {
|
| 7 |
+
const body = await req.json();
|
| 8 |
+
const { session_id, text, use_llm } = body;
|
| 9 |
+
|
| 10 |
+
if (!session_id && !text) {
|
| 11 |
+
return NextResponse.json(
|
| 12 |
+
{ error: "Provide session_id or text" },
|
| 13 |
+
{ status: 400 }
|
| 14 |
+
);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
const response = await fetch(`${API_URL}/api/redline`, {
|
| 18 |
+
method: "POST",
|
| 19 |
+
headers: { "Content-Type": "application/json" },
|
| 20 |
+
body: JSON.stringify({ session_id, text, use_llm: use_llm ?? true }),
|
| 21 |
+
});
|
| 22 |
+
|
| 23 |
+
if (!response.ok) {
|
| 24 |
+
const err = await response.text().catch(() => "");
|
| 25 |
+
throw new Error(err || `Backend error: ${response.status}`);
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
const result = await response.json();
|
| 29 |
+
return NextResponse.json(result);
|
| 30 |
+
} catch (error: any) {
|
| 31 |
+
console.error("Redline error:", error.message);
|
| 32 |
+
return NextResponse.json(
|
| 33 |
+
{ error: error.message || "Redlining failed" },
|
| 34 |
+
{ status: 500 }
|
| 35 |
+
);
|
| 36 |
+
}
|
| 37 |
+
}
|