Skip to content

Commit 47299c2

Browse files
authored
Merge pull request #304 from n4ze3m/next
bug fixes
2 parents 919a0c3 + d80b60e commit 47299c2

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

app/ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "app",
33
"private": true,
4-
"version": "1.11.3",
4+
"version": "1.11.4",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

app/ui/src/hooks/useMessage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ export const useMessage = () => {
107107
method: "POST",
108108
body: JSON.stringify({
109109
message,
110-
history,
111110
history_id: historyId,
112111
}),
113112
headers: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dialoqbase",
3-
"version": "1.11.3",
3+
"version": "1.11.4",
44
"description": "Create chatbots with ease",
55
"scripts": {
66
"ui:dev": "pnpm run --filter ui dev",

server/src/handlers/api/v1/admin/delete.handler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ export const adminDeleteUserHandler = async (
132132
},
133133
});
134134
}
135+
await tx.userApiKey.deleteMany({
136+
where: {
137+
user_id: request.body.user_id,
138+
},
139+
});
135140
await tx.user.delete({
136141
where: {
137142
user_id: request.body.user_id,

server/src/handlers/api/v1/bot/playground/chat.handler.ts

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export const chatRequestHandler = async (
1717
reply: FastifyReply
1818
) => {
1919
const { id: bot_id } = request.params;
20-
const { message, history, history_id } = request.body;
20+
const { message, history_id } = request.body;
21+
let history = [];
2122

2223
try {
2324
const prisma = request.server.prisma;
@@ -33,6 +34,30 @@ export const chatRequestHandler = async (
3334
);
3435
}
3536

37+
38+
if (history_id) {
39+
const details = await prisma.botPlayground.findFirst({
40+
where: {
41+
id: history_id,
42+
botId: bot_id,
43+
},
44+
include: {
45+
BotPlaygroundMessage: {
46+
orderBy: {
47+
createdAt: "asc",
48+
},
49+
},
50+
},
51+
});
52+
53+
const botMessages = details?.BotPlaygroundMessage.map((message) => ({
54+
type: message.type,
55+
text: message.message,
56+
}));
57+
58+
history = botMessages || [];
59+
}
60+
3661
const embeddingInfo = await getModelInfo({
3762
model: bot.embedding,
3863
prisma,
@@ -117,7 +142,8 @@ export const chatRequestStreamHandler = async (
117142
reply: FastifyReply
118143
) => {
119144
const { id: bot_id } = request.params;
120-
const { message, history, history_id } = request.body;
145+
const { message, history_id } = request.body;
146+
let history = [];
121147

122148
try {
123149
const prisma = request.server.prisma;
@@ -133,6 +159,32 @@ export const chatRequestStreamHandler = async (
133159
);
134160
}
135161

162+
163+
if (history_id) {
164+
const details = await prisma.botPlayground.findFirst({
165+
where: {
166+
id: history_id,
167+
botId: bot_id,
168+
},
169+
include: {
170+
BotPlaygroundMessage: {
171+
orderBy: {
172+
createdAt: "asc",
173+
},
174+
},
175+
},
176+
});
177+
178+
const botMessages = details?.BotPlaygroundMessage.map((message) => ({
179+
type: message.type,
180+
text: message.message,
181+
}));
182+
183+
history = botMessages || [];
184+
}
185+
186+
187+
136188
const embeddingInfo = await getModelInfo({
137189
model: bot.embedding,
138190
prisma,
@@ -143,7 +195,7 @@ export const chatRequestStreamHandler = async (
143195
return handleErrorResponse(
144196
history,
145197
message,
146-
"There was an error processing your request."
198+
"No embedding model found"
147199
);
148200
}
149201

@@ -165,7 +217,7 @@ export const chatRequestStreamHandler = async (
165217
return handleErrorResponse(
166218
history,
167219
message,
168-
"There was an error processing your request."
220+
"Not model found"
169221
);
170222
}
171223

@@ -236,11 +288,10 @@ export const chatRequestStreamHandler = async (
236288
await nextTick();
237289
return reply.raw.end();
238290
} catch (e) {
239-
console.error(e);
240291
return handleErrorResponse(
241292
history,
242293
message,
243-
"There was an error processing your request."
294+
"Internal Server Error"
244295
);
245296
}
246297
};

server/src/schema/api/v1/bot/playground/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ export const chatRequestSchema: FastifySchema = {
2626
message: {
2727
type: "string",
2828
},
29-
history: {
30-
type: "array",
31-
},
3229
history_id: {
3330
type: "string",
3431
},

0 commit comments

Comments
 (0)