Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Import/export from ChatGPT + backup (and restore) all conversations for LibreChat #1660

Open
1 task done
darkBuddha opened this issue Jan 28, 2024 · 13 comments
Labels
enhancement New feature or request

Comments

@darkBuddha
Copy link

What features would you like to see added?

I guess most people that start to use LibreChat used ChatGPT before. A fair amount of them will switch fully to LibreChat and not use ChatGPT again.

As ChatGPT allows to export all chats into a nice JSON, maybe it would be a cool feature to be able to import these timestamped JSON messages into LibreChat, to not lose the history?

Also, the ChatGPT chats are not private and used for training. So there is an incentive to delete the Chats from ChatGPT.

More details

I think this would decrease the friction of leaving ChatGPT for LibreChat and thus increase users.

Which components are impacted by your request?

No response

Pictures

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@darkBuddha darkBuddha added the enhancement New feature or request label Jan 28, 2024
@danny-avila danny-avila changed the title Enhancement: Import JSON export from ChatGPT Apr 5, 2024
@danny-avila
Copy link
Owner

The import portion of this is now merged!

@darkBuddha
Copy link
Author

Bless you 🙏🏻

@aswny
Copy link

aswny commented May 2, 2024

Thank you so much. 🙏🏻

Are you also working on adding an option to export all conversations from LibreChat?

Currently I use LibreChat on a work machine but I eventually want to export all conversations to personal device.

@darkBuddha
Copy link
Author

being able to open single conversations and share them by link would also be nice... no exports needed then.

@aswny
Copy link

aswny commented May 2, 2024

@darkBuddha single conversations can still be shared, right? In JSON/Text formats at least. I'm looking for a bulk export to transfer all chats from one machine to another.

@darkBuddha
Copy link
Author

this is too much work, it would be easier/better to be able to share a link to a conversation (like in ChatGPT)

@darkBuddha
Copy link
Author

HI @danny-avila, I just tested it, it works!! 15 MB ChatGPT export from a few months ago, first try. Amazing, thank you! Meilisearch also very fast, good choice!👏🏻

@darkBuddha
Copy link
Author

@danny-avila on first try, nothing happened, so i tried again with console open. then it worked and i saw the "conversation import successful". now i saw, that the messages were imported twice. do you have an idea, how i can get rid of this, e.g. in mongo express?

@danny-avila
Copy link
Owner

@danny-avila on first try, nothing happened, so i tried again with console open. then it worked and i saw the "conversation import successful". now i saw, that the messages were imported twice. do you have an idea, how i can get rid of this, e.g. in mongo express?

So it had started already the first time, that’s why it got imported twice. Maybe an info toast saying it was importing could’ve helped prevent this

It would be a bit difficult to “undo” but will keep that in mind as an improvement

@sam1am
Copy link

sam1am commented May 23, 2024

Is there any kinda hacky way to export conversations in the meantime? Key feature for me is open access to my own gathered data and conversations. Thanks.

@danny-avila
Copy link
Owner

Is there any kinda hacky way to export conversations in the meantime? Key feature for me is open access to my own gathered data and conversations. Thanks.

You can use mongodump for this now

@OverLordGoldDragon
Copy link

way to export conversations in the meantime

My approach, based on MongoDB Compass:

  1. LibreChat > conversations > Aggregations

  2. + CREATE NEW, check </> TEXT, copy/paste below snippet

expand
[
  {
    $lookup: {
      from: "messages",
      localField: "messages",
      foreignField: "_id",
      as: "messageDetails"
    }
  },
  {
    $project: {
      _id: 1,
      conversationId: 1,
      user: 1,
      createdAt: 1,
      updatedAt: 1,
      title: 1,
      messageDetails: 1
    }
  }
]

image

  1. Run + Export

This yields a .json. It has lots of irrelevant info. I converted it to .md in Python as follows (made by GPT-4o + Claude 3.5 Sonnet):

expand
# -*- coding: utf-8 -*-
import json
from datetime import datetime

# Load JSON data from a file
path = "LibreChat.conversations.json"
with open(path, 'r', encoding='utf-8') as file:
    data = json.load(file)

def convert_date(date_str):
    return datetime.strptime(
        date_str, "%Y-%m-%dT%H:%M:%S.%fZ").strftime("%Y-%m-%d %H:%M:%S")

def json_to_markdown(conversation):
    markdown = f"# Conversation: {conversation['title']}\n\n"
    markdown += f"Conversation ID: {conversation['conversationId']}\n"
    markdown += f"User ID: {conversation['user']}\n"
    markdown += f"Created At: {convert_date(conversation['createdAt']['$date'])}\n"
    markdown += f"Updated At: {convert_date(conversation['updatedAt']['$date'])}\n"
    markdown += "\n## Messages\n"
    for msg in conversation['messageDetails']:
        markdown += f"### Message from {msg['sender']} at {convert_date(msg['createdAt']['$date'])}\n"
        markdown += f"{msg['text']}\n\n"
    return markdown

# Process all conversations
all_markdown = ""
for conversation in data:
    all_markdown += json_to_markdown(conversation) + "\n\n---\n\n"

# Print the first few lines of the output
print(all_markdown[:500])

# Write all conversations to a single markdown file
with open("all_conversations.md", "w", encoding='utf-8') as file:
    file.write(all_markdown)

print("Conversion complete. Check 'all_conversations.md' for the result.")

This can be viewed in whichever markdown viewer, including Github comments. I've not tested whether the .json can be imported back into LibreChat.

@cendenta
Copy link

cendenta commented Jul 3, 2024

I've found ChatGPT Exporter the best exporter of any of the various systems I've tried, with some nice customizability. Since LibreChat is very similar to ChatGPT, I had (mild) hopes that the TamperMonkey script would work just by adding the LibreChat URLs into the config (no dice, unfortunately). Thought it was worth mentioning for considering potential compatibility, or at least inspiration for LibreChat export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
6 participants