You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
Yi 47dc009505
feat: 添加用于显示回复消息原文的选项 (#672)
* feat: 添加显示用于原文的选项

* chore: 修复暗色主题下文本颜色问题

给输入和输出气泡添加了 css 类,用来处理在暗色主题下聊天气泡的文本颜色

* feat: 用户输入不应该被渲染,防止 xss

---------

Co-authored-by: ChenZhaoYu <790348264@qq.com>
2 years ago
.github/workflows feat: 调整镜像构建的tag,让最新代码指向latest,让每次版本指向日期 (#144) 2 years ago
.husky fix: 修复代码提交前验证流程 2 years ago
.vscode feat: 渲染的链接新窗口打开 2 years ago
config feat: v2.7.2 消息样式美化和优化代码 (#111) 2 years ago
docker-compose chore: update deps and lint fix 2 years ago
docs chore: cover 2 years ago
public feat: support pwa (#452) 2 years ago
service perf: config 接口添加权限验证 2 years ago
src feat: 添加用于显示回复消息原文的选项 (#672) 2 years ago
.commitlintrc.json chore: 添加 lint-staged 2 years ago
.dockerignore 优化docker打包镜像文件过大的问题 (#415) 2 years ago
.editorconfig chore: initialize 2 years ago
.env feat: 支持长回复 (#450) 2 years ago
.eslintrc.cjs chore: initialize 2 years ago
.gitattributes chore: initialize 2 years ago
.gitignore chore: reset .env 2 years ago
.npmrc chore: 添加 lint-staged 2 years ago
CHANGELOG.md chore: v2.10.7 2 years ago
CONTRIBUTING.en.md chore: added English translation for the docs 2 years ago
CONTRIBUTING.md chore: # CONTRIBUTING 2 years ago
Dockerfile chore: optimize dockerfile to speed up building and reduce docker image size (#520) 2 years ago
README.en.md fix: typo (#636) 2 years ago
README.md docs: 移除 docker-compose.yml 省略 2 years ago
index.html feat: 支持webAPP(苹果添加到主页书签访问) (#227) 2 years ago
license pref: 优化部份内容 2 years ago
package.json feat: 渲染的链接新窗口打开 2 years ago
pnpm-lock.yaml feat: 渲染的链接新窗口打开 2 years ago
postcss.config.js chore: initialize 2 years ago
start.sh Add Dockerfile (#33) 2 years ago
tailwind.config.js chore: version 2.7.3 (#120) 2 years ago
tsconfig.json feat: version 2.9.1 (#207) 2 years ago
vite.config.ts feat: support pwa (#452) 2 years ago

README.en.md

ChatGPT Web


Disclaimer: This project is only released on GitHub, under the MIT License, free and for open-source learning purposes. There will be no account selling, paid services, discussion groups, or forums. Beware of fraud.

cover cover2

Introduction

Supports dual models, provides two unofficial ChatGPT API methods:

Method Free? Reliability Quality
ChatGPTAPI(gpt-3.5-turbo-0301) No Reliable Relatively clumsy
ChatGPTUnofficialProxyAPI(Web accessToken) Yes Relatively unreliable Smart

Comparison:

  1. ChatGPTAPI uses gpt-3.5-turbo-0301 to simulate ChatGPT through the official OpenAI completion API (the most reliable method, but it is not free and does not use models specifically tuned for chat).
  2. ChatGPTUnofficialProxyAPI accesses ChatGPT's backend API via an unofficial proxy server to bypass Cloudflare (uses the real ChatGPT, is very lightweight, but depends on third-party servers and has rate limits).

Details

Switching Methods:

  1. Go to the service/.env.example file and copy the contents to the service/.env file.
  2. For OpenAI API Key, fill in the OPENAI_API_KEY field (Get apiKey).
  3. For Web API, fill in the OPENAI_ACCESS_TOKEN field (Get accessToken).
  4. When both are present, OpenAI API Key takes precedence.

Reverse Proxy:

Available when using ChatGPTUnofficialProxyAPI.Details

# service/.env
API_REVERSE_PROXY=

Environment Variables:

For all parameter variables, check here or see:

/service/.env

Roadmap

[✓] Dual models

[✓] Multiple session storage and context logic

[✓] Formatting and beautifying code-like message types

[✓] Access rights control

[✓] Data import and export

[✓] Save message to local image

[✓] Multilingual interface

[✓] Interface themes

[✗] More...

Prerequisites

Node

node requires version ^16 || ^18 (node >= 14 requires installation of fetch polyfill), and multiple local node versions can be managed using nvm.

node -v

PNPM

If you have not installed pnpm before:

npm install pnpm -g

Fill in the Keys

Get Openai Api Key or accessToken and fill in the local environment variables jump

# service/.env file

# OpenAI API Key - https://platform.openai.com/overview
OPENAI_API_KEY=

# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
OPENAI_ACCESS_TOKEN=

Install Dependencies

To make it easier for backend developers to understand, we did not use the front-end workspace mode, but stored it in different folders. If you only need to do secondary development of the front-end page, delete the service folder.

Backend

Enter the /service folder and run the following command

pnpm install

Frontend

Run the following command in the root directory

pnpm bootstrap

Run in Test Environment

Backend Service

Enter the /service folder and run the following command

pnpm start

Frontend Webpage

Run the following command in the root directory

pnpm dev

Packaging

Using Docker

Docker Parameter Example

  • OPENAI_API_KEY one of two
  • OPENAI_ACCESS_TOKEN one of two, OPENAI_API_KEY takes precedence when both are present
  • OPENAI_API_BASE_URL optional, available when OPENAI_API_KEY is set
  • OPENAI_API_MODEL optional, available when OPENAI_API_KEY is set
  • API_REVERSE_PROXY optional, available when OPENAI_ACCESS_TOKEN is set Reference
  • AUTH_SECRET_KEY Access Passwordoptional
  • TIMEOUT_MS timeout, in milliseconds, optional
  • SOCKS_PROXY_HOST optional, effective with SOCKS_PROXY_PORT
  • SOCKS_PROXY_PORT optional, effective with SOCKS_PROXY_HOST
  • HTTPS_PROXY optional, support httphttps, socks5
  • ALL_PROXY optional, support httphttps, socks5

docker

Docker Build & Run

docker build -t chatgpt-web .

# foreground operation
docker run --name chatgpt-web --rm -it -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web

# background operation
docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web

# running address
http://localhost:3002/

Docker Compose

Hub Address

version: '3'

services:
  app:
    image: chenzhaoyu94/chatgpt-web # always use latest, pull the tag image again when updating
    ports:
      - 3002:3002
    environment:
      # one of two
      OPENAI_API_KEY: xxxxxx
      # one of two
      OPENAI_ACCESS_TOKEN: xxxxxx
      # api interface url, optional, available when OPENAI_API_KEY is set
      OPENAI_API_BASE_URL: xxxx
      # api model, optional, available when OPENAI_API_KEY is set
      OPENAI_API_MODEL: xxxx
      # reverse proxy, optional
      API_REVERSE_PROXY: xxx
      # access passwordoptional
      AUTH_SECRET_KEY: xxx
      # timeout, in milliseconds, optional
      TIMEOUT_MS: 60000
      # socks proxy, optional, effective with SOCKS_PROXY_PORT
      SOCKS_PROXY_HOST: xxxx
      # socks proxy port, optional, effective with SOCKS_PROXY_HOST
      SOCKS_PROXY_PORT: xxxx
      # HTTPS Proxyoptional, support http, https, socks5
      HTTPS_PROXY: http://xxx:7890

The OPENAI_API_BASE_URL is optional and only used when setting the OPENAI_API_KEY. The OPENAI_API_MODEL is optional and only used when setting the OPENAI_API_KEY.

Deployment with Railway

Deploy on Railway

Railway Environment Variables

Environment Variable Required Description
PORT Required Default: 3002
AUTH_SECRET_KEY Optional access password
TIMEOUT_MS Optional Timeout in milliseconds
OPENAI_API_KEY Optional Required for OpenAI API. apiKey can be obtained from here.
OPENAI_ACCESS_TOKEN Optional Required for Web API. accessToken can be obtained from here.
OPENAI_API_BASE_URL Optional, only for OpenAI API API endpoint.
OPENAI_API_MODEL Optional, only for OpenAI API API model.
API_REVERSE_PROXY Optional, only for Web API Reverse proxy address for Web API. Details
SOCKS_PROXY_HOST Optional, effective with SOCKS_PROXY_PORT Socks proxy.
SOCKS_PROXY_PORT Optional, effective with SOCKS_PROXY_HOST Socks proxy port.
HTTPS_PROXY Optional HTTPS Proxy.
ALL_PROXY Optional ALL Proxy.

Note: Changing environment variables in Railway will cause re-deployment.

Manual packaging

Backend service

If you don't need the node interface of this project, you can skip the following steps.

Copy the service folder to a server that has a node service environment.

# Install
pnpm install

# Build
pnpm build

# Run
pnpm prod

PS: You can also run pnpm start directly on the server without packaging.

Frontend webpage

  1. Refer to the root directory .env.example file content to create .env file, modify VITE_GLOB_API_URL in .env at the root directory to your actual backend interface address.
  2. Run the following command in the root directory and then copy the files in the dist folder to the root directory of your website service.

Reference information

pnpm build

Frequently Asked Questions

Q: Why does Git always report an error when committing?

A: Because there is submission information verification, please follow the Commit Guidelines.

Q: Where to change the request interface if only the frontend page is used?

A: The VITE_GLOB_API_URL field in the .env file at the root directory.

Q: All red when saving the file?

A: For vscode, please install the recommended plug-in of the project or manually install the Eslint plug-in.

Q: Why doesn't the frontend have a typewriter effect?

A: One possible reason is that after Nginx reverse proxying, buffering is turned on, and Nginx will try to buffer a certain amount of data from the backend before sending it to the browser. Please try adding proxy_buffering off; after the reverse proxy parameter and then reloading Nginx. Other web server configurations are similar.

Contributing

Please read the Contributing Guidelines before contributing.

Thanks to all the contributors!

Sponsorship

If you find this project helpful and circumstances permit, you can give me a little support. Thank you very much for your support~

WeChat

WeChat Pay

Alipay

Alipay

License

MIT © ChenZhaoYu