Skip to content

Clone of ChatGPT, uses official model & Bing, reverse-engineered UI, with AI model switching, message search, and prompt templates (WIP)

License

Notifications You must be signed in to change notification settings

freeintweb/chatgpt-clone

 
 

Repository files navigation

ChatGPT Clone

demo-vid.mp4

All AI Conversations under One Roof.

Assistant AIs are the future and OpenAI revolutionized this movement with ChatGPT. While numerous methods exist to integrate them, this app commemorates the original styling of ChatGPT, with the ability to integrate any current/future AI models, while improving upon original client features, such as conversation search and prompt templates (currently WIP).

This project was started early in Feb '23, anticipating the release of the official ChatGPT API from OpenAI, and now uses it. Through this clone, you can avoid ChatGPT Plus in favor of free or pay-per-call APIs. I will soon deploy a demo of this app. Feel free to contribute, clone, or fork. Currently dockerized.

Updates

2023-03-23

Released v0.1.0, searching messages/conversations is live! Up next is more custom parameters for customGpt's. Join the discord server for more immediate assistance and update: community discord server

Previous Updates
2023-03-22

Released v0.0.6, the latest stable release before Searching messages goes live tomorrow. See exact updates to date in the tag link. By request, there is now also a community discord server

2023-03-20

Searching messages is almost here as I test more of its functionality. There've been a lot of great features requested and great contributions and I will work on some soon, namely, further customizing the custom gpt params with sliders similar to the OpenAI playground, and including the custom params and system messages available to Bing.

The above features are next and then I will have to focus on building the test environment. I would greatly appreciate help in this area with any test environment you're familiar with (mocha, chai, jest, playwright, puppeteer). This is to aid in the velocity of contributing and to save time I spend debugging.

On that note, I had to switch the default branch due to some breaking changes that haven't been straight forward to debug, mainly related to node-chat-gpt the main dependency of the project. Thankfully, my working branch, now switched to default as main, is working as expected.

2023-03-16

Latest release (v0.0.4) includes Resubmitting messages & Branching messages, which mirrors official ChatGPT feature of editing a sent message, that then branches the conversation into separate message paths (works only with ChatGPT)

Full details and example here. Message search is on the docket

2023-03-12

Really thankful for all the issues reported and contributions made, the project's features and improvements have accelerated as result. Honorable mention is wtlyu for contributing a lot of mindful code, namely hostname configuration and mobile styling. I will upload images on next release for faster docker setup, and starting updating them simultaneously with this repo.

Many improvements across the board, the biggest is being able to start conversations simultaneously (again thanks to wtlyu for bringing it to my attention), as you can switch conversations or start a new chat without any response streaming from a prior one, as the backend will still process/save client responses. Just watch out for any rate limiting from OpenAI/Microsoft if this is done excessively.

Adding support for conversation search is next! Thank you mysticaltech for bringing up a method I can use for this.

2023-03-09 Released v.0.0.2

Adds Sydney (jailbroken Bing AI) to the model menu. Thank you DavesDevFails for bringing it to my attention in this issue. Bing/Sydney now correctly cite links, more styling to come. Fix some overlooked bugs, and model menu doesn't close upon deleting a customGpt.

I've re-enabled the ChatGPT browser client (free version) since it might be working for most people, it no longer works for me. Sydney is the best free route anyway.

2023-03-07 Due to increased interest in the repo, I've dockerized the app as of this update for quick setup! See setup instructions below. I realize this still takes some time with installing docker dependencies, so it's on the roadmap to have a deployed demo. Besides this, I've made major improvements for a lot of the existing features across the board, mainly UI/UX.

Also worth noting, the method to access the Free Version is no longer working, so I've removed it from model selection until further notice.

2023-03-04 Custom prompt prefixing and labeling is now supported through the official API. This nets some interesting results when you need ChatGPT for specific uses or entertainment. Select 'CustomGPT' in the model menu to configure this, and you can choose to save the configuration or reference it by conversation. Model selection will change by conversation.
2023-03-01 Official ChatGPT API is out! Removed davinci since the official API is extremely fast and 10x less expensive. Since user labeling and prompt prefixing is officially supported, I will add a View feature so you can set this within chat, which gives the UI an added use case. I've kept the BrowserClient, since it's free to use like the official site.

