Skip to content

Commit

Permalink
Merge pull request #304 from n4ze3m/next
Browse files Browse the repository at this point in the history
bug fixes
  • Loading branch information
n4ze3m authored Oct 15, 2024
2 parents 919a0c3 + d80b60e commit 47299c2
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "app",
"private": true,
"version": "1.11.3",
"version": "1.11.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
1 change: 0 additions & 1 deletion app/ui/src/hooks/useMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export const useMessage = () => {
method: "POST",
body: JSON.stringify({
message,
history,
history_id: historyId,
}),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 5 additions & 0 deletions server/src/handlers/api/v1/admin/delete.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
63 changes: 57 additions & 6 deletions server/src/handlers/api/v1/bot/playground/chat.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -143,7 +195,7 @@ export const chatRequestStreamHandler = async (
return handleErrorResponse(
history,
message,
"There was an error processing your request."
"No embedding model found"
);
}

Expand All @@ -165,7 +217,7 @@ export const chatRequestStreamHandler = async (
return handleErrorResponse(
history,
message,
"There was an error processing your request."
"Not model found"
);
}

Expand Down Expand Up @@ -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"
);
}
};
3 changes: 0 additions & 3 deletions server/src/schema/api/v1/bot/playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ export const chatRequestSchema: FastifySchema = {
message: {
type: "string",
},
history: {
type: "array",
},
history_id: {
type: "string",
},
Expand Down

0 comments on commit 47299c2

Please sign in to comment.