Niek / chatgpt-web

ChatGPT web interface using the OpenAI API
https://niek.github.io/chatgpt-web/
GNU General Public License v3.0
1.78k stars 463 forks source link

Sync chats across machines #364

Open sandeeps- opened 7 months ago

sandeeps- commented 7 months ago

Is it possible to add an option to auto sync the chats across different machines? For example in chrome use the sync features.

Or add an option to change the location where the chats are stored; so the user can use a 3rd party sync service like dropbox, google drive, box etc to sync chats between multiple machines

DustinWehr commented 5 months ago

@Niek are you open to this if I work on it? I wouldn't get into complicated sync protocols. Probably some simple restriction such as: chats created from one session are read-only from other sessions.

I'm already doing a very hacky non-automated version of this in a fork of your repo, where i've added "Backup all JSON" and "import many JSON" choices next to the single-chat ones.

Niek commented 5 months ago

Interesting idea, what would be an option is https://remote.storage/ (https://github.com/FrigadeHQ/remote-storage). However, when we implement this people should be aware that their data is stored on a 3rd party host.

DustinWehr commented 5 months ago

It could be opt-in, right? Put the remoteStorage config on the same page as the OpenAI key. Also, from a brief look at Storage.svelte, it seems plausible that end-to-end encryption of individual serialized Messages might not be too much work. What do you think?

I think 5apps is another company that offers free hosting for remoteStorage.

DustinWehr commented 5 months ago

Oh, or using json chat import/export. Maybe that's what you had it mind, since it would require very few changes to your code. I just made it so it won't import a json chat if there's already a Chat with the same hash of .messages. Would be very easy to include an end-to-end encryption option that way, also.

DustinWehr commented 4 months ago

Oh, or using json chat import/export. Maybe that's what you had it mind, since it would require very few changes to your code. I just made it so it won't import a json chat if there's already a Chat with the same hash of .messages. Would be very easy to include an end-to-end encryption option that way, also.

@Niek was easy to get a proof-of-concept working this way. Only problem for me is that the default community server from Frigate (I haven't gotten 5apps working) appears to enforce a size limit of 1 MB (uncompressed), smaller than google chrome's enforced localStorage limit. Incidentally, I recall seeing a note from you somewhere about thinking of switching to IndexDB to avoid localStorage's size limits.

DustinWehr commented 4 months ago

Oh, silly me. That limit appears to be per-key. Well, we should compress the chats as gracious users of the free server anyway. I'll do that, and also encryption. LMK if you want me to share it.

Niek commented 4 months ago

Sounds great! If you can do a PR that would be amazing!

DustinWehr commented 4 months ago

FYI the remoteStorage of https://github.com/FrigadeHQ/remote-storage / https://remote.storage / npm remote-storage is not the standards-track, much older remoteStorage, which is https://github.com/remotestorage / https://remotestorage.io / npm remotestoragejs.

DustinWehr commented 4 months ago

Quick update; remoteStorage caching, which it uses for background syncing, uses too much localStorage, so I'm reworking this sync feature to make it efficient without remoteStorage caching. They supposedly support caching with IndexedDB too, but provide no way to choose it manually; it's only used if the environment has no localStorage. I don't want to force IndexedDB by changing the remoteStorage.js source only to find out that it's buggier.

DustinWehr commented 3 months ago

@sandeeps- @Niek I have a fork with sync running here https://chatgptweb-dust.vercel.app/. Hope to put it on github soon. There are a few very minor extra things added in this fork, just because I use them regularly, but with the exception of a couple new menu items (Backup all chats JSON and Restore many chats JSON) they are disabled by default with options added on the settings page.

Notes:

Setup:

  1. Click the Enable syncing between your devices checkbox in the settings, which will reveal a RemoteStorage login widget. In the "IMPORTANT NOTES", there's a link to 5apps.com where you can make a free RemoteStorage account. There are probably other companies hosting servers too, and I'm told it's easy to run one's own.
  2. Click the First Device Setup button. A 12 character code will be generated, and from it an AES key derived and saved unencrypted to your browser's localStorage. Click Accept. You can see the code later by hovering over an element just above the setup buttons.
  3. There will be a new sync button next to the sort button in the sidebar. Click it. Alternatively, check the option Do a sync after every change you make from this device, and then make a local change. In either case, your chats will be encrypted with the AES key and then slowly (to avoid rate limiting) uploaded to the RS server. I have it going slower than necessary atm.
  4. On other devices, you login to the same RemoteStorage account, then click Additional device setup, then input the 12 character code from your first device and click save. After a few seconds a popup should tell you that you entered the right code. Click ok to start a sync.
DustinWehr commented 2 months ago

Here's the fork https://github.com/DustinWehr/chatgpt-web-syncing @Niek lmk if you're still interested in a PR.