From 7bff5679919c15d9b936b86a3498a43e3ebc8dd4 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 15 Oct 2024 18:03:07 +0530 Subject: [PATCH 1/3] feat: Delete associated API keys when deleting a user When deleting a user, also delete any associated API keys to ensure a clean and consistent data state. This prevents orphaned API keys from existing, improving security and data integrity. --- app/ui/package.json | 2 +- package.json | 2 +- server/src/handlers/api/v1/admin/delete.handler.ts | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) 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/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, From cd796bce75faa2fd39aba666e8b9c517333fe1e4 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 15 Oct 2024 19:01:37 +0530 Subject: [PATCH 2/3] feat: Remove unused `history` field The `history` field in the chat request body was no longer used. This change removes the unnecessary field, simplifying the API and improving efficiency. This change also introduces a mechanism to retrieve and utilize existing conversation history from the database based on the provided `history_id`. This allows for more seamless and interactive conversation experiences. --- app/ui/src/hooks/useMessage.tsx | 1 - .../api/v1/bot/playground/chat.handler.ts | 56 ++++++++++++++++++- .../src/schema/api/v1/bot/playground/index.ts | 3 - 3 files changed, 54 insertions(+), 6 deletions(-) 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", }, From d80b60e2b12d173e181cf1c2b9e3f1e9214a3967 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Tue, 15 Oct 2024 19:13:25 +0530 Subject: [PATCH 3/3] Fix: More informative error messages in playground Improved error messages in the playground to provide more specific feedback to the user when encountering issues. This makes it easier to understand the reason for the error and potentially resolve the problem. --- server/src/handlers/api/v1/bot/playground/chat.handler.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 c195aba6..a2250125 100644 --- a/server/src/handlers/api/v1/bot/playground/chat.handler.ts +++ b/server/src/handlers/api/v1/bot/playground/chat.handler.ts @@ -195,7 +195,7 @@ export const chatRequestStreamHandler = async ( return handleErrorResponse( history, message, - "There was an error processing your request." + "No embedding model found" ); } @@ -217,7 +217,7 @@ export const chatRequestStreamHandler = async ( return handleErrorResponse( history, message, - "There was an error processing your request." + "Not model found" ); } @@ -288,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" ); } };