mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-31 08:56:48 +00:00
feat: import shared convos
This commit is contained in:
parent
50a48efa43
commit
503b7f4d8d
6 changed files with 126 additions and 8 deletions
|
|
@ -242,8 +242,11 @@ router.post(
|
|||
async (req, res) => {
|
||||
try {
|
||||
/* TODO: optimize to return imported conversations and add manually */
|
||||
await importConversations({ filepath: req.file.path, requestUserId: req.user.id });
|
||||
res.status(201).json({ message: 'Conversation(s) imported successfully' });
|
||||
const conversationIds = await importConversations({
|
||||
filepath: req.file.path,
|
||||
requestUserId: req.user.id,
|
||||
});
|
||||
res.status(201).json({ message: 'Conversation(s) imported successfully', conversationIds });
|
||||
} catch (error) {
|
||||
logger.error('Error processing file', error);
|
||||
res.status(500).send('Error processing file');
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ const importConversations = async (job) => {
|
|||
const fileData = await fs.readFile(filepath, 'utf8');
|
||||
const jsonData = JSON.parse(fileData);
|
||||
const importer = getImporter(jsonData);
|
||||
await importer(jsonData, requestUserId);
|
||||
const conversationIds = await importer(jsonData, requestUserId);
|
||||
logger.debug(`user: ${requestUserId} | Finished importing conversations`);
|
||||
return conversationIds;
|
||||
} catch (error) {
|
||||
logger.error(`user: ${requestUserId} | Failed to import conversation: `, error);
|
||||
throw error; // throw error all the way up so request does not return success
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ async function importChatBotUiConvo(
|
|||
}
|
||||
await importBatchBuilder.saveBatch();
|
||||
logger.info(`user: ${requestUserId} | ChatbotUI conversation imported`);
|
||||
return importBatchBuilder.conversations.map((c) => c.conversationId);
|
||||
} catch (error) {
|
||||
logger.error(`user: ${requestUserId} | Error creating conversation from ChatbotUI file`, error);
|
||||
}
|
||||
|
|
@ -177,6 +178,7 @@ async function importClaudeConvo(
|
|||
|
||||
await importBatchBuilder.saveBatch();
|
||||
logger.info(`user: ${requestUserId} | Claude conversation imported`);
|
||||
return importBatchBuilder.conversations.map((c) => c.conversationId);
|
||||
} catch (error) {
|
||||
logger.error(`user: ${requestUserId} | Error creating conversation from Claude file`, error);
|
||||
}
|
||||
|
|
@ -272,6 +274,7 @@ async function importLibreChatConvo(
|
|||
importBatchBuilder.finishConversation(jsonData.title, firstMessageDate ?? new Date(), options);
|
||||
await importBatchBuilder.saveBatch();
|
||||
logger.debug(`user: ${requestUserId} | Conversation "${jsonData.title}" imported`);
|
||||
return importBatchBuilder.conversations.map((c) => c.conversationId);
|
||||
} catch (error) {
|
||||
logger.error(`user: ${requestUserId} | Error creating conversation from LibreChat file`, error);
|
||||
}
|
||||
|
|
@ -297,6 +300,7 @@ async function importChatGptConvo(
|
|||
processConversation(conv, importBatchBuilder, requestUserId);
|
||||
}
|
||||
await importBatchBuilder.saveBatch();
|
||||
return importBatchBuilder.conversations.map((c) => c.conversationId);
|
||||
} catch (error) {
|
||||
logger.error(`user: ${requestUserId} | Error creating conversation from imported file`, error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue