feat(editing): Adds the ability to edit messages
This commit is contained in:
parent
b96c4234f4
commit
380216e062
4 changed files with 112 additions and 89 deletions
|
|
@ -16,7 +16,7 @@ import { AIMessage, BaseMessage, HumanMessage } from '@langchain/core/messages';
|
|||
import { ChatOllama } from '@langchain/ollama';
|
||||
import { ChatOpenAI } from '@langchain/openai';
|
||||
import crypto from 'crypto';
|
||||
import { and, eq, gte } from 'drizzle-orm';
|
||||
import { and, eq, gt } from 'drizzle-orm';
|
||||
import { EventEmitter } from 'stream';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
|
@ -210,11 +210,21 @@ const handleHistorySave = async (
|
|||
})
|
||||
.execute();
|
||||
} else {
|
||||
await db
|
||||
.update(messagesSchema)
|
||||
.set({
|
||||
content: message.content,
|
||||
metadata: JSON.stringify({
|
||||
createdAt: new Date(),
|
||||
}),
|
||||
})
|
||||
.where(eq(messagesSchema.messageId, humanMessageId))
|
||||
.execute();
|
||||
await db
|
||||
.delete(messagesSchema)
|
||||
.where(
|
||||
and(
|
||||
gte(messagesSchema.id, messageExists.id),
|
||||
gt(messagesSchema.id, messageExists.id),
|
||||
eq(messagesSchema.chatId, message.chatId),
|
||||
),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue