chore: Update npm dependency versions and add export/import functions for chat history and knowledge
This commit is contained in:
parent
88ad1fcab7
commit
11147fd951
@ -37,7 +37,7 @@
|
||||
"langchain": "^0.1.28",
|
||||
"lucide-react": "^0.350.0",
|
||||
"ml-distance": "^4.0.1",
|
||||
"pdfjs-dist": "^4.0.379",
|
||||
"pdfjs-dist": "4.0.379",
|
||||
"property-information": "^6.4.1",
|
||||
"pubsub-js": "^1.9.4",
|
||||
"react": "18.2.0",
|
||||
|
@ -417,3 +417,30 @@ export const getUserId = async () => {
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
export const exportChatHistory = async () => {
|
||||
const db = new PageAssitDatabase()
|
||||
const chatHistories = await db.getChatHistories()
|
||||
const messages = await Promise.all(
|
||||
chatHistories.map(async (history) => {
|
||||
const messages = await db.getChatHistory(history.id)
|
||||
return { history, messages }
|
||||
})
|
||||
)
|
||||
return messages
|
||||
}
|
||||
|
||||
export const importChatHistory = async (
|
||||
data: {
|
||||
history: HistoryInfo
|
||||
messages: MessageHistory
|
||||
}[]
|
||||
) => {
|
||||
const db = new PageAssitDatabase()
|
||||
for (const { history, messages } of data) {
|
||||
await db.addChatHistory(history)
|
||||
for (const message of messages) {
|
||||
await db.addMessage(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,3 +190,16 @@ export const deleteSource = async (id: string, source_id: string) => {
|
||||
await db.deleteSource(id, source_id)
|
||||
await deleteVectorByFileId(`vector:${id}`, source_id)
|
||||
}
|
||||
|
||||
export const exportKnowledge = async () => {
|
||||
const db = new PageAssistKnowledge()
|
||||
const data = await db.getAll()
|
||||
return data
|
||||
}
|
||||
|
||||
export const importKnowledge = async (data: Knowledge[]) => {
|
||||
const db = new PageAssistKnowledge()
|
||||
for (const d of data) {
|
||||
await db.create(d)
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +100,18 @@ export class PageAssistVectorDb {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
getAll = async (): Promise<VectorData[]> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.db.get(null, (result) => {
|
||||
if (chrome.runtime.lastError) {
|
||||
reject(chrome.runtime.lastError)
|
||||
} else {
|
||||
resolve(Object.values(result))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const insertVector = async (
|
||||
@ -127,3 +139,16 @@ export const deleteVectorByFileId = async (
|
||||
const db = new PageAssistVectorDb()
|
||||
return db.deleteVectorByFileId(id, file_id)
|
||||
}
|
||||
|
||||
export const exportVectors = async () => {
|
||||
const db = new PageAssistVectorDb()
|
||||
const data = await db.getAll()
|
||||
return data
|
||||
}
|
||||
|
||||
export const importVectors = async (data: VectorData[]) => {
|
||||
const db = new PageAssistVectorDb()
|
||||
for (const d of data) {
|
||||
await db.insertVector(d.id, d.vectors)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user