diff --git a/app/ui/src/hooks/useMessage.tsx b/app/ui/src/hooks/useMessage.tsx index 494919be..fc9994fa 100644 --- a/app/ui/src/hooks/useMessage.tsx +++ b/app/ui/src/hooks/useMessage.tsx @@ -107,7 +107,6 @@ export const useMessage = () => { method: "POST", body: JSON.stringify({ message, - history, history_id: historyId, }), headers: { diff --git a/server/src/handlers/api/v1/bot/playground/chat.handler.ts b/server/src/handlers/api/v1/bot/playground/chat.handler.ts index a4f27606..c195aba6 100644 --- a/server/src/handlers/api/v1/bot/playground/chat.handler.ts +++ b/server/src/handlers/api/v1/bot/playground/chat.handler.ts @@ -17,7 +17,8 @@ export const chatRequestHandler = async ( reply: FastifyReply ) => { const { id: bot_id } = request.params; - const { message, history, history_id } = request.body; + const { message, history_id } = request.body; + let history = []; try { const prisma = request.server.prisma; @@ -33,6 +34,30 @@ export const chatRequestHandler = async ( ); } + + if (history_id) { + const details = await prisma.botPlayground.findFirst({ + where: { + id: history_id, + botId: bot_id, + }, + include: { + BotPlaygroundMessage: { + orderBy: { + createdAt: "asc", + }, + }, + }, + }); + + const botMessages = details?.BotPlaygroundMessage.map((message) => ({ + type: message.type, + text: message.message, + })); + + history = botMessages || []; + } + const embeddingInfo = await getModelInfo({ model: bot.embedding, prisma, @@ -117,7 +142,8 @@ export const chatRequestStreamHandler = async ( reply: FastifyReply ) => { const { id: bot_id } = request.params; - const { message, history, history_id } = request.body; + const { message, history_id } = request.body; + let history = []; try { const prisma = request.server.prisma; @@ -133,6 +159,32 @@ export const chatRequestStreamHandler = async ( ); } + + if (history_id) { + const details = await prisma.botPlayground.findFirst({ + where: { + id: history_id, + botId: bot_id, + }, + include: { + BotPlaygroundMessage: { + orderBy: { + createdAt: "asc", + }, + }, + }, + }); + + const botMessages = details?.BotPlaygroundMessage.map((message) => ({ + type: message.type, + text: message.message, + })); + + history = botMessages || []; + } + + + const embeddingInfo = await getModelInfo({ model: bot.embedding, prisma, diff --git a/server/src/schema/api/v1/bot/playground/index.ts b/server/src/schema/api/v1/bot/playground/index.ts index c778ee1f..4005547d 100644 --- a/server/src/schema/api/v1/bot/playground/index.ts +++ b/server/src/schema/api/v1/bot/playground/index.ts @@ -26,9 +26,6 @@ export const chatRequestSchema: FastifySchema = { message: { type: "string", }, - history: { - type: "array", - }, history_id: { type: "string", },