Add edit functionality to PlaygroundMessage component

This commit is contained in:
n4ze3m
2024-03-16 00:30:41 +05:30
parent 5b04e55a03
commit 78c44e13b0
6 changed files with 197 additions and 11 deletions

View File

@@ -299,6 +299,22 @@ export const getAllPrompts = async () => {
}
export const updateMessageByIndex = async (history_id: string, index: number, message: string) => {
const db = new PageAssitDatabase()
const chatHistory = (await db.getChatHistory(history_id)).reverse()
chatHistory[index].content = message
await db.db.set({ [history_id]: chatHistory.reverse() })
}
export const deleteChatForEdit = async (history_id: string, index: number) => {
const db = new PageAssitDatabase()
const chatHistory = (await db.getChatHistory(history_id)).reverse()
const previousHistory = chatHistory.slice(0, index + 1)
// console.log(previousHistory)
await db.db.set({ [history_id]: previousHistory.reverse() })
}
export const savePrompt = async ({ content, title, is_system = false }: { title: string, content: string, is_system: boolean }) => {
const db = new PageAssitDatabase()
const id = generateID()