File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments