Merge branch 'Yidadaa:main' into main

This commit is contained in:
Rentoo 2023-03-28 20:57:31 +08:00 committed by GitHub
commit 303fdddf55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 115 additions and 44 deletions

View File

@ -7,7 +7,7 @@
One-Click to deploy your own ChatGPT web UI. One-Click to deploy your own ChatGPT web UI.
[演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [加入 Discord](https://discord.gg/zrhvHCr79N) / [微信群](https://user-images.githubusercontent.com/16968934/227772522-b3ba3713-9206-4c8d-a81f-22300b7c313a.jpg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) [演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [加入 Discord](https://discord.gg/zrhvHCr79N) / [QQ 群](https://user-images.githubusercontent.com/16968934/228190818-7dd00845-e9b9-4363-97e5-44c507ac76da.jpeg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg)
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web) [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web)
@ -116,18 +116,10 @@ OPENAI_API_KEY=<your api key here>
2. 执行 `yarn install && yarn dev` 即可。 2. 执行 `yarn install && yarn dev` 即可。
### 本地部署 Local Deployment ### 本地部署 Local Deployment
```shell
请直接询问 ChatGPT使用下列 Prompt bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
```
如何使用 pm2 和 yarn 部署 nextjs 项目到 ubuntu 服务器上,项目编译命令为 yarn build启动命令为 yarn start启动时需要设置环境变量为 OPENAI_API_KEY端口为 3000使用 ngnix 做反向代理
``` ```
Please ask ChatGPT with prompt:
```
how to deploy nextjs project with pm2 and yarn on my ubuntu server, the build command is `yarn build`, the start command is `yarn start`, the project must start with env var named `OPENAI_API_KEY`, the port is 3000, use ngnix
```
### 容器部署 Docker Deployment ### 容器部署 Docker Deployment
@ -159,12 +151,14 @@ If you would like to contribute your API key, you can email it to the author and
[@mushan0x0](https://github.com/mushan0x0) [@mushan0x0](https://github.com/mushan0x0)
[@ClarenceDan](https://github.com/ClarenceDan) [@ClarenceDan](https://github.com/ClarenceDan)
[@zhangjia](https://github.com/zhangjia)
### 贡献者 Contributor ### 贡献者 Contributor
[@AprilNEA](https://github.com/AprilNEA) [@AprilNEA](https://github.com/AprilNEA)
[@iSource](https://github.com/iSource) [@iSource](https://github.com/iSource)
[@iFwu](https://github.com/iFwu) [@iFwu](https://github.com/iFwu)
[@xiaotianxt](https://github.com/xiaotianxt)
## LICENSE ## LICENSE

View File

@ -14,3 +14,4 @@ export function getAccessCodes(): Set<string> {
} }
export const ACCESS_CODES = getAccessCodes(); export const ACCESS_CODES = getAccessCodes();
export const IS_IN_DOCKER = process.env.DOCKER;

View File

@ -131,10 +131,12 @@ function useSubmitHandler() {
(config.submitKey === SubmitKey.AltEnter && e.altKey) || (config.submitKey === SubmitKey.AltEnter && e.altKey) ||
(config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) || (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) ||
(config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) || (config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) ||
(config.submitKey === SubmitKey.MetaEnter && e.metaKey) ||
(config.submitKey === SubmitKey.Enter && (config.submitKey === SubmitKey.Enter &&
!e.altKey && !e.altKey &&
!e.ctrlKey && !e.ctrlKey &&
!e.shiftKey) !e.shiftKey &&
!e.metaKey)
); );
}; };
@ -163,6 +165,7 @@ export function Chat(props: { showSideBar?: () => void }) {
setIsLoading(true); setIsLoading(true);
onUserInput(userInput).then(() => setIsLoading(false)); onUserInput(userInput).then(() => setIsLoading(false));
setUserInput(""); setUserInput("");
inputRef.current?.focus();
}; };
// stop response // stop response
@ -203,6 +206,7 @@ export function Chat(props: { showSideBar?: () => void }) {
// for auto-scroll // for auto-scroll
const latestMessageRef = useRef<HTMLDivElement>(null); const latestMessageRef = useRef<HTMLDivElement>(null);
const inputRef = useRef<HTMLTextAreaElement>(null);
// wont scroll while hovering messages // wont scroll while hovering messages
const [autoScroll, setAutoScroll] = useState(false); const [autoScroll, setAutoScroll] = useState(false);
@ -371,6 +375,7 @@ export function Chat(props: { showSideBar?: () => void }) {
<div className={styles["chat-input-panel"]}> <div className={styles["chat-input-panel"]}>
<div className={styles["chat-input-panel-inner"]}> <div className={styles["chat-input-panel-inner"]}>
<textarea <textarea
ref={inputRef}
className={styles["chat-input"]} className={styles["chat-input"]}
placeholder={Locale.Chat.Input(submitKey)} placeholder={Locale.Chat.Input(submitKey)}
rows={3} rows={3}
@ -561,7 +566,10 @@ export function Home() {
<IconButton <IconButton
icon={<AddIcon />} icon={<AddIcon />}
text={Locale.Home.NewChat} text={Locale.Home.NewChat}
onClick={createNewSession} onClick={()=>{
createNewSession();
setShowSideBar(false);
}}
/> />
</div> </div>
</div> </div>

View File

@ -3,7 +3,7 @@ import "./styles/globals.scss";
import "./styles/markdown.scss"; import "./styles/markdown.scss";
import "./styles/prism.scss"; import "./styles/prism.scss";
import process from "child_process"; import process from "child_process";
import { ACCESS_CODES } from "./api/access"; import { ACCESS_CODES, IS_IN_DOCKER } from "./api/access";
let COMMIT_ID: string | undefined; let COMMIT_ID: string | undefined;
try { try {
@ -28,7 +28,7 @@ export const metadata = {
function Meta() { function Meta() {
const metas = { const metas = {
version: COMMIT_ID ?? "unknown", version: COMMIT_ID ?? "unknown",
access: ACCESS_CODES.size > 0 ? "enabled" : "disabled", access: (ACCESS_CODES.size > 0 || IS_IN_DOCKER) ? "enabled" : "disabled",
}; };
return ( return (

View File

@ -21,6 +21,7 @@ export enum SubmitKey {
CtrlEnter = "Ctrl + Enter", CtrlEnter = "Ctrl + Enter",
ShiftEnter = "Shift + Enter", ShiftEnter = "Shift + Enter",
AltEnter = "Alt + Enter", AltEnter = "Alt + Enter",
MetaEnter = "Meta + Enter",
} }
export enum Theme { export enum Theme {

View File

@ -839,21 +839,20 @@
.markdown-body .highlight pre, .markdown-body .highlight pre,
.markdown-body pre { .markdown-body pre {
padding: 16px; padding: 16px 16px 8px 16px;
overflow: auto; overflow: auto;
font-size: 85%; font-size: 85%;
line-height: 1.45; line-height: 1.45;
background-color: var(--color-canvas-subtle);
border-radius: 6px; border-radius: 6px;
} }
.markdown-body pre code, .markdown-body pre code,
.markdown-body pre tt { .markdown-body pre tt {
display: inline; display: inline-block;
max-width: auto; max-width: 100%;
padding: 0; padding: 0;
margin: 0; margin: 0;
overflow: visible; overflow-x: scroll;
line-height: inherit; line-height: inherit;
word-wrap: normal; word-wrap: normal;
background-color: transparent; background-color: transparent;

View File

@ -121,32 +121,32 @@
} }
} }
// @mixin light { @mixin light {
// .markdown-body pre[class*="language-"] { .markdown-body pre {
// filter: invert(1) hue-rotate(50deg) brightness(1.3); filter: invert(1) hue-rotate(90deg) brightness(1.3);
// } }
// } }
// @mixin dark { @mixin dark {
// .markdown-body pre[class*="language-"] { .markdown-body pre {
// filter: none; filter: none;
// } }
// } }
// :root { :root {
// @include light(); @include light();
// } }
// .light { .light {
// @include light(); @include light();
// } }
// .dark { .dark {
// @include dark(); @include dark();
// } }
// @media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
// :root { :root {
// @include dark(); @include dark();
// } }
// } }

4
public/robots.txt Normal file
View File

@ -0,0 +1,4 @@
User-agent: *
Disallow: /
User-agent: vitals.vercel-insights.com
Allow: /

64
scripts/setup.sh Normal file
View File

@ -0,0 +1,64 @@
#!/bin/bash
# Check if running on a supported system
case "$(uname -s)" in
Linux)
if [[ -f "/etc/lsb-release" ]]; then
. /etc/lsb-release
if [[ "$DISTRIB_ID" != "Ubuntu" ]]; then
echo "This script only works on Ubuntu, not $DISTRIB_ID."
exit 1
fi
else
if [[ ! "$(cat /etc/*-release | grep '^ID=')" =~ ^(ID=\"ubuntu\")|(ID=\"centos\")|(ID=\"arch\")$ ]]; then
echo "Unsupported Linux distribution."
exit 1
fi
fi
;;
Darwin)
echo "Running on MacOS."
;;
*)
echo "Unsupported operating system."
exit 1
;;
esac
# Check if needed dependencies are installed and install if necessary
if ! command -v node >/dev/null || ! command -v git >/dev/null || ! command -v yarn >/dev/null; then
case "$(uname -s)" in
Linux)
if [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"ubuntu\"" ]]; then
sudo apt-get update
sudo apt-get -y install nodejs git yarn
elif [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"centos\"" ]]; then
sudo yum -y install epel-release
sudo yum -y install nodejs git yarn
elif [[ "$(cat /etc/*-release | grep '^ID=')" = "ID=\"arch\"" ]]; then
sudo pacman -Syu -y
sudo pacman -S -y nodejs git yarn
else
echo "Unsupported Linux distribution"
exit 1
fi
;;
Darwin)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install node git yarn
;;
esac
fi
# Clone the repository and install dependencies
git clone https://github.com/Yidadaa/ChatGPT-Next-Web
cd ChatGPT-Next-Web
yarn install
# Prompt user for environment variables
read -p "Enter OPENAI_API_KEY: " OPENAI_API_KEY
read -p "Enter CODE: " CODE
read -p "Enter PORT: " PORT
# Build and run the project using the environment variables
OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn build && OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn start