feat: Add export/import functions for chat history, promt and knowledge
This commit is contained in:
@@ -444,3 +444,15 @@ export const importChatHistory = async (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const exportPrompts = async () => {
|
||||
const db = new PageAssitDatabase()
|
||||
return await db.getAllPrompts()
|
||||
}
|
||||
|
||||
export const importPrompts = async (prompts: Prompts) => {
|
||||
const db = new PageAssitDatabase()
|
||||
for (const prompt of prompts) {
|
||||
await db.addPrompt(prompt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,22 @@ export class PageAssistVectorDb {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
saveImportedData = async (data: VectorData[]): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const obj: Record<string, VectorData> = {}
|
||||
data.forEach((d) => {
|
||||
obj[d.id] = d
|
||||
})
|
||||
this.db.set(obj, () => {
|
||||
if (chrome.runtime.lastError) {
|
||||
reject(chrome.runtime.lastError)
|
||||
} else {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const insertVector = async (
|
||||
@@ -148,7 +164,5 @@ export const exportVectors = async () => {
|
||||
|
||||
export const importVectors = async (data: VectorData[]) => {
|
||||
const db = new PageAssistVectorDb()
|
||||
for (const d of data) {
|
||||
await db.insertVector(d.id, d.vectors)
|
||||
}
|
||||
return db.saveImportedData(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user