Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24c203f8d4 | ||
|
|
cbcbdda4c0 | ||
|
|
a2fcd31f24 | ||
|
|
07b92d4ede | ||
|
|
ed4ff67760 | ||
|
|
9c4644c969 | ||
|
|
dd91c2a4e0 | ||
|
|
7e8e15a628 | ||
|
|
076c56d1d9 | ||
|
|
133a24e25f | ||
|
|
73a67b8f64 | ||
|
|
222b3eaa4c | ||
|
|
c4baccdc48 | ||
|
|
7021a08ecf | ||
|
|
e88b9bef13 | ||
|
|
c17cc16c0e | ||
|
|
d7d037618f | ||
|
|
01edad7717 |
7
.env
Normal file
7
.env
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Glob API URL
|
||||||
|
VITE_GLOB_API_URL=/api
|
||||||
|
|
||||||
|
VITE_APP_API_BASE_URL=http://localhost:3002/
|
||||||
|
|
||||||
|
# Whether long replies are supported, which may result in higher API fees
|
||||||
|
VITE_GLOB_OPEN_LONG_REPLY=false
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# Glob API URL
|
|
||||||
VITE_GLOB_API_URL=/api
|
|
||||||
|
|
||||||
VITE_APP_API_BASE_URL=http://localhost:3002/
|
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,4 +30,3 @@ coverage
|
|||||||
|
|
||||||
# Environment variables files
|
# Environment variables files
|
||||||
/service/.env
|
/service/.env
|
||||||
/.env
|
|
||||||
|
|||||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,3 +1,38 @@
|
|||||||
|
## v2.10.3
|
||||||
|
|
||||||
|
`2023-03-10`
|
||||||
|
|
||||||
|
> 声明:除 `ChatGPTUnofficialProxyAPI` 使用的非官方代理外,本项目代码包括上游引用包均开源在 `GitHub`,如果你觉得本项目有监控后门或有问题导致你的账号、API被封,那我很抱歉。我可能`BUG`写的多,但我不缺德。此次主要为前端界面调整,周末愉快。
|
||||||
|
|
||||||
|
## Feature
|
||||||
|
- 支持长回复 [[yi-ge](https://github.com/Chanzhaoyu/chatgpt-web/pull/450)][[详情](https://github.com/Chanzhaoyu/chatgpt-web/pull/450)]
|
||||||
|
- 支持 `PWA` [[chenxch](https://github.com/Chanzhaoyu/chatgpt-web/pull/452)]
|
||||||
|
|
||||||
|
## Enhancement
|
||||||
|
- 调整移动端按钮和优化布局
|
||||||
|
- 调整 `iOS` 上安全距离
|
||||||
|
- 简化 `docker-compose` 部署 [[cloudGrin](https://github.com/Chanzhaoyu/chatgpt-web/pull/466)]
|
||||||
|
|
||||||
|
## BugFix
|
||||||
|
- 修复清空会话侧边栏标题不会重置的问题 [[RyanXinOne](https://github.com/Chanzhaoyu/chatgpt-web/pull/453)]
|
||||||
|
- 修复设置文字过长时导致的设置按钮消失的问题
|
||||||
|
|
||||||
|
## Other
|
||||||
|
- 更新依赖
|
||||||
|
|
||||||
|
## v2.10.2
|
||||||
|
|
||||||
|
`2023-03-09`
|
||||||
|
|
||||||
|
衔接 `2.10.1` 版本[详情](https://github.com/Chanzhaoyu/chatgpt-web/releases/tag/v2.10.1)
|
||||||
|
|
||||||
|
## Enhancement
|
||||||
|
- 移动端下输入框获得焦点时左侧按钮隐藏
|
||||||
|
|
||||||
|
## BugFix
|
||||||
|
- 修复 `2.10.1` 中添加 `OPENAI_API_MODEL` 变量的判断错误,会导致默认模型指定失效,抱歉
|
||||||
|
- 回退 `2.10.1` 中前端变量影响 `Docker` 打包
|
||||||
|
|
||||||
## v2.10.1
|
## v2.10.1
|
||||||
|
|
||||||
`2023-03-09`
|
`2023-03-09`
|
||||||
@@ -24,7 +59,6 @@
|
|||||||
- 修复深色模式导出图片的样式问题
|
- 修复深色模式导出图片的样式问题
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## v2.10.0
|
## v2.10.0
|
||||||
|
|
||||||
`2023-03-07`
|
`2023-03-07`
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
|||||||
|
|
||||||
#### 前端网页
|
#### 前端网页
|
||||||
|
|
||||||
1、参考根目录下 `.env.example` 文件内容创建 `.env` 文件,修改 `VITE_APP_API_BASE_URL` 为你的实际后端接口地址
|
1、修改根目录下 `.env` 文件中的 `VITE_APP_API_BASE_URL` 为你的实际后端接口地址
|
||||||
|
|
||||||
2、根目录下运行以下命令,然后将 `dist` 文件夹内的文件复制到你网站服务的根目录下
|
2、根目录下运行以下命令,然后将 `dist` 文件夹内的文件复制到你网站服务的根目录下
|
||||||
|
|
||||||
|
|||||||
@@ -25,13 +25,13 @@ services:
|
|||||||
# Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效
|
# Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||||
SOCKS_PROXY_PORT: xxxx
|
SOCKS_PROXY_PORT: xxxx
|
||||||
nginx:
|
nginx:
|
||||||
build: nginx
|
image: nginx:alpine
|
||||||
image: chatgpt/nginx
|
|
||||||
ports:
|
ports:
|
||||||
- '80:80'
|
- '80:80'
|
||||||
expose:
|
expose:
|
||||||
- '80'
|
- '80'
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx/html/:/etc/nginx/html/
|
- ./nginx/html:/usr/share/nginx/html
|
||||||
|
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
|
||||||
links:
|
links:
|
||||||
- app
|
- app
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
FROM hub.c.163.com/library/nginx
|
|
||||||
|
|
||||||
MAINTAINER jo "tionsin@live.com"
|
|
||||||
|
|
||||||
RUN rm -rf /etc/nginx/conf.d/default.conf
|
|
||||||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
|
||||||
COPY ./html/ /usr/share/nginx/html/
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
|
||||||
@@ -3,9 +3,9 @@ server {
|
|||||||
server_name localhost;
|
server_name localhost;
|
||||||
charset utf-8;
|
charset utf-8;
|
||||||
error_page 500 502 503 504 /50x.html;
|
error_page 500 502 503 504 /50x.html;
|
||||||
location = / {
|
location / {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html index.htm;
|
try_files $uri /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api {
|
location /api {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
### docker-compose 部署教程
|
### docker-compose 部署教程
|
||||||
- 将打包好的前端文件放到 `nginx/html` 目录下
|
- 将打包好的前端文件放到 `nginx/html` 目录下
|
||||||
- ```shell
|
- ```shell
|
||||||
# 打包启动
|
# 启动
|
||||||
docker-compose build
|
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
```
|
```
|
||||||
- ```shell
|
- ```shell
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "2.10.1",
|
"version": "2.10.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "ChatGPT Web",
|
"description": "ChatGPT Web",
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||||
@@ -58,6 +58,7 @@
|
|||||||
"tailwindcss": "^3.2.7",
|
"tailwindcss": "^3.2.7",
|
||||||
"typescript": "~4.9.5",
|
"typescript": "~4.9.5",
|
||||||
"vite": "^4.1.4",
|
"vite": "^4.1.4",
|
||||||
|
"vite-plugin-pwa": "^0.14.4",
|
||||||
"vue-tsc": "^1.2.0"
|
"vue-tsc": "^1.2.0"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
|
|||||||
1852
pnpm-lock.yaml
generated
1852
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
BIN
public/pwa-192x192.png
Normal file
BIN
public/pwa-192x192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 7.2 KiB |
BIN
public/pwa-512x512.png
Normal file
BIN
public/pwa-512x512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
@@ -24,7 +24,7 @@
|
|||||||
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chatgpt": "^5.0.8",
|
"chatgpt": "^5.0.9",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"esno": "^0.16.3",
|
"esno": "^0.16.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
|||||||
8
service/pnpm-lock.yaml
generated
8
service/pnpm-lock.yaml
generated
@@ -4,7 +4,7 @@ specifiers:
|
|||||||
'@antfu/eslint-config': ^0.35.3
|
'@antfu/eslint-config': ^0.35.3
|
||||||
'@types/express': ^4.17.17
|
'@types/express': ^4.17.17
|
||||||
'@types/node': ^18.14.6
|
'@types/node': ^18.14.6
|
||||||
chatgpt: ^5.0.8
|
chatgpt: ^5.0.9
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.0.3
|
||||||
eslint: ^8.35.0
|
eslint: ^8.35.0
|
||||||
esno: ^0.16.3
|
esno: ^0.16.3
|
||||||
@@ -17,7 +17,7 @@ specifiers:
|
|||||||
typescript: ^4.9.5
|
typescript: ^4.9.5
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
chatgpt: 5.0.8
|
chatgpt: 5.0.9
|
||||||
dotenv: 16.0.3
|
dotenv: 16.0.3
|
||||||
esno: 0.16.3
|
esno: 0.16.3
|
||||||
express: 4.18.2
|
express: 4.18.2
|
||||||
@@ -902,8 +902,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/chatgpt/5.0.8:
|
/chatgpt/5.0.9:
|
||||||
resolution: {integrity: sha512-Bjh7Y15QIsZ+SkQvbbZGymv1PGxkZ7X1vwqAwvyqaMMhbipU4kxht/GL62VCxhoUCXPwxTfScbFeNFtNldgqaw==}
|
resolution: {integrity: sha512-H0MMegLKcYyYh3LeFO4ubIdJSiSAl4rRjTeXf3KjHfGXDM7QZ1EkiTH9RuIoaNzOm8rJTn4QEhrwBbOIpbalxw==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@@ -31,11 +31,14 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||||
|
|
||||||
if (process.env.OPENAI_API_KEY) {
|
if (process.env.OPENAI_API_KEY) {
|
||||||
|
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
||||||
|
const model = (typeof OPENAI_API_MODEL === 'string' && OPENAI_API_MODEL.length > 0)
|
||||||
|
? OPENAI_API_MODEL
|
||||||
|
: 'gpt-3.5-turbo'
|
||||||
|
|
||||||
const options: ChatGPTAPIOptions = {
|
const options: ChatGPTAPIOptions = {
|
||||||
apiKey: process.env.OPENAI_API_KEY,
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
completionParams: {
|
completionParams: { model },
|
||||||
model: process.env.OPENAI_API_MODEL ?? 'gpt-3.5-turbo',
|
|
||||||
},
|
|
||||||
debug: false,
|
debug: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +87,8 @@ async function chatReplyProcess(
|
|||||||
lastContext?: { conversationId?: string; parentMessageId?: string },
|
lastContext?: { conversationId?: string; parentMessageId?: string },
|
||||||
process?: (chat: ChatMessage) => void,
|
process?: (chat: ChatMessage) => void,
|
||||||
) {
|
) {
|
||||||
if (!message)
|
// if (!message)
|
||||||
return sendResponse({ type: 'Fail', message: 'Message is empty' })
|
// return sendResponse({ type: 'Fail', message: 'Message is empty' })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let options: SendMessageOptions = { timeoutMs }
|
let options: SendMessageOptions = { timeoutMs }
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ const userInfo = computed(() => userStore.userInfo)
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex items-center">
|
<div class="flex items-center overflow-hidden">
|
||||||
<div class="w-10 h-10 overflow-hidden rounded-full">
|
<div class="w-10 h-10 overflow-hidden rounded-full shrink-0">
|
||||||
<template v-if="isString(userInfo.avatar) && userInfo.avatar.length > 0">
|
<template v-if="isString(userInfo.avatar) && userInfo.avatar.length > 0">
|
||||||
<NAvatar
|
<NAvatar
|
||||||
size="large"
|
size="large"
|
||||||
@@ -25,11 +25,11 @@ const userInfo = computed(() => userStore.userInfo)
|
|||||||
<NAvatar size="large" round :src="defaultAvatar" />
|
<NAvatar size="large" round :src="defaultAvatar" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div class="ml-2">
|
<div class="flex-1 min-w-0 ml-2">
|
||||||
<h2 class="font-bold text-md">
|
<h2 class="overflow-hidden font-bold text-md text-ellipsis whitespace-nowrap">
|
||||||
{{ userInfo.name ?? 'ChenZhaoYu' }}
|
{{ userInfo.name ?? 'ChenZhaoYu' }}
|
||||||
</h2>
|
</h2>
|
||||||
<p class="text-xs text-gray-500">
|
<p class="overflow-hidden text-xs text-gray-500 text-ellipsis whitespace-nowrap">
|
||||||
<span
|
<span
|
||||||
v-if="isString(userInfo.description) && userInfo.description !== ''"
|
v-if="isString(userInfo.description) && userInfo.description !== ''"
|
||||||
v-html="userInfo.description"
|
v-html="userInfo.description"
|
||||||
|
|||||||
@@ -165,6 +165,7 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
if (!uuid || uuid === 0) {
|
if (!uuid || uuid === 0) {
|
||||||
if (this.chat.length) {
|
if (this.chat.length) {
|
||||||
this.chat[0].data = []
|
this.chat[0].data = []
|
||||||
|
this.history[0].title = 'New Chat'
|
||||||
this.recordState()
|
this.recordState()
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@@ -173,6 +174,7 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
const index = this.chat.findIndex(item => item.uuid === uuid)
|
const index = this.chat.findIndex(item => item.uuid === uuid)
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.chat[index].data = []
|
this.chat[index].data = []
|
||||||
|
this.history[index].title = 'New Chat'
|
||||||
this.recordState()
|
this.recordState()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ body,
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
padding-bottom: constant(safe-area-inset-bottom);
|
padding-bottom: constant(safe-area-inset-bottom);
|
||||||
|
padding-bottom: env(safe-area-inset-bottom);
|
||||||
}
|
}
|
||||||
|
|||||||
78
src/views/chat/components/Header/index.vue
Normal file
78
src/views/chat/components/Header/index.vue
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { computed, nextTick } from 'vue'
|
||||||
|
import { HoverButton, SvgIcon } from '@/components/common'
|
||||||
|
import { useAppStore, useChatStore } from '@/store'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
usingContext: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Emit {
|
||||||
|
(ev: 'export'): void
|
||||||
|
(ev: 'toggleUsingContext'): void
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<Props>()
|
||||||
|
|
||||||
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
|
const appStore = useAppStore()
|
||||||
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
|
const collapsed = computed(() => appStore.siderCollapsed)
|
||||||
|
const currentChatHistory = computed(() => chatStore.getChatHistoryByCurrentActive)
|
||||||
|
|
||||||
|
function handleUpdateCollapsed() {
|
||||||
|
appStore.setSiderCollapsed(!collapsed.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onScrollToTop() {
|
||||||
|
const scrollRef = document.querySelector('#scrollRef')
|
||||||
|
if (scrollRef)
|
||||||
|
nextTick(() => scrollRef.scrollTop = 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleExport() {
|
||||||
|
emit('export')
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleUsingContext() {
|
||||||
|
emit('toggleUsingContext')
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<header
|
||||||
|
class="sticky top-0 left-0 right-0 z-30 border-b dark:border-neutral-800 bg-white/80 dark:bg-black/20 backdrop-blur"
|
||||||
|
>
|
||||||
|
<div class="relative flex items-center justify-between min-w-0 overflow-hidden h-14">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<button
|
||||||
|
class="flex items-center justify-center w-11 h-11"
|
||||||
|
@click="handleUpdateCollapsed"
|
||||||
|
>
|
||||||
|
<SvgIcon v-if="collapsed" class="text-2xl" icon="ri:align-justify" />
|
||||||
|
<SvgIcon v-else class="text-2xl" icon="ri:align-right" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<h1
|
||||||
|
class="flex-1 px-4 pr-6 overflow-hidden cursor-pointer select-none text-ellipsis whitespace-nowrap"
|
||||||
|
@dblclick="onScrollToTop"
|
||||||
|
>
|
||||||
|
{{ currentChatHistory?.title ?? '' }}
|
||||||
|
</h1>
|
||||||
|
<div class="flex items-center space-x-2">
|
||||||
|
<HoverButton @click="toggleUsingContext">
|
||||||
|
<span class="text-xl" :class="{ 'text-[#4b9e5f]': usingContext, 'text-[#a8071a]': !usingContext }">
|
||||||
|
<SvgIcon icon="ri:chat-history-line" />
|
||||||
|
</span>
|
||||||
|
</HoverButton>
|
||||||
|
<HoverButton @click="handleExport">
|
||||||
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
|
<SvgIcon icon="ri:download-2-line" />
|
||||||
|
</span>
|
||||||
|
</HoverButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
</template>
|
||||||
21
src/views/chat/hooks/useUsingContext.ts
Normal file
21
src/views/chat/hooks/useUsingContext.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { ref } from 'vue'
|
||||||
|
import { useMessage } from 'naive-ui'
|
||||||
|
import { t } from '@/locales'
|
||||||
|
|
||||||
|
export function useUsingContext() {
|
||||||
|
const ms = useMessage()
|
||||||
|
const usingContext = ref<boolean>(true)
|
||||||
|
|
||||||
|
function toggleUsingContext() {
|
||||||
|
usingContext.value = !usingContext.value
|
||||||
|
if (usingContext.value)
|
||||||
|
ms.success(t('chat.turnOnContext'))
|
||||||
|
else
|
||||||
|
ms.warning(t('chat.turnOffContext'))
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
usingContext,
|
||||||
|
toggleUsingContext,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import { Message } from './components'
|
|||||||
import { useScroll } from './hooks/useScroll'
|
import { useScroll } from './hooks/useScroll'
|
||||||
import { useChat } from './hooks/useChat'
|
import { useChat } from './hooks/useChat'
|
||||||
import { useCopyCode } from './hooks/useCopyCode'
|
import { useCopyCode } from './hooks/useCopyCode'
|
||||||
|
import { useUsingContext } from './hooks/useUsingContext'
|
||||||
|
import HeaderComponent from './components/Header/index.vue'
|
||||||
import { HoverButton, SvgIcon } from '@/components/common'
|
import { HoverButton, SvgIcon } from '@/components/common'
|
||||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
import { useChatStore } from '@/store'
|
import { useChatStore } from '@/store'
|
||||||
@@ -15,6 +17,8 @@ import { t } from '@/locales'
|
|||||||
|
|
||||||
let controller = new AbortController()
|
let controller = new AbortController()
|
||||||
|
|
||||||
|
const openLongReply = import.meta.env.VITE_GLOB_OPEN_LONG_REPLY === 'true'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
const ms = useMessage()
|
const ms = useMessage()
|
||||||
@@ -22,9 +26,11 @@ const ms = useMessage()
|
|||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
useCopyCode()
|
useCopyCode()
|
||||||
|
|
||||||
const { isMobile } = useBasicLayout()
|
const { isMobile } = useBasicLayout()
|
||||||
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
||||||
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
|
const { scrollRef, scrollToBottom } = useScroll()
|
||||||
|
const { usingContext, toggleUsingContext } = useUsingContext()
|
||||||
|
|
||||||
const { uuid } = route.params as { uuid: string }
|
const { uuid } = route.params as { uuid: string }
|
||||||
|
|
||||||
@@ -33,14 +39,13 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.
|
|||||||
|
|
||||||
const prompt = ref<string>('')
|
const prompt = ref<string>('')
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
const usingContext = ref<boolean>(true)
|
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
onConversation()
|
onConversation()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onConversation() {
|
async function onConversation() {
|
||||||
const message = prompt.value
|
let message = prompt.value
|
||||||
|
|
||||||
if (loading.value)
|
if (loading.value)
|
||||||
return
|
return
|
||||||
@@ -87,40 +92,53 @@ async function onConversation() {
|
|||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
let lastText = ''
|
||||||
prompt: message,
|
const fetchChatAPIOnce = async () => {
|
||||||
options,
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||||
signal: controller.signal,
|
prompt: message,
|
||||||
onDownloadProgress: ({ event }) => {
|
options,
|
||||||
const xhr = event.target
|
signal: controller.signal,
|
||||||
const { responseText } = xhr
|
onDownloadProgress: ({ event }) => {
|
||||||
// Always process the final line
|
const xhr = event.target
|
||||||
const lastIndex = responseText.lastIndexOf('\n')
|
const { responseText } = xhr
|
||||||
let chunk = responseText
|
// Always process the final line
|
||||||
if (lastIndex !== -1)
|
const lastIndex = responseText.lastIndexOf('\n')
|
||||||
chunk = responseText.substring(lastIndex)
|
let chunk = responseText
|
||||||
try {
|
if (lastIndex !== -1)
|
||||||
const data = JSON.parse(chunk)
|
chunk = responseText.substring(lastIndex)
|
||||||
updateChat(
|
try {
|
||||||
+uuid,
|
const data = JSON.parse(chunk)
|
||||||
dataSources.value.length - 1,
|
updateChat(
|
||||||
{
|
+uuid,
|
||||||
dateTime: new Date().toLocaleString(),
|
dataSources.value.length - 1,
|
||||||
text: data.text ?? '',
|
{
|
||||||
inversion: false,
|
dateTime: new Date().toLocaleString(),
|
||||||
error: false,
|
text: lastText + data.text ?? '',
|
||||||
loading: false,
|
inversion: false,
|
||||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
error: false,
|
||||||
requestOptions: { prompt: message, options: { ...options } },
|
loading: false,
|
||||||
},
|
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||||
)
|
requestOptions: { prompt: message, options: { ...options } },
|
||||||
scrollToBottomIfAtBottom()
|
},
|
||||||
}
|
)
|
||||||
catch (error) {
|
|
||||||
|
if (openLongReply && data.detail.choices[0].finish_reason === 'length') {
|
||||||
|
options.parentMessageId = data.id
|
||||||
|
lastText = data.text
|
||||||
|
message = ''
|
||||||
|
return fetchChatAPIOnce()
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToBottom()
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await fetchChatAPIOnce()
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
const errorMessage = error?.message ?? t('common.wrong')
|
const errorMessage = error?.message ?? t('common.wrong')
|
||||||
@@ -165,10 +183,10 @@ async function onConversation() {
|
|||||||
requestOptions: { prompt: message, options: { ...options } },
|
requestOptions: { prompt: message, options: { ...options } },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
scrollToBottom()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +198,7 @@ async function onRegenerate(index: number) {
|
|||||||
|
|
||||||
const { requestOptions } = dataSources.value[index]
|
const { requestOptions } = dataSources.value[index]
|
||||||
|
|
||||||
const message = requestOptions?.prompt ?? ''
|
let message = requestOptions?.prompt ?? ''
|
||||||
|
|
||||||
let options: Chat.ConversationRequest = {}
|
let options: Chat.ConversationRequest = {}
|
||||||
|
|
||||||
@@ -204,39 +222,50 @@ async function onRegenerate(index: number) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
let lastText = ''
|
||||||
prompt: message,
|
const fetchChatAPIOnce = async () => {
|
||||||
options,
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||||
signal: controller.signal,
|
prompt: message,
|
||||||
onDownloadProgress: ({ event }) => {
|
options,
|
||||||
const xhr = event.target
|
signal: controller.signal,
|
||||||
const { responseText } = xhr
|
onDownloadProgress: ({ event }) => {
|
||||||
// Always process the final line
|
const xhr = event.target
|
||||||
const lastIndex = responseText.lastIndexOf('\n')
|
const { responseText } = xhr
|
||||||
let chunk = responseText
|
// Always process the final line
|
||||||
if (lastIndex !== -1)
|
const lastIndex = responseText.lastIndexOf('\n')
|
||||||
chunk = responseText.substring(lastIndex)
|
let chunk = responseText
|
||||||
try {
|
if (lastIndex !== -1)
|
||||||
const data = JSON.parse(chunk)
|
chunk = responseText.substring(lastIndex)
|
||||||
updateChat(
|
try {
|
||||||
+uuid,
|
const data = JSON.parse(chunk)
|
||||||
index,
|
updateChat(
|
||||||
{
|
+uuid,
|
||||||
dateTime: new Date().toLocaleString(),
|
index,
|
||||||
text: data.text ?? '',
|
{
|
||||||
inversion: false,
|
dateTime: new Date().toLocaleString(),
|
||||||
error: false,
|
text: lastText + data.text ?? '',
|
||||||
loading: false,
|
inversion: false,
|
||||||
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
error: false,
|
||||||
requestOptions: { prompt: message, ...options },
|
loading: false,
|
||||||
},
|
conversationOptions: { conversationId: data.conversationId, parentMessageId: data.id },
|
||||||
)
|
requestOptions: { prompt: message, ...options },
|
||||||
}
|
},
|
||||||
catch (error) {
|
)
|
||||||
//
|
|
||||||
}
|
if (openLongReply && data.detail.choices[0].finish_reason === 'length') {
|
||||||
},
|
options.parentMessageId = data.id
|
||||||
})
|
lastText = data.text
|
||||||
|
message = ''
|
||||||
|
return fetchChatAPIOnce()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await fetchChatAPIOnce()
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
if (error.message === 'canceled') {
|
if (error.message === 'canceled') {
|
||||||
@@ -365,24 +394,6 @@ function handleStop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleUsingContext() {
|
|
||||||
usingContext.value = !usingContext.value
|
|
||||||
if (usingContext.value) {
|
|
||||||
dialog.info({
|
|
||||||
title: t('chat.usingContext'),
|
|
||||||
content: t('chat.turnOnContext'),
|
|
||||||
positiveText: t('common.yes'),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
dialog.info({
|
|
||||||
title: t('chat.usingContext'),
|
|
||||||
content: t('chat.turnOffContext'),
|
|
||||||
positiveText: t('common.yes'),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const placeholder = computed(() => {
|
const placeholder = computed(() => {
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
return t('chat.placeholderMobile')
|
return t('chat.placeholderMobile')
|
||||||
@@ -393,16 +404,10 @@ const buttonDisabled = computed(() => {
|
|||||||
return loading.value || !prompt.value || prompt.value.trim() === ''
|
return loading.value || !prompt.value || prompt.value.trim() === ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const wrapClass = computed(() => {
|
|
||||||
if (isMobile.value)
|
|
||||||
return ['pt-14']
|
|
||||||
return []
|
|
||||||
})
|
|
||||||
|
|
||||||
const footerClass = computed(() => {
|
const footerClass = computed(() => {
|
||||||
let classes = ['p-4']
|
let classes = ['p-4']
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
classes = ['sticky', 'left-0', 'bottom-0', 'right-0', 'p-2', 'pr-4', 'overflow-hidden']
|
classes = ['sticky', 'left-0', 'bottom-0', 'right-0', 'p-2', 'pr-3', 'overflow-hidden']
|
||||||
return classes
|
return classes
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -417,7 +422,13 @@ onUnmounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col w-full h-full" :class="wrapClass">
|
<div class="flex flex-col w-full h-full">
|
||||||
|
<HeaderComponent
|
||||||
|
v-if="isMobile"
|
||||||
|
:using-context="usingContext"
|
||||||
|
@export="handleExport"
|
||||||
|
@toggle-using-context="toggleUsingContext"
|
||||||
|
/>
|
||||||
<main class="flex-1 overflow-hidden">
|
<main class="flex-1 overflow-hidden">
|
||||||
<div
|
<div
|
||||||
id="scrollRef"
|
id="scrollRef"
|
||||||
@@ -469,12 +480,12 @@ onUnmounted(() => {
|
|||||||
<SvgIcon icon="ri:delete-bin-line" />
|
<SvgIcon icon="ri:delete-bin-line" />
|
||||||
</span>
|
</span>
|
||||||
</HoverButton>
|
</HoverButton>
|
||||||
<HoverButton @click="handleExport">
|
<HoverButton v-if="!isMobile" @click="handleExport">
|
||||||
<span class="text-xl text-[#4f555e] dark:text-white">
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
<SvgIcon icon="ri:download-2-line" />
|
<SvgIcon icon="ri:download-2-line" />
|
||||||
</span>
|
</span>
|
||||||
</HoverButton>
|
</HoverButton>
|
||||||
<HoverButton @click="toggleUsingContext">
|
<HoverButton v-if="!isMobile" @click="toggleUsingContext">
|
||||||
<span class="text-xl" :class="{ 'text-[#4b9e5f]': usingContext, 'text-[#a8071a]': !usingContext }">
|
<span class="text-xl" :class="{ 'text-[#4b9e5f]': usingContext, 'text-[#a8071a]': !usingContext }">
|
||||||
<SvgIcon icon="ri:chat-history-line" />
|
<SvgIcon icon="ri:chat-history-line" />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { computed } from 'vue'
|
|||||||
import { NLayout, NLayoutContent } from 'naive-ui'
|
import { NLayout, NLayoutContent } from 'naive-ui'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import Sider from './sider/index.vue'
|
import Sider from './sider/index.vue'
|
||||||
import Header from './header/index.vue'
|
|
||||||
import Permission from './Permission.vue'
|
import Permission from './Permission.vue'
|
||||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
import { useAppStore, useAuthStore, useChatStore } from '@/store'
|
import { useAppStore, useAuthStore, useChatStore } from '@/store'
|
||||||
@@ -40,7 +39,6 @@ const getContainerClass = computed(() => {
|
|||||||
<div class="h-full overflow-hidden" :class="getMobileClass">
|
<div class="h-full overflow-hidden" :class="getMobileClass">
|
||||||
<NLayout class="z-40 transition" :class="getContainerClass" has-sider>
|
<NLayout class="z-40 transition" :class="getContainerClass" has-sider>
|
||||||
<Sider />
|
<Sider />
|
||||||
<Header v-if="isMobile" />
|
|
||||||
<NLayoutContent class="h-full">
|
<NLayoutContent class="h-full">
|
||||||
<RouterView v-slot="{ Component, route }">
|
<RouterView v-slot="{ Component, route }">
|
||||||
<component :is="Component" :key="route.fullPath" />
|
<component :is="Component" :key="route.fullPath" />
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { computed, nextTick } from 'vue'
|
|
||||||
import { SvgIcon } from '@/components/common'
|
|
||||||
import { useAppStore, useChatStore } from '@/store'
|
|
||||||
|
|
||||||
const appStore = useAppStore()
|
|
||||||
const chatStore = useChatStore()
|
|
||||||
|
|
||||||
const collapsed = computed(() => appStore.siderCollapsed)
|
|
||||||
const currentChatHistory = computed(() => chatStore.getChatHistoryByCurrentActive)
|
|
||||||
|
|
||||||
function handleUpdateCollapsed() {
|
|
||||||
appStore.setSiderCollapsed(!collapsed.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onScrollToTop() {
|
|
||||||
const scrollRef = document.querySelector('#scrollRef')
|
|
||||||
if (scrollRef)
|
|
||||||
nextTick(() => scrollRef.scrollTop = 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function onScrollToBottom() {
|
|
||||||
const scrollRef = document.querySelector('#scrollRef')
|
|
||||||
if (scrollRef)
|
|
||||||
nextTick(() => scrollRef.scrollTop = scrollRef.scrollHeight)
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<header
|
|
||||||
class="fixed top-0 left-0 right-0 z-30 border-b dark:border-neutral-800 bg-white/80 dark:bg-black/20 backdrop-blur"
|
|
||||||
>
|
|
||||||
<div class="relative flex items-center justify-between h-14">
|
|
||||||
<button
|
|
||||||
class="flex items-center justify-center w-11 h-11"
|
|
||||||
@click="handleUpdateCollapsed"
|
|
||||||
>
|
|
||||||
<SvgIcon v-if="collapsed" class="text-2xl" icon="ri:align-justify" />
|
|
||||||
<SvgIcon v-else class="text-2xl" icon="ri:align-right" />
|
|
||||||
</button>
|
|
||||||
<h1
|
|
||||||
class="flex-1 px-4 overflow-hidden text-center cursor-pointer select-none text-ellipsis whitespace-nowrap"
|
|
||||||
@dblclick="onScrollToTop"
|
|
||||||
>
|
|
||||||
{{ currentChatHistory?.title ?? '' }}
|
|
||||||
</h1>
|
|
||||||
<button
|
|
||||||
class="flex items-center justify-center w-11 h-11"
|
|
||||||
@click="onScrollToBottom"
|
|
||||||
>
|
|
||||||
<SvgIcon class="text-2xl" icon="ri:arrow-down-s-line" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
</template>
|
|
||||||
@@ -9,8 +9,9 @@ const show = ref(false)
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t dark:border-neutral-800">
|
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t dark:border-neutral-800">
|
||||||
<UserAvatar />
|
<div class="flex-1 flex-shrink-0 overflow-hidden">
|
||||||
|
<UserAvatar />
|
||||||
|
</div>
|
||||||
<HoverButton :tooltip="$t('setting.setting')" @click="show = true">
|
<HoverButton :tooltip="$t('setting.setting')" @click="show = true">
|
||||||
<span class="text-xl text-[#4f555e] dark:text-white">
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
<SvgIcon icon="ri:settings-4-line" />
|
<SvgIcon icon="ri:settings-4-line" />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
export default defineConfig((env) => {
|
export default defineConfig((env) => {
|
||||||
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
|
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
|
||||||
@@ -11,7 +12,20 @@ export default defineConfig((env) => {
|
|||||||
'@': path.resolve(process.cwd(), 'src'),
|
'@': path.resolve(process.cwd(), 'src'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [vue()],
|
plugins: [
|
||||||
|
vue(),
|
||||||
|
VitePWA({
|
||||||
|
injectRegister: 'auto',
|
||||||
|
manifest: {
|
||||||
|
name: 'chatGPT',
|
||||||
|
short_name: 'chatGPT',
|
||||||
|
icons: [
|
||||||
|
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
|
||||||
|
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 1002,
|
port: 1002,
|
||||||
|
|||||||
Reference in New Issue
Block a user