The Messages UI correctly mirrors code syntax highlighting. The exact replication of the cursor is not 1-to-1 yet, but pretty close. Later on in the project, I'll implement tests for code edge cases and explore the possibility of running code in-browser. Right now, unknown code defaults to javascript, but will detect language as close as possible.

2023-02-21 BingAI is integrated (although sadly limited by Microsoft with the 5 msg/convo limit, 50 msgs/day). I will need to handle the case when Bing refuses to give more answers on top of the other styling features I have in mind. Official ChatGPT use is back with the new BrowserClient. Brainstorming how to handle the UI when the Ai model changes, since conversations can't be persisted between them (or perhaps build a way to achieve this at some level).
2023-02-15 Just got access to Bing AI so I'll be focusing on integrating that through waylaidwanderer's 'experimental' BingAIClient.
2023-02-14

Official ChatGPT use is no longer possible though I recently used it with waylaidwanderer's reverse proxy method, and before that, through leaked models he also discovered.

Currently, this project is only functional with the text-davinci-003 model.

Table of Contents

Roadmap

Warning

This is a work in progress. I'm building this in public. FYI there is still a lot of tech debt to cleanup. You can follow the progress here or on my Linkedin.

Here are my recently completed and planned features:
  • Persistent conversation
  • Rename, delete conversations
  • UI Error handling
  • Bing AI integration
  • AI model change handling (start new convos within existing, remembers last selected)
  • Code block handling (highlighting, markdown, clipboard, language detection)
  • Markdown handling
  • Customize prompt prefix/label (custom ChatGPT using official API)
  • Server convo pagination (limit fetch and load more with 'show more' button)
  • Config file for easy startup (docker compose)
  • Mobile styling (thanks to wtlyu)
  • Resubmit/edit sent messages (thanks to wtlyu)
  • Message Search
  • Custom params for ChatGPT API (temp, top_p, presence_penalty)
  • Bing AI Styling (params, suggested responses, convo end, etc.) - In progress
  • Add warning before clearing convos
  • Build test suite for CI/CD
  • Prompt Templates/Search
  • Refactor/clean up code (tech debt)
  • Optional use of local storage for credentials
  • Deploy demo

Features

  • Response streaming identical to ChatGPT through server-sent events
  • UI from original ChatGPT, including Dark mode
  • AI model selection (official ChatGPT API, BingAI, ChatGPT Free)
  • Create and Save custom ChatGPTs*
  • 3/23/23 - Search all messages/conversations - see details here

^* ChatGPT can be 'customized' by setting a system message or prompt prefix and alternate 'role' to the API request^

More info here. Here's an example from this app.

Tech Stack

This project uses:
  • node-chatgpt-api
  • No React boilerplate/toolchain/clone tutorials, created from scratch with react@latest
  • Use of Tailwind CSS and shadcn/ui components
  • Docker, useSWR, Redux, Express, MongoDB, Keyv

Getting Started

Prerequisites

  • npm
  • Node.js >= 19.0.0
  • MongoDB installed or MongoDB Atlas (required if not using Docker)
    • MongoDB does not support older ARM CPUs like those found in Raspberry Pis. However, you can make it work by setting MongoDB's version to mongo:4.4.18 in docker-compose.yml, the most recent version compatible with
  • Docker (optional)
  • OpenAI API key
  • BingAI, ChatGPT access tokens (optional, free AIs)

Usage

  • Clone/download the repo down where desired
  git clone https://github.com/danny-avila/chatgpt-clone.git
  • If using MongoDB Atlas, remove &w=majority from default connection string.

Local

Docker

  • Provide all credentials, (API keys, access tokens, and Mongo Connection String) in docker-compose.yml under api service
  • Run docker-compose up to start the app
  • Note: MongoDB does not support older ARM CPUs like those found in Raspberry Pis. However, you can make it work by setting MongoDB's version to mongo:4.4.18 in docker-compose.yml, the most recent version compatible with

Access Tokens

ChatGPT Free Instructions

To get your Access token For ChatGPT 'Free Version', login to chat.openai.com, then visit https://chat.openai.com/api/auth/session.

Warning: There may be a high chance of your account being banned with this method. Continue doing so at your own risk.

BingAI Instructions The Bing Access Token is the "_U" cookie from bing.com. Use dev tools or an extension while logged into the site to view it.

Note: Specific error handling and styling for this model is still in progress.

Proxy

If your server cannot connect to the chatGPT API server by some reason, (eg in China). You can set a environment variable PROXY. This will be transmitted to node-chatgpt-api interface.

