Spaces:
Running
Running
import { Hono } from 'hono'; | |
import { streamSSE } from 'hono/streaming'; | |
const chatApp = new Hono(); | |
// Visual RAG Chat SSE endpoint | |
chatApp.get('/', async (c) => { | |
const queryId = c.req.query('queryId'); | |
const query = c.req.query('query'); | |
const docIds = c.req.query('docIds'); | |
if (!queryId || !query || !docIds) { | |
return c.json({ error: 'Missing required parameters: queryId, query, docIds' }, 400); | |
} | |
return streamSSE(c, async (stream) => { | |
try { | |
// Mock response for now - in production this would use an LLM | |
const messages = [ | |
`I'll analyze the search results for your query: "${query}"`, | |
"Based on the documents provided, here are the key findings:", | |
"1. LINQTO filed for Chapter 11 bankruptcy protection", | |
"2. The filing includes detailed financial statements and creditor information", | |
"3. Various claims and assets are documented in the court filings", | |
"", | |
"This is a demo response. In production, this would analyze the actual document contents using an LLM." | |
]; | |
for (const msg of messages) { | |
await stream.writeSSE({ data: msg }); | |
await new Promise(resolve => setTimeout(resolve, 300)); // Simulate typing | |
} | |
} catch (error) { | |
console.error('Chat streaming error:', error); | |
await stream.writeSSE({ | |
event: 'error', | |
data: JSON.stringify({ | |
error: 'Streaming failed', | |
message: error instanceof Error ? error.message : 'Unknown error' | |
}), | |
}); | |
} | |
}); | |
}); | |
export { chatApp }; |