@@ -35,10 +35,10 @@ export async function streamLangbaseResponse(prompt: string, res: Response, opti
3535 const langbase = new Langbase ( {
3636 apiKey : process . env . LANGBASE_API_KEY ! ,
3737 } ) ;
38-
38+
3939 // Store the complete answer for saving later
4040 let completeAnswer = '' ;
41-
41+
4242 // Run the pipe
4343 const { stream } = await langbase . pipe . run ( {
4444 name : options . pipeName ,
@@ -50,35 +50,36 @@ export async function streamLangbaseResponse(prompt: string, res: Response, opti
5050 } ,
5151 ] ,
5252 } ) ;
53-
53+
5454 // Set up the runner to handle the stream
5555 const runner = getRunner ( stream ) ;
56-
56+
5757 // Handle content chunks
5858 runner . on ( 'content' , content => {
5959 // Send chunk to client
6060 res . write ( `data: ${ JSON . stringify ( { content } ) } \n\n` ) ;
61-
61+
6262 // Accumulate the complete answer
6363 completeAnswer += content ;
6464 } ) ;
65-
65+
6666 // Handle stream end
6767 runner . on ( 'end' , async ( ) => {
6868 // Save the complete answer to the database
6969 await prismaClient . question . create ( {
7070 data : {
7171 project : { connect : { id : options . projectId } } ,
7272 question : options . prompt ,
73- answer : completeAnswer
73+ answer : completeAnswer ,
74+ user : { connect : { id : options . userId } }
7475 }
7576 } ) ;
76-
77+
7778 // // End the response
7879 res . write ( `data: ${ JSON . stringify ( { done : true } ) } \n\n` ) ;
7980 res . end ( ) ;
8081 } ) ;
81-
82+
8283 // Handle errors
8384 runner . on ( 'error' , error => {
8485 console . error ( "Streaming error:" , error ) ;
@@ -126,6 +127,4 @@ export async function streamLangbaseResponse(prompt: string, res: Response, opti
126127// async function main() {
127128// //createPipe('ccb6b329-a7fd-45af-81f5-64f9bd80763a_GENSTACK Final','ccb6b329-a7fd-45af-81f5-64f9bd80763a-gen-stack-final')
128129// callpipe('ccb6b329-a7fd-45af-81f5-64f9bd80763a-genstack-final','WHat is this repo about')
129- // }
130-
131- // main();
130+ // }
0 commit comments