diff --git a/app/ui/package.json b/app/ui/package.json index 591026dc..0c0ddb22 100644 --- a/app/ui/package.json +++ b/app/ui/package.json @@ -1,7 +1,7 @@ { "name": "app", "private": true, - "version": "1.11.3", + "version": "1.11.4", "type": "module", "scripts": { "dev": "vite", 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/package.json b/package.json index 3fb326e0..f2da3209 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dialoqbase", - "version": "1.11.3", + "version": "1.11.4", "description": "Create chatbots with ease", "scripts": { "ui:dev": "pnpm run --filter ui dev", diff --git a/server/src/handlers/api/v1/admin/delete.handler.ts b/server/src/handlers/api/v1/admin/delete.handler.ts index b4b3a9ea..5c134c18 100644 --- a/server/src/handlers/api/v1/admin/delete.handler.ts +++ b/server/src/handlers/api/v1/admin/delete.handler.ts @@ -132,6 +132,11 @@ export const adminDeleteUserHandler = async ( }, }); } + await tx.userApiKey.deleteMany({ + where: { + user_id: request.body.user_id, + }, + }); await tx.user.delete({ where: { user_id: request.body.user_id, 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..a2250125 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, @@ -143,7 +195,7 @@ export const chatRequestStreamHandler = async ( return handleErrorResponse( history, message, - "There was an error processing your request." + "No embedding model found" ); } @@ -165,7 +217,7 @@ export const chatRequestStreamHandler = async ( return handleErrorResponse( history, message, - "There was an error processing your request." + "Not model found" ); } @@ -236,11 +288,10 @@ export const chatRequestStreamHandler = async ( await nextTick(); return reply.raw.end(); } catch (e) { - console.error(e); return handleErrorResponse( history, message, - "There was an error processing your request." + "Internal Server Error" ); } }; 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", },