Skip to content

Commit

Permalink
feat: Remove unused history field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
n4ze3m committed Oct 15, 2024
1 parent 7bff567 commit cd796bc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
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
56 changes: 54 additions & 2 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 Down
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 cd796bc

Please sign in to comment.