Best way to flush LF in Next.js? #1055
-
I'm currently implementing LF in a Next.js app and have trouble correctly flushing events. I want to avoid using showdownAsync, as this seemed to slow down my functions a lot. lf.flush doesnt flush events correctly either, and when I try: const langfuse = new Langfuse({
baseUrl: 'xxxx',
secretKey: process.env.LANGFUSE_SECRET_KEY,
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
flushAt: 1,
flushInterval: 0
}); not all assistant responses are logged. Any ideas/examples? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
How do you deploy your NextJS application? If you deploy serverless (eg AWS Lambda), there's no way around shutdownAsync as otherwise the function is terminated before all events are batched to the Langfuse API. I've built a quick demo of Langfuse (blog post) some time ago which uses NextJS and streaming responses. Maybe these lines are helpful: |
Beta Was this translation helpful? Give feedback.
How do you deploy your NextJS application? If you deploy serverless (eg AWS Lambda), there's no way around shutdownAsync as otherwise the function is terminated before all events are batched to the Langfuse API.
I've built a quick demo of Langfuse (blog post) some time ago which uses NextJS and streaming responses. Maybe these lines are helpful:
https://github.com/langfuse/langfuse-docs/blob/9581297f5abeda767abd2d769c9f7a034a51e95f/pages/api/qa-chatbot.ts#L192-L224