add optional web search functionality with UI updates and backend integration
This commit is contained in:
+10
-5
@@ -21,7 +21,8 @@ const sendMessageValidator = (body) => {
|
||||
const chatId = Number(body?.chatId);
|
||||
if (!chatId) return {error: "chatId is required"};
|
||||
if (!message) return {error: "message is required"};
|
||||
return {value: {message, chatId, model: String(body?.model || "mistral:latest")}};
|
||||
if (body.webSearch !== undefined && typeof body.webSearch !== "boolean") return {error: "webSearch must be a boolean"};
|
||||
return {value: {message, chatId, model: String(body?.model || "mistral:latest"), webSearch: body.webSearch === true}};
|
||||
};
|
||||
|
||||
const organizationValidator = (body) => ({
|
||||
@@ -234,7 +235,8 @@ export function createChatsRouter({repositories, chatService, modelService, conf
|
||||
chatId,
|
||||
targetMessage,
|
||||
content: req.validatedBody.message,
|
||||
model: req.validatedBody.model
|
||||
model: req.validatedBody.model,
|
||||
webSearch: req.validatedBody.webSearch
|
||||
});
|
||||
if (result.error) return res.status(result.status).json({error: result.error});
|
||||
return res.json(result);
|
||||
@@ -409,10 +411,11 @@ export function createChatsRouter({repositories, chatService, modelService, conf
|
||||
user: req.session.user,
|
||||
chatId: req.validatedBody.chatId,
|
||||
message: req.validatedBody.message,
|
||||
model: req.validatedBody.model
|
||||
model: req.validatedBody.model,
|
||||
webSearch: req.validatedBody.webSearch
|
||||
});
|
||||
if (result.error) return res.status(result.status).json({error: result.error});
|
||||
return res.json({reply: result.reply});
|
||||
return res.json({reply: result.reply, ...(result.sources ? {sources: result.sources} : {})});
|
||||
} catch (error) {
|
||||
const mapped = modelService.mapError(error);
|
||||
return res.status(mapped.status).json(mapped.body);
|
||||
@@ -444,12 +447,14 @@ export function createChatsRouter({repositories, chatService, modelService, conf
|
||||
message: req.validatedBody.message,
|
||||
model: req.validatedBody.model,
|
||||
onChunk: (chunk, fullReply) => sendEvent("chunk", {chunk, fullReply}),
|
||||
webSearch: req.validatedBody.webSearch,
|
||||
onStatus: (status) => sendEvent("status", status),
|
||||
signal: generationController.signal
|
||||
});
|
||||
if (result.error) {
|
||||
sendEvent("error", {error: result.error});
|
||||
} else {
|
||||
sendEvent("done", {reply: result.reply});
|
||||
sendEvent("done", {reply: result.reply, ...(result.sources ? {sources: result.sources} : {})});
|
||||
}
|
||||
} catch (error) {
|
||||
const mapped = modelService.mapError(error);
|
||||
|
||||
Reference in New Issue
Block a user