Skip to content

Commit 4f11fd2

Browse files
Create chatController.js
1 parent b46552f commit 4f11fd2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

controllers/chatController.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ragflow } from '../services/ragflowService.js';
2+
3+
export async function chatController(req, res) {
4+
try {
5+
const { sessionId, prompt } = req.body;
6+
7+
if (!sessionId || !prompt) {
8+
return res.status(400).json({ error: "Missing sessionId or prompt" });
9+
}
10+
11+
console.log(`Processing chat for session: ${sessionId} with prompt: ${prompt}`);
12+
13+
const response = await ragflow(sessionId, prompt);
14+
15+
if (!response) {
16+
return res.status(500).json({ error: "Failed to process request with RAGFlow" });
17+
}
18+
19+
return res.json({ sessionId, response });
20+
21+
} catch (error) {
22+
console.error("Error in chatController:", error);
23+
return res.status(500).json({ error: "Internal server error" });
24+
}
25+
}

0 commit comments

Comments
 (0)