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

Feat/v2 Feat: Add the function of sending messages by hitting enter. #369

Closed
wants to merge 160 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
3b16bfe
feat: v2 ui frame
ddiu8081 Mar 11, 2023
2fe1315
Merge branch 'main' into feat/v2
ddiu8081 Mar 14, 2023
7e6ecad
chore: add `alpinejs`, `nanostores`
ddiu8081 Mar 14, 2023
bc914b4
chore: add store for ui
ddiu8081 Mar 15, 2023
73fbc37
feat: v2 header, sidebar
ddiu8081 Mar 15, 2023
3b680d9
feat(ui): empty state for send component
ddiu8081 Mar 16, 2023
bd24e81
fix(ui): set site height to `100svh`
ddiu8081 Mar 16, 2023
1515c53
feat(ui): use unocss to detect dark mode
ddiu8081 Mar 16, 2023
c5ca7c8
fix(ui): border color in light mode
ddiu8081 Mar 16, 2023
22950f8
feat(ui): fix header, footer and modal
ddiu8081 Mar 16, 2023
30a5dc6
feat(ui): textarea editing state
ddiu8081 Mar 16, 2023
cc3da42
feat: send prompt from single chat
ddiu8081 Mar 16, 2023
d512df8
Merge branch 'main' into feat/v2
ddiu8081 Mar 18, 2023
4321972
chore: lint fix on v2
ddiu8081 Mar 18, 2023
449b127
chore: rename dir to stores
ddiu8081 Mar 18, 2023
bd2e771
feat: conversations sidebar
ddiu8081 Mar 18, 2023
0b696d5
refactor: chatList manage logics
ddiu8081 Mar 18, 2023
e65d1bf
feat: chat edit modal
ddiu8081 Mar 18, 2023
1779db5
fix: clear editingChatId when click add new chat
ddiu8081 Mar 18, 2023
abd4d4c
fix: judge `crypto` exists using `typeof`
ddiu8081 Mar 19, 2023
2f178be
chore: code style in `Layout.astro`
ddiu8081 Mar 20, 2023
4e1a504
feat(ui): set styles for scrollbar
ddiu8081 Mar 20, 2023
2635ec8
fix(ui): overflow scroll for sidebar
ddiu8081 Mar 20, 2023
8a21227
feat: remove support for `HTTPS_PROXY`
ddiu8081 Mar 20, 2023
fee6b8e
feat: usage api
ddiu8081 Mar 20, 2023
59edc89
Merge branch 'main' into feat/v2
ddiu8081 Mar 21, 2023
ff65b89
Merge branch 'main' into feat/v2
yzh990918 Mar 22, 2023
bbaa19f
refactor: move currentChat logic to `stores`
ddiu8081 Mar 22, 2023
9f9f1a0
feat: provider template
ddiu8081 Mar 22, 2023
6b071fa
Merge remote-tracking branch 'origin/feat/v2' into feat/v2
ddiu8081 Mar 22, 2023
3e2d24f
chore: move providers to /src
ddiu8081 Mar 22, 2023
fc29610
feat: add settings store
yzh990918 Mar 22, 2023
5569757
chore: lint code
yzh990918 Mar 22, 2023
b2af5b6
chore: update
yzh990918 Mar 22, 2023
8b82ef7
chore: type declaration of `Provider`
ddiu8081 Mar 22, 2023
7501249
fix: focus on textarea when clicking empty-state
ddiu8081 Mar 22, 2023
dcfdf50
refactor: rename `chat` to `conversation`
ddiu8081 Mar 22, 2023
4a3a7cb
refactor: store conversationTabs as object
ddiu8081 Mar 22, 2023
c001679
feat: bind conversationType config with providers
ddiu8081 Mar 23, 2023
4c11416
fix: show previous conversationType when editing
ddiu8081 Mar 23, 2023
92ce091
feat: disable selecting type in edit mode
ddiu8081 Mar 23, 2023
6b09858
feat: connect to provider
ddiu8081 Mar 23, 2023
1db3f7e
feat: send single message
ddiu8081 Mar 25, 2023
be0a4fd
chore: move provider registration to store
ddiu8081 Mar 25, 2023
79e1614
feat: continuous conversation
ddiu8081 Mar 25, 2023
a6fdf5b
feat: quick create conversation when push a prompt
ddiu8081 Mar 25, 2023
f56a3dc
fix(ui): handle overflow scrolling
ddiu8081 Mar 25, 2023
a9e47fa
fix(ui): clear output on sending, single chats
ddiu8081 Mar 25, 2023
0823051
feat(ui): max width for main area
ddiu8081 Mar 25, 2023
9fd1ac1
chore: move currentEditingId store to conversation
ddiu8081 Mar 26, 2023
fd35a7e
Merge branch 'main' into feat/v2
ddiu8081 Mar 26, 2023
157992f
chore: move interface to `./types`
ddiu8081 Mar 26, 2023
9d224b2
chore: add conversation mock data file
ddiu8081 Mar 26, 2023
8794d97
chore: remove vercelDisableBlocks
ddiu8081 Mar 26, 2023
2adc783
refactor: adjust directory structures
ddiu8081 Mar 26, 2023
4d68ec8
Merge branch 'main' into feat/v2
ddiu8081 Mar 26, 2023
b50eeb5
feat: settings sidebar basic ui
ddiu8081 Mar 26, 2023
04f5559
feat: markdown parse in v2
ddiu8081 Mar 27, 2023
fd652a3
chore: back to markdown-it temporarily
ddiu8081 Mar 27, 2023
5c41a29
fix: set overflow behavior to messageItem
ddiu8081 Mar 27, 2023
e13e617
feat(ui): adjust sidebar header ui
ddiu8081 Mar 28, 2023
1a39409
chore: remove alpine dependencies
ddiu8081 Mar 28, 2023
9e0f590
feat: provider icon definition
ddiu8081 Mar 28, 2023
e2f8a53
feat(ui): api-key settings ui
ddiu8081 Mar 28, 2023
438c380
fix: include provider icon in unocss scanning
ddiu8081 Mar 28, 2023
7fedc03
Merge branch 'main' into feat/v2
yzh990918 Mar 29, 2023
7e660f3
feat: add ThemeToogle component
yzh990918 Mar 29, 2023
934553f
chore: add `idb` dependency
ddiu8081 Mar 29, 2023
1b35ca9
feat: store conversation information in indexedDB
ddiu8081 Mar 30, 2023
cf2f49f
refactor: separate`messages` from `conversation`
ddiu8081 Mar 30, 2023
178b56b
chore: add `HandlerPayload` interface
ddiu8081 Mar 30, 2023
dc375c6
fix: refactor themeToogle
yzh990918 Apr 1, 2023
434c9d1
refactor: rename `platformSettings` to `globalSettings`
ddiu8081 Apr 1, 2023
1baa3af
feat: read provider global settings
ddiu8081 Apr 1, 2023
00ffaea
feat: store settings to indexedDB
ddiu8081 Apr 1, 2023
b92d405
refactor: fetch api logic
ddiu8081 Apr 1, 2023
3fe1735
chore: remove debug `console.log`
ddiu8081 Apr 1, 2023
791a4cf
chore: push single message to store
ddiu8081 Apr 1, 2023
04895ae
chore: test stream output
ddiu8081 Apr 1, 2023
33c2038
feat: stream output
ddiu8081 Apr 2, 2023
ab5a18d
feat: clear message db after delete conversation
ddiu8081 Apr 2, 2023
205c31b
feat(ui): use 100dvh
ddiu8081 Apr 2, 2023
a3fda82
fix(ui): set sideber height
ddiu8081 Apr 2, 2023
f0a272e
chore: move v2 pages to base dir
ddiu8081 Apr 3, 2023
06e9408
fix: skip storage building in server-rendering
ddiu8081 Apr 3, 2023
7dc19d0
feat: add currentChat info & clear to header
ddiu8081 Apr 3, 2023
488583f
fix: clear currentConversationId when deleting
ddiu8081 Apr 3, 2023
19f7b69
fix(ui): match theme toggle button to global style
ddiu8081 Apr 3, 2023
33260e9
feat: image generation
ddiu8081 Apr 4, 2023
0340ea0
feat: stable-diffusion image generation
ddiu8081 Apr 5, 2023
14939d4
chore: add kobalte dependency
ddiu8081 Apr 5, 2023
649cc6d
feat(ui): use `zag` to build ui components
ddiu8081 Apr 6, 2023
d04e63c
chore: hide `Select` component import
ddiu8081 Apr 6, 2023
33a6dc7
feat: add some zag components
yzh990918 Apr 7, 2023
fb85148
feat: add some model settings
yzh990918 Apr 7, 2023
017c360
chore: update
yzh990918 Apr 7, 2023
1dd46c9
feat(store): read default settings
ddiu8081 Apr 8, 2023
a0a2b46
feat: add more model settings, add settings's init value
yzh990918 Apr 9, 2023
db7967c
fix: onChange error in select component
ddiu8081 Apr 9, 2023
0ec6cc0
Merge branch 'feat/v2-model' into feat/v2
ddiu8081 Apr 9, 2023
04f5e8b
fix(stable-diffusion): adjust settings description
ddiu8081 Apr 9, 2023
cd2dcb5
feat(ui): Simplify ui of settings
ddiu8081 Apr 9, 2023
b4e79bb
feat(ui): select hover ui
ddiu8081 Apr 9, 2023
8e5b314
chore: set modalsLayer to clientOnly
ddiu8081 Apr 9, 2023
90edaf8
feat(ui): use zag to build drawers; add transition
ddiu8081 Apr 9, 2023
124b20d
fix(ui): disable close model on outside click
ddiu8081 Apr 9, 2023
458b07a
feat(ui): show non-full-screen modal on lg devices
ddiu8081 Apr 9, 2023
a91b9a8
feat: adjust ui of base components
ddiu8081 Apr 9, 2023
221b541
fix(ui): adjust accent color
ddiu8081 Apr 9, 2023
1545d1c
feat: add conversation icons
ddiu8081 Apr 9, 2023
8e51473
fix: set default conversationType to continuous
ddiu8081 Apr 9, 2023
5c958b1
fix(ui): adjust markdown styles
ddiu8081 Apr 9, 2023
b3b9f41
feat: use `remark` to parse markdown
ddiu8081 Apr 9, 2023
409d724
chore: set Conversation client only
ddiu8081 Apr 9, 2023
f8cf2c5
chore: remove mock data
ddiu8081 Apr 9, 2023
2531fc5
feat: send message by `command+enter`
ddiu8081 Apr 10, 2023
b2d23b7
fix: apply default values when rebuilding data
ddiu8081 Apr 10, 2023
242c8d2
fix: return when no input
ddiu8081 Apr 10, 2023
18d5291
feat(ui): scroll to top when dblClick header
ddiu8081 Apr 10, 2023
eaa6398
feat(ui): adapt for safe-area
ddiu8081 Apr 10, 2023
cde427b
fix: listen keyboard event after mount
ddiu8081 Apr 10, 2023
f656a65
feat(ui): adapt multi-line scrollbar in textarea
ddiu8081 Apr 11, 2023
c11d184
feat(ui): adjust background colors
ddiu8081 Apr 11, 2023
b972131
feat: show error message
ddiu8081 Apr 11, 2023
5a161e2
feat(ui): adjust border radius of modal
ddiu8081 Apr 12, 2023
fb50f55
chore: add todo on model
ddiu8081 Apr 12, 2023
57c5436
feat(ui): add icon in provider select component
ddiu8081 Apr 12, 2023
65ce312
feat: sort conversation tabs by message time
ddiu8081 Apr 12, 2023
b3eb3ce
feat: scroll to bottom ui
ddiu8081 Apr 12, 2023
f74d514
feat(ui): hide scroll banner when focus on input
ddiu8081 Apr 12, 2023
8a1991d
fix(ui): padding of sendBox edit state
ddiu8081 Apr 12, 2023
f5307cb
chore: code style fix
ddiu8081 Apr 12, 2023
32e8722
fix: set settings sidebar render client only
ddiu8081 Apr 12, 2023
fc49e52
feat: pin to bottom when streaming
ddiu8081 Apr 12, 2023
2d9ca0b
fix: move ui logic to client components, fix ssr
ddiu8081 Apr 12, 2023
ac35301
feat: add ctrl + enter keyCode send message
yzh990918 Apr 13, 2023
31b33f0
feat: add send button background color
yzh990918 Apr 13, 2023
39ead54
chore: update send icon opacity
yzh990918 Apr 13, 2023
8f0a639
chore: add modal close btn hover style, add closeBtnStyle
yzh990918 Apr 13, 2023
669faa1
feat(ui): adjust text & bg colors in dark mode
ddiu8081 Apr 13, 2023
3a4f2ce
fix(ui): adjust bg colors
ddiu8081 Apr 13, 2023
c49e0d2
fix(ui): adjust click-area of buttons in header
ddiu8081 Apr 13, 2023
c839591
feat: support math
ddiu8081 Apr 13, 2023
74f5285
fix(ui): adjust header components' gap
ddiu8081 Apr 13, 2023
1c4c781
fix(ui): hide scroll banner when clear message
ddiu8081 Apr 13, 2023
0e2d7dc
chore: move scrollBottom judge info throttle
ddiu8081 Apr 13, 2023
faa5693
feat(ui): add Tooltip componet, add send tips
yzh990918 Apr 14, 2023
7cb1387
feat(ui): add message sendTime
yzh990918 Apr 14, 2023
e4d93ca
chore: remove timeText
yzh990918 Apr 14, 2023
f251852
feat(ui): add messge item options menu
yzh990918 Apr 14, 2023
4e0a08c
fix(ui): layout error in send component, error state
ddiu8081 Apr 14, 2023
ae231a0
fix(ui): layout error in messageItem
ddiu8081 Apr 14, 2023
8c95926
fix: temporarily fix the unclickable send button
ddiu8081 Apr 14, 2023
ff45004
refactor: move ReadableStream to separate store
ddiu8081 Apr 14, 2023
50af82e
feat: loading state
ddiu8081 Apr 14, 2023
ced99fb
fix(ui): set `shrink-0` in header and send com
ddiu8081 Apr 16, 2023
e1a95bf
fix(ui): set width of message-item
ddiu8081 Apr 16, 2023
9fa7460
fix(ui): light mode of progress-bg
ddiu8081 Apr 16, 2023
b72fd91
refactor: remove reactivity store of providers
ddiu8081 Apr 16, 2023
b4cc56b
Update Send.tsx
GalaxySciTech Apr 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Your API Key for OpenAI
OPENAI_API_KEY=
# Provide proxy for OpenAI API. e.g. http://127.0.0.1:7890
HTTPS_PROXY=
# Custom base url for OpenAI API. default: https://api.openai.com
OPENAI_API_BASE_URL=
# Inject analytics or other scripts before </head> of the page
Expand Down
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module.exports = {
extends: ['@evan-yang', 'plugin:astro/recommended'],
rules: {
'no-console': ['error', { allow: ['error'] }],
'no-console': 'off',
'react/display-name': 'off',
'react-hooks/rules-of-hooks': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'react/jsx-key': 'off',
},
overrides: [
{
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
push:
branches:
- main
- feat/v2

pull_request:
branches:
- main
- feat/v2

jobs:
lint:
Expand Down
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
registry=https://registry.npmjs.org/
strict-peer-dependencies=false
auto-install-peers=true
shamefully-hoist=true
129 changes: 2 additions & 127 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,132 +1,7 @@
# ChatGPT-API Demo
# ChatGPT-API Demo v2

English | [简体中文](./README.zh-CN.md)
**🍿 Live preview**: https://v2.chatgpt.ddiu.me

A demo repo based on [OpenAI GPT-3.5 Turbo API.](https://platform.openai.com/docs/guides/chat)

**🍿 Live preview**: https://chatgpt.ddiu.me

> ⚠️ Notice: Our API Key limit has been exhausted. So the demo site is not available now.

![chat-logo](https://cdn.staticaly.com/gh/yzh990918/static@master/chat-logo.webp)



## Running Locally

### Pre environment
1. **Node**: Check that both your development environment and deployment environment are using `Node v18` or later. You can use [nvm](https://github.com/nvm-sh/nvm) to manage multiple `node` versions locally。
```bash
node -v
```
2. **PNPM**: We recommend using [pnpm](https://pnpm.io/) to manage dependencies. If you have never installed pnpm, you can install it with the following command:
```bash
npm i -g pnpm
```
3. **OPENAI_API_KEY**: Before running this application, you need to obtain the API key from OpenAI. You can register the API key at [https://beta.openai.com/signup](https://beta.openai.com/signup).

### Getting Started

1. Install dependencies
```bash
pnpm install
```
2. Copy the `.env.example` file, then rename it to `.env`, and add your [OpenAI API key](https://platform.openai.com/account/api-keys) to the `.env` file.
```bash
OPENAI_API_KEY=sk-xxx...
```
3. Run the application, the local project runs on `http://localhost:3000/`
```bash
pnpm run dev
```

## Deploy

### Deploy With Vercel

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fddiu8081%2Fchatgpt-demo&env=OPENAI_API_KEY&envDescription=OpenAI%20API%20Key&envLink=https%3A%2F%2Fplatform.openai.com%2Faccount%2Fapi-keys)



> #### 🔒 Need website password?
>
> Deploy with the [`SITE_PASSWORD`](#environment-variables)
>
> <a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fddiu8081%2Fchatgpt-demo&env=OPENAI_API_KEY&env=SITE_PASSWORD&envDescription=OpenAI%20API%20Key&envLink=https%3A%2F%2Fplatform.openai.com%2Faccount%2Fapi-keys" alt="Deploy with Vercel" target="_blank"><img src="https://vercel.com/button" alt="Deploy with Vercel" height=24 style="vertical-align: middle; margin-right: 4px;"></a>

![image](https://cdn.staticaly.com/gh/yzh990918/static@master/20230310/image.4wzfb79qt7k0.webp)


### Deploy With Netlify

[![Deploy with Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/ddiu8081/chatgpt-demo#OPENAI_API_KEY=&HTTPS_PROXY=&OPENAI_API_BASE_URL=&HEAD_SCRIPTS=&SECRET_KEY=&OPENAI_API_MODEL=&SITE_PASSWORD=)

**Step-by-step deployment tutorial:**

1. [Fork](https://github.com/ddiu8081/chatgpt-demo/fork) this project,Go to [https://app.netlify.com/start](https://app.netlify.com/start) new Site, select the project you `forked` done, and connect it with your `GitHub` account.

![image](https://cdn.staticaly.com/gh/yzh990918/static@master/20230310/image.3nlt4hgzb16o.webp)

![image](https://cdn.staticaly.com/gh/yzh990918/static@master/20230310/image.5fhfouap270g.webp)


2. Select the branch you want to deploy, then configure environment variables in the project settings.

![image](https://cdn.staticaly.com/gh/yzh990918/static@master/20230311/image.gfs9lx8c854.webp)

3. Select the default build command and output directory, Click the `Deploy Site` button to start deploying the site。

![image](https://cdn.staticaly.com/gh/yzh990918/static@master/20230311/image.4jky9e1wbojk.webp)


### Deploy with Docker
Before deploying the app, please make sure `.env` is configured normally.

```bash
# build
docker-compose build .
# run
docker-compose up -d
# stop
docker-compose down
```

### Deploy on more servers

Please refer to the official deployment documentation:https://docs.astro.build/en/guides/deploy

## Environment Variables

You can control the website through environment variables.

| Name | Description | Default |
| --- | --- | --- |
| `OPENAI_API_KEY` | Your API Key for OpenAI. | `null` |
| `HTTPS_PROXY` | Provide proxy for OpenAI API. e.g. `http://127.0.0.1:7890` | `null` |
| `OPENAI_API_BASE_URL` | Custom base url for OpenAI API. | `https://api.openai.com` |
| `HEAD_SCRIPTS` | Inject analytics or other scripts before `</head>` of the page | `null` |
| `SECRET_KEY` | Secret string for the project. Use for generating signatures for API calls | `null` |
| `SITE_PASSWORD` | Set password for site. If not set, site will be public | `null` |
| `OPENAI_API_MODEL` | ID of the model to use. [List models](https://platform.openai.com/docs/api-reference/models/list) | `gpt-3.5-turbo` |


## Frequently Asked Questions

Q: TypeError: fetch failed (can't connect to OpenAI Api)

A: Configure environment variables `HTTPS_PROXY`,reference: https://github.com/ddiu8081/chatgpt-demo/issues/34

Q: throw new TypeError(${context} is not a ReadableStream.)

A: The Node version needs to be `v18` or later,reference: https://github.com/ddiu8081/chatgpt-demo/issues/65

Q: Accelerate domestic access without the need for proxy deployment tutorial?

A: You can refer to this tutorial: https://github.com/ddiu8081/chatgpt-demo/discussions/270

Q: `PWA` is not working?

A: Current `PWA` does not support deployment on Netlify, you can choose vercel or node deployment.
## Contributing

This project exists thanks to all those who contributed.
Expand Down
137 changes: 0 additions & 137 deletions README.zh-CN.md

This file was deleted.

3 changes: 1 addition & 2 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineConfig } from 'astro/config'
import unocss from 'unocss/astro'
import solidJs from '@astrojs/solid-js'

import node from '@astrojs/node'
import { VitePWA } from 'vite-plugin-pwa'
import vercel from '@astrojs/vercel/edge'
Expand Down Expand Up @@ -64,7 +63,7 @@ export default defineConfig({
periodicSyncForUpdates: 20,
},
devOptions: {
enabled: true,
enabled: false,
},
}),
],
Expand Down
Loading