Skip to content

Commit 8750d09

Browse files
Merge pull request #98 from DataScienceUIBK/demo
fix
2 parents e893f09 + 2e69517 commit 8750d09

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export const runtime = 'nodejs';
2+
3+
const PYTHON_API = process.env.RANKIFY_API_URL || 'http://localhost:8000';
4+
5+
export async function POST(req: Request) {
6+
try {
7+
const body = await req.json();
8+
9+
const res = await fetch(`${PYTHON_API}/api/agent/chat`, {
10+
method: 'POST',
11+
headers: { 'Content-Type': 'application/json' },
12+
body: JSON.stringify(body),
13+
});
14+
15+
if (!res.ok) {
16+
const errText = await res.text().catch(() => `HTTP ${res.status}`);
17+
return new Response(`data: {"type": "error", "message": ${JSON.stringify(errText)}}\n\n`, {
18+
status: 200,
19+
headers: { 'Content-Type': 'text/event-stream' }
20+
});
21+
}
22+
23+
return new Response(res.body, {
24+
status: 200,
25+
headers: {
26+
'Content-Type': 'text/event-stream',
27+
'Cache-Control': 'no-cache',
28+
'Connection': 'keep-alive',
29+
},
30+
});
31+
} catch (error: any) {
32+
return new Response(`data: {"type": "error", "message": ${JSON.stringify(error.message)}}\n\n`, {
33+
status: 200,
34+
headers: { 'Content-Type': 'text/event-stream' }
35+
});
36+
}
37+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const runtime = 'nodejs';
2+
3+
const PYTHON_API = process.env.RANKIFY_API_URL || 'http://localhost:8000';
4+
5+
export async function POST(req: Request) {
6+
try {
7+
const body = await req.json();
8+
9+
const res = await fetch(`${PYTHON_API}/api/arena/run`, {
10+
method: 'POST',
11+
headers: { 'Content-Type': 'application/json' },
12+
body: JSON.stringify(body),
13+
});
14+
15+
if (!res.ok) {
16+
const errText = await res.text().catch(() => `HTTP ${res.status}`);
17+
return new Response(JSON.stringify({ detail: errText }), { status: res.status });
18+
}
19+
20+
const data = await res.json();
21+
return new Response(JSON.stringify(data), {
22+
status: 200,
23+
headers: { 'Content-Type': 'application/json' }
24+
});
25+
} catch (error: any) {
26+
return new Response(JSON.stringify({ detail: error.message }), { status: 500 });
27+
}
28+
}

0 commit comments

Comments
 (0)