anything-llm/server/endpoints/chat.js

28 lines
799 B
JavaScript
Raw Normal View History

2023-06-08 06:31:35 +02:00
const { reqBody } = require("../utils/http");
const { Workspace } = require("../models/workspace");
const { chatWithWorkspace } = require("../utils/chats");
2023-06-04 04:28:07 +02:00
function chatEndpoints(app) {
if (!app) return;
2023-06-08 06:31:35 +02:00
app.post("/workspace/:slug/chat", async (request, response) => {
try {
const { slug } = request.params;
const { message, mode = "query" } = reqBody(request);
const workspace = await Workspace.get(`slug = '${slug}'`);
if (!workspace) {
response.sendStatus(400).end();
return;
}
2023-06-04 04:28:07 +02:00
const result = await chatWithWorkspace(workspace, message, mode);
response.status(200).json({ ...result });
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
2023-06-08 06:31:35 +02:00
});
2023-06-04 04:28:07 +02:00
}
2023-06-08 06:31:35 +02:00
module.exports = { chatEndpoints };