Skip to content

Commit

Permalink
Merge branch 'Yidadaa:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy-qinyuhai authored Jun 27, 2023
2 parents ac5c37d + 058e289 commit 76c32f4
Show file tree
Hide file tree
Showing 36 changed files with 1,108 additions and 481 deletions.
5 changes: 5 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ HIDE_USER_API_KEY=
# Default: Empty
# If you do not want users to use GPT-4, set this value to 1.
DISABLE_GPT4=

# (optional)
# Default: Empty
# If you do not want users to query balance, set this value to 1.
HIDE_BALANCE_QUERY=
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ One-Click to get well-designed cross-platform ChatGPT web UI.
[网页版](https://chatgpt.nextweb.fun/) / [客户端](https://github.com/Yidadaa/ChatGPT-Next-Web/releases) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://github.com/Yidadaa/ChatGPT-Next-Web/discussions/1724) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg)

[web-url]: https://chatgpt.nextweb.fun

[download-url]: https://github.com/Yidadaa/ChatGPT-Next-Web/releases

[Web-image]: https://img.shields.io/badge/Web-PWA-orange?logo=microsoftedge

[Windows-image]: https://img.shields.io/badge/-Windows-blue?logo=windows

[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple

[Linux-image]: https://img.shields.io/badge/-Linux-333?logo=ubuntu

[![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&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web)
Expand Down Expand Up @@ -190,6 +185,16 @@ If you do not want users to input their own API key, set this value to 1.
If you do not want users to use GPT-4, set this value to 1.

### `HIDE_BALANCE_QUERY` (optional)

> Default: Empty
If you do not want users to query balance, set this value to 1.

## Requirements

NodeJS >= 18, Docker >= 20

## Development

> [简体中文 > 如何进行二次开发](./README_CN.md#开发)
Expand Down Expand Up @@ -240,6 +245,12 @@ docker run -d -p 3000:3000 \
yidadaa/chatgpt-next-web
```

If your proxy needs password, use:

```shell
-e PROXY_URL="http://127.0.0.1:7890 user pass"
```

### Shell

```shell
Expand Down
10 changes: 10 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填

如果你不想让用户使用 GPT-4,将此环境变量设置为 1 即可。

### `HIDE_BALANCE_QUERY` (可选)

如果你不想让用户查询余额,将此环境变量设置为 1 即可。

## 开发

点击下方按钮,开始二次开发:
Expand Down Expand Up @@ -147,6 +151,12 @@ docker run -d -p 3000:3000 \
yidadaa/chatgpt-next-web
```

如果你的本地代理需要账号密码,可以使用:

```shell
-e PROXY_URL="http://127.0.0.1:7890 user password"
```

如果你需要指定其他环境变量,请自行在上述命令中增加 `-e 环境变量=环境变量值` 来指定。

### 本地部署
Expand Down
4 changes: 4 additions & 0 deletions README_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ Si no desea que los usuarios rellenen la clave de API ellos mismos, establezca e

Si no desea que los usuarios utilicen GPT-4, establezca esta variable de entorno en 1.

### `HIDE_BALANCE_QUERY` (Opcional)

Si no desea que los usuarios consulte el saldo, establezca esta variable de entorno en 1.

## explotación

> No se recomienda encarecidamente desarrollar o implementar localmente, debido a algunas razones técnicas, es difícil configurar el agente API de OpenAI localmente, a menos que pueda asegurarse de que puede conectarse directamente al servidor OpenAI.
Expand Down
1 change: 1 addition & 0 deletions app/api/config/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const DANGER_CONFIG = {
needCode: serverConfig.needCode,
hideUserApiKey: serverConfig.hideUserApiKey,
enableGPT4: serverConfig.enableGPT4,
hideBalanceQuery: serverConfig.hideBalanceQuery,
};

declare global {
Expand Down
43 changes: 43 additions & 0 deletions app/command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useSearchParams } from "react-router-dom";
import Locale from "./locales";

type Command = (param: string) => void;
interface Commands {
Expand Down Expand Up @@ -26,3 +27,45 @@ export function useCommand(commands: Commands = {}) {
setSearchParams(searchParams);
}
}

interface ChatCommands {
new?: Command;
newm?: Command;
next?: Command;
prev?: Command;
clear?: Command;
del?: Command;
}

export const ChatCommandPrefix = ":";

export function useChatCommand(commands: ChatCommands = {}) {
function extract(userInput: string) {
return (
userInput.startsWith(ChatCommandPrefix) ? userInput.slice(1) : userInput
) as keyof ChatCommands;
}

function search(userInput: string) {
const input = extract(userInput);
const desc = Locale.Chat.Commands;
return Object.keys(commands)
.filter((c) => c.startsWith(input))
.map((c) => ({
title: desc[c as keyof ChatCommands],
content: ChatCommandPrefix + c,
}));
}

function match(userInput: string) {
const command = extract(userInput);
const matched = typeof commands[command] === "function";

return {
matched,
invoke: () => matched && commands[command]!(userInput),
};
}

return { match, search };
}
237 changes: 236 additions & 1 deletion app/components/chat.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
animation: slide-in ease 0.3s;
box-shadow: var(--card-shadow);
transition: all ease 0.3s;
margin-bottom: 10px;
align-items: center;
height: 16px;
width: var(--icon-width);
Expand Down Expand Up @@ -202,3 +201,239 @@
}
}
}

.chat {
display: flex;
flex-direction: column;
position: relative;
height: 100%;
}

.chat-body {
flex: 1;
overflow: auto;
padding: 20px;
padding-bottom: 40px;
position: relative;
overscroll-behavior: none;
}

.chat-body-main-title {
cursor: pointer;

&:hover {
text-decoration: underline;
}
}

@media only screen and (max-width: 600px) {
.chat-body-title {
text-align: center;
}
}

.chat-message {
display: flex;
flex-direction: row;

&:last-child {
animation: slide-in ease 0.3s;
}
}

.chat-message-user {
display: flex;
flex-direction: row-reverse;
}

.chat-message-container {
max-width: var(--message-max-width);
display: flex;
flex-direction: column;
align-items: flex-start;
}

.chat-message-user > .chat-message-container {
align-items: flex-end;
}

.chat-message-avatar {
margin-top: 20px;
}

.chat-message-status {
font-size: 12px;
color: #aaa;
line-height: 1.5;
margin-top: 5px;
}

.chat-message-item {
box-sizing: border-box;
max-width: 100%;
margin-top: 10px;
border-radius: 10px;
background-color: rgba(0, 0, 0, 0.05);
padding: 10px;
font-size: 14px;
user-select: text;
word-break: break-word;
border: var(--border-in-light);
position: relative;
transition: all ease 0.3s;
min-width: 0;

&:hover {
min-width: 330px;

.chat-message-actions {
height: 40px;
opacity: 1;
transform: translateY(0px);

.chat-message-action-date {
opacity: 0.3;
}
}
}

.chat-message-actions {
display: flex;
width: 100%;
box-sizing: border-box;
font-size: 12px;
align-items: flex-end;
justify-content: space-between;
transition: all ease 0.3s;
transform: translateY(10px);
opacity: 0;
height: 0;
}

.chat-message-action-date {
color: var(--black);
opacity: 0;
}
}

.chat-message-user > .chat-message-container > .chat-message-item {
background-color: var(--second);

&:hover {
min-width: 0;
}
}

.chat-input-panel {
position: relative;
width: 100%;
padding: 20px;
padding-top: 10px;
box-sizing: border-box;
flex-direction: column;
border-top: var(--border-in-light);
box-shadow: var(--card-shadow);

.chat-input-actions {
.chat-input-action {
margin-bottom: 10px;
}
}
}

@mixin single-line {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.prompt-hints {
min-height: 20px;
width: 100%;
max-height: 50vh;
overflow: auto;
display: flex;
flex-direction: column-reverse;

background-color: var(--white);
border: var(--border-in-light);
border-radius: 10px;
margin-bottom: 10px;
box-shadow: var(--shadow);

.prompt-hint {
color: var(--black);
padding: 6px 10px;
animation: slide-in ease 0.3s;
cursor: pointer;
transition: all ease 0.3s;
border: transparent 1px solid;
margin: 4px;
border-radius: 8px;

&:not(:last-child) {
margin-top: 0;
}

.hint-title {
font-size: 12px;
font-weight: bolder;

@include single-line();
}
.hint-content {
font-size: 12px;

@include single-line();
}

&-selected,
&:hover {
border-color: var(--primary);
}
}
}

.chat-input-panel-inner {
display: flex;
flex: 1;
}

.chat-input {
height: 100%;
width: 100%;
border-radius: 10px;
border: var(--border-in-light);
box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.03);
background-color: var(--white);
color: var(--black);
font-family: inherit;
padding: 10px 90px 10px 14px;
resize: none;
outline: none;
box-sizing: border-box;
min-height: 68px;
}

.chat-input:focus {
border: 1px solid var(--primary);
}

.chat-input-send {
background-color: var(--primary);
color: white;

position: absolute;
right: 30px;
bottom: 32px;
}

@media only screen and (max-width: 600px) {
.chat-input {
font-size: 16px;
}

.chat-input-send {
bottom: 30px;
}
}
Loading

0 comments on commit 76c32f4

Please sign in to comment.