Warning: PROXY is not reverseProxyUrl in node-chatgpt-api

Set up proxy in local environment

Here is two ways to set proxy.

  • Option 1: system level environment export PROXY="http://127.0.0.1:7890"
  • Option 2: set in .env file PROXY="http://127.0.0.1:7890"

Change http://127.0.0.1:7890 to your proxy server

Set up proxy in docker environment

set in docker-compose.yml file, under services - api - environment

    api:
        ...
        environment:
                ...
                - "PROXY=http://127.0.0.1:7890"
                # add this line ↑

Change http://127.0.0.1:7890 to your proxy server

User System

By default, there is no user system enabled, so anyone can access your server.

This project is not designed to provide a complete and full-featured user system. It's not high priority task and might never be provided.

wtlyu provide a sample user system structure, that you can implement your own user system. It's simple and not a ready-for-use edition.

(If you want to implement your user system, open this ↓)

Implement your own user system

To enable the user system, set ENABLE_USER_SYSTEM=1 in your .env file.

The sample structure is simple. It provide three basic endpoint:

  1. /auth/login will redirect to your own login url. In the sample code, it's /auth/your_login_page.
  2. /auth/logout will redirect to your own logout url. In the sample code, it's /auth/your_login_page/logout.
  3. /api/me will return the userinfo: { username, display }.
    1. username will be used in db, used to distinguish between users.
    2. display will be displayed in UI.

The only one thing that drive user system work is req.session.user. Once it's set, the client will be trusted. Set to null if logout.

Please refer to /api/server/routes/authYourLogin.js file. It's very clear and simple to tell you how to implement your user system.

Or you can ask chatGPT to write the code for you, here is one example to connect LDAP:

Please write me an express module, that serve the login and logout endpoint as a router. The login and logout uri is '/' and '/logout'. Once loginned, save display name and username in session.user, as {display, username}. Then redirect to '/'. Please write the code using express and other lib, and storage any server configuration in a config variable. I want the user to be connected to my LDAP server.

Updating

  • As the project is still a work-in-progress, you should pull the latest and run the steps over. Reset your browser cache/clear site data.

Use Cases

Why use this project?
  • One stop shop for all conversational AIs, with the added bonus of searching past conversations.

  • Using the official API, you'd have to generate 7.5 million words to expense the same cost as ChatGPT Plus ($20).

  • ChatGPT/Google Bard/Bing AI conversations are lost in space or cannot be searched past a certain timeframe.

  • Customize ChatGPT

    use case example

  • API is not as limited as ChatGPT Free (at chat.openai.com)

    use case example

  • ChatGPT Free is down.

    use case example

Origin

This project was originally created as a Minimum Viable Product (or MVP) for the @HackReactor Bootcamp. It was built with OpenAI response streaming and most of the UI completed in under 20 hours. During the end of that time, I had most of the UI and basic functionality done. This was created without using any boilerplates or templates, including create-react-app and other toolchains. I didn't follow any 'un-official chatgpt' video tutorials, and simply referenced the official site for the UI. The purpose of the exercise was to learn setting up a full stack project from scratch. Please feel free to give feedback, suggestions, or fork the project for your own use.

Caveats

Regarding use of Official ChatGPT API

From @waylaidwanderer:

Since gpt-3.5-turbo is ChatGPT's underlying model, I had to do my best to replicate the way the official ChatGPT website uses it. This means my implementation or the underlying model may not behave exactly the same in some ways:

  • Conversations are not tied to any user IDs, so if that's important to you, you should implement your own user ID system.
  • ChatGPT's model parameters (temperature, frequency penalty, etc.) are unknown, so I set some defaults that I thought would be reasonable.
  • Conversations are limited to roughly the last 3000 tokens, so earlier messages may be forgotten during longer conversations.
    • This works in a similar way to ChatGPT, except I'm pretty sure they have some additional way of retrieving context from earlier messages when needed (which can probably be achieved with embeddings, but I consider that out-of-scope for now).

Contributing

Contributions and suggestions welcome! Bug reports and fixes are welcome!

For new features, components, or extensions, please open an issue and discuss before sending a PR.

License

This project is licensed under the MIT License.

About

Clone of ChatGPT, uses official model & Bing, reverse-engineered UI, with AI model switching, message search, and prompt templates (WIP)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 67.0%
  • CSS 26.5%
  • TypeScript 6.0%
  • Other 0.5%