Compare commits

..

68 Commits

Author SHA1 Message Date
ChenZhaoYu
797cc7461b Merge branch 'dev' 2023-02-14 10:09:10 +08:00
ChenZhaoYu
58547d1b58 chore: version 2.1.0 2023-02-14 10:08:31 +08:00
Redon
c933a851f4 Merge pull request #21 from Chanzhaoyu/dev
v2.1.0
2023-02-14 10:05:21 +08:00
ChenZhaoYu
86fcbbff0b feat: 上限文联想改为前端进行 2023-02-14 10:04:32 +08:00
ChenZhaoYu
5d1f8519c2 chore: typo description 2023-02-14 08:45:07 +08:00
ChenZhaoYu
3c21068150 chore: update readme 2023-02-13 21:07:34 +08:00
ChenZhaoYu
cd03a71ef1 chore: update deps 2023-02-13 21:02:25 +08:00
Redon
1d74717beb Merge pull request #20 from Chanzhaoyu/dev
fix: 修复代码提交前验证流程
2023-02-13 20:55:55 +08:00
ChenZhaoYu
e35abb1c98 fix: 修复代码提交前验证流程 2023-02-13 20:55:26 +08:00
Redon
b4b0f65158 Merge pull request #19 from Chanzhaoyu/dev
chore: 移除打包测试
2023-02-13 20:46:37 +08:00
ChenZhaoYu
910c19b02e chore: 移除打包测试 2023-02-13 20:42:45 +08:00
Redon
32049fbf18 Merge pull request #18 from Chanzhaoyu/dev
chore: key invalid tips
2023-02-13 20:34:08 +08:00
ChenZhaoYu
817a4842ac chore: key invalid tips 2023-02-13 20:33:36 +08:00
Redon
0cd120ec5b Merge pull request #17 from Chanzhaoyu/dev
chore: 优化 `service` 内命令
2023-02-13 20:24:17 +08:00
ChenZhaoYu
007763f7d7 chore: 忽略 service 文件夹 2023-02-13 20:13:19 +08:00
ChenZhaoYu
3debaec4b2 chore: 添加 service 打包编译设置 2023-02-13 20:10:08 +08:00
ChenZhaoYu
35f353c1f7 chore: 补全配置 2023-02-13 19:56:11 +08:00
Redon
3ac6746930 Merge pull request #16 from Chanzhaoyu/dev
fix: 上下文按钮失效
2023-02-13 19:40:46 +08:00
ChenZhaoYu
9b556e4833 chore: 添加对于模型的提示 2023-02-13 19:30:26 +08:00
ChenZhaoYu
071283c007 fix: 清除上下文按钮失效的问题 2023-02-13 19:25:59 +08:00
Redon
854261ef86 Merge pull request #15 from Chanzhaoyu/dev
chore: 修复报错和自动化错误
2023-02-13 19:20:51 +08:00
ChenZhaoYu
633e9ad8e2 chore: cli error 2023-02-13 19:18:01 +08:00
ChenZhaoYu
47dd6c9801 fix: type-check 2023-02-13 19:17:55 +08:00
Redon
0eb9df6d31 Merge pull request #14 from Chanzhaoyu/dev
chore: 优化部份问题
2023-02-13 19:11:49 +08:00
ChenZhaoYu
8bfbe6f7df feat: 调整页面样式 2023-02-13 19:10:21 +08:00
ChenZhaoYu
43e8635e7f chore: README.md 2023-02-13 19:09:34 +08:00
Redon
b7542c70cb Create ci.yml
chore: test cli
2023-02-13 18:58:26 +08:00
Redon
b594ec5de1 Merge pull request #12 from Chanzhaoyu/dev
chore: typo
2023-02-13 18:41:27 +08:00
ChenZhaoYu
9a9b154040 chore: typo 2023-02-13 18:21:26 +08:00
Redon
12681b1a05 Update README.md 2023-02-13 16:48:24 +08:00
Redon
9f4f6304c7 Merge pull request #11 from Chanzhaoyu/dev
chore: clear cache
2023-02-13 16:37:23 +08:00
ChenZhaoYu
93c63d9195 chore: clear cache 2023-02-13 16:35:58 +08:00
Redon
361494d444 Merge pull request #10 from Chanzhaoyu/dev
v2.0.0
2023-02-13 16:33:19 +08:00
ChenZhaoYu
2f69cfd10b chore: CHANGELOG.md 2023-02-13 16:32:28 +08:00
ChenZhaoYu
0086f17df4 chore: version 2.0.0 2023-02-13 16:30:12 +08:00
ChenZhaoYu
befad1cbe1 chore: README.md 2023-02-13 16:29:51 +08:00
ChenZhaoYu
6cafc07e0d feat: 调整内容 2023-02-13 16:01:18 +08:00
ChenZhaoYu
feb167e2da chore: 移除页面多余内容 2023-02-13 15:57:31 +08:00
ChenZhaoYu
847623e22a feat: 前后端统一接口类型 2023-02-13 15:54:17 +08:00
ChenZhaoYu
dd522eb404 feat: 统一服务端返回参数 2023-02-13 15:08:55 +08:00
ChenZhaoYu
73c9ac4d8f feat: 调整消息布局以便扩展 2023-02-13 14:29:45 +08:00
ChenZhaoYu
727562f495 feat: 添加用户头像 2023-02-13 14:13:20 +08:00
ChenZhaoYu
d7464642a7 feat: 侧边栏历史会话 2023-02-13 13:47:41 +08:00
ChenZhaoYu
951636869b feat: 调整为路由模式 2023-02-13 12:38:44 +08:00
ChenZhaoYu
39f718ef16 feat: 优化文件结构、组件、布局 2023-02-13 11:59:00 +08:00
ChenZhaoYu
72df35c929 chore: 调整部份脚本命令 2023-02-13 11:12:28 +08:00
ChenZhaoYu
cf7a56a015 chore: 打包脚本错误 2023-02-13 11:08:11 +08:00
ChenZhaoYu
5ca1b4557a chore: miss build-only script 2023-02-13 11:06:07 +08:00
ChenZhaoYu
11544ff24b chore: 添加 lint-staged 2023-02-13 11:03:10 +08:00
ChenZhaoYu
f910b5f8a4 chore: 调整文件结构 service 和 web 分离 2023-02-13 10:00:08 +08:00
ChenZhaoYu
98e75c0c5c chore: release v1.0.5 2023-02-12 10:40:22 +08:00
ChenZhaoYu
06fd5a861c chore: CHANGELOG.md 2023-02-12 10:38:17 +08:00
ChenZhaoYu
fc0d2073aa chore: 默认 MD 文件 2023-02-12 10:34:51 +08:00
ChenZhaoYu
2c816afbd2 pref: 取消 disabled 以使 input 焦点连续输入 2023-02-12 10:29:21 +08:00
ChenZhaoYu
1bf2399a45 feat: chat 回复样式错误 2023-02-12 10:28:35 +08:00
Redon
ddec57f562 Merge pull request #6 from jjm2473/patch-1
fix: 防止中文输入法输入英文时触发提交
2023-02-12 10:24:04 +08:00
练亮斌
63af4a8e97 fix: 防止中文输入法输入英文时触发提交
部分输入法支持中英文混输,输入过程中按空格选择中文,按回车把当前的英文直接上屏。

至少在Chrome浏览器中,会把输入法选英文词的回车作为keyup事件,导致未输入完成的句子被提交。改成监听keypress事件就没问题了。
其他浏览器未测试。
2023-02-11 23:51:09 +08:00
ChenZhaoYu
a5a67f688e chore: release v1.0.4 2023-02-11 15:38:57 +08:00
ChenZhaoYu
692d37ec35 chore: version 1.0.4 2023-02-11 15:38:44 +08:00
ChenZhaoYu
4b16560958 feat: 支持上下文联想 2023-02-11 15:20:58 +08:00
ChenZhaoYu
52bfd15ad8 chore: release v1.0.3 2023-02-11 09:17:03 +08:00
ChenZhaoYu
e0920bee4b chore: CHANGELOG 2023-02-11 09:14:11 +08:00
ChenZhaoYu
cb589e05e9 chore: update deps 2023-02-11 08:32:59 +08:00
ChenZhaoYu
6aa2591d9c chore: editor config 2023-02-11 08:17:48 +08:00
ChenZhaoYu
ad41dd21c6 chore: remove Message.vue 2023-02-10 11:51:30 +08:00
ChenZhaoYu
35da3f1d1f feat: 拆分以便扩展 2023-02-10 11:40:40 +08:00
ChenZhaoYu
31ea7c5529 chore: remove some config 2023-02-10 10:49:26 +08:00
ChenZhaoYu
cab7b0ec99 chore: CHANGELOG 2023-02-10 10:36:39 +08:00
69 changed files with 5775 additions and 1322 deletions

3
.commitlintrc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"extends": ["@commitlint/config-conventional"]
}

3
.env
View File

@@ -1,5 +1,2 @@
# OpenAI API Key
OPENAI_API_KEY='xxxx'
# Glob API URL
VITE_GLOB_API_URL='http://localhost:3002'

View File

@@ -1 +0,0 @@
components.d.ts

47
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Setup
run: npm i -g @antfu/ni
- name: Install
run: nci
- name: Lint
run: nr lint:fix
typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set node
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Setup
run: npm i -g @antfu/ni
- name: Install
run: nci
- name: Typecheck
run: nr type-check

4
.husky/commit-msg Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit

4
.husky/pre-commit Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged

3
.npmrc
View File

@@ -1,4 +1 @@
registry=https://registry.npmmirror.com/
shamefully-hoist=true
strict-peer-dependencies=false
auto-install-peers=true

View File

@@ -1,4 +0,0 @@
{
"semi": false,
"singleQuote": true
}

View File

@@ -1,3 +1,3 @@
{
"recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
"recommendations": ["Vue.volar", "dbaeumer.vscode-eslint"]
}

19
.vscode/settings.json vendored
View File

@@ -1,13 +1,29 @@
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"json",
"jsonc",
"json5",
"yaml",
"yml",
"markdown"
],
"cSpell.words": [
"antfu",
"axios",
"bumpp",
"chatgpt",
"commitlint",
"esno",
"GPTAPI",
"iconify",
@@ -15,7 +31,10 @@
"OPENAI",
"pinia",
"rushstack",
"Sider",
"tailwindcss",
"tsup",
"Typecheck",
"unplugin",
"VITE",
"vueuse"

View File

@@ -0,0 +1,53 @@
## v2.1.0
`2023-02-14`
### Enhancement
- 更新依赖至最新
- 联想功能移动至前端提交,后端只做转发
### BugFix
- 修复部份项目检测有关 `Bug`
- 修复清除上下文按钮失效
## v2.0.0
`2023-02-13`
### Refactor
重构并优化大部分内容
## v1.0.5
`2023-02-12`
### Enhancement
- 输入框焦点,连续提交
### BugFix
- 修复信息框样式问题
- 修复中文输入法提交问题
## v1.0.4
`2023-02-11`
### Feature
- 支持上下文联想
## v1.0.3
`2023-02-11`
### Enhancement
- 拆分 `service` 文件以便扩展
- 调整 `Eslint` 相关验证
### BugFix
- 修复部份控制台报错
## v1.0.2
`2023-02-10`
### BugFix
- 修复新增信息容器不会自动滚动到问题
- 修复文本过长不换行到问题 [#1](https://github.com/Chanzhaoyu/chatgpt-web/issues/1)

26
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,26 @@
# 指南
## Commit 指南
Commit messages 请遵循[conventional-changelog 标准](https://www.conventionalcommits.org/en/v1.0.0/)
```bash
<类型>[可选 范围]: <描述>
[可选 正文]
[可选 脚注]
```
### Commit 类型
以下是 commit 类型列表:
- feat: 新特性或功能
- fix: 缺陷修复
- docs: 文档更新
- style: 代码风格或者组件样式更新
- refactor: 代码重构,不引入新功能和缺陷修复
- perf: 性能优化
- test: 单元测试
- chore: 其他不修改 src 或测试文件的提交

120
README.md
View File

@@ -1,39 +1,121 @@
# ChatGPT Web Bot
# ChatGPT Web
English | [中文](./README.zh-CN.md)
使用 express 和 vue3 搭建的 ChartGPT 演示网页
ChartGPT demo page built with express and vue3
![cover](./docs/cover-2.png)
![cover](./docs/cover.png)
## Usage
> Make sure `node >= 18`
> 提示:目前 `OpenAI` 开放的模型最高只有 `GPT-3`,和现在网页所使用的 `GPT-3.5` 或 `GPT-4` 有很大差距,需要等官方开放最新的模型接口。
If pnpm is not installed
## 待实现路线
[x] 多会话储存和上下文逻辑
[x] 对代码等消息类型的格式化美化处理
[x] 用户模块(注册、登录、个人中心)
[x] 界面多语言
[x] 界面主题
[x] More...
## 前置要求
### Node
`node` 版本需要 >= 18使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
```shell
node -v
```
### PNPM
如果你没有安装过 `pnpm`
```shell
npm install pnpm -g
```
install node deps
### OpenAI API Key
获取 [OpenAI API key](https://platform.openai.com/overview) 并填写到本地环境变量
```
# service/.env 文件
OPENAI_API_KEY='Your key'
```
## 安装依赖
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
### 后端服务
进入文件夹 `/service` 运行以下命令
```shell
pnpm install
```
Sign up for an [OpenAI API key](https://platform.openai.com/overview) and store it in your environment.
```
# .env
OPENAI_API_KEY="Your Key"
```
Run service
### 网页
根目录下运行以下命令
```shell
pnpm run service
pnpm bootstrap
```
Run web
## 运行
### 后端服务
进入文件夹 `/service` 运行以下命令
```shell
pnpm run dev
pnpm start
```
### 网页
根目录下运行以下命令
```shell
pnpm dev
```
## 打包
### 后端服务
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。(搜索关键字:`express部署`
```shell
# 安装
pnpm install
# 打包
pnpm build
# 运行
pnpm prod
```
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
### 网页
根目录下运行以下命令,然后将 `dist` 文件夹复制到你的托管服务器上
```shell
pnpm build
```
### 常见问题
Q: 为什么 `Git` 提交总是报错?
A: 因为有提交信息验证,请遵循 [Commit 指南](./CONTRIBUTING.md)
Q: 如果只使用前端页面,在哪里改请求接口?
A: 根目录下 `.env` 文件中的 `VITE_GLOB_API_URL` 字段。
Q: 文件保存时全部爆红?
A: `vscode` 请安装项目推荐插件,或手动安装 `Eslint` 插件。
## License
MIT © [ChenZhaoYu](./license)

View File

@@ -1,40 +0,0 @@
# ChatGPT Web Bot
[English](./README.md) | 中文
使用 express 和 vue3 搭建的 ChartGPT 演示网页
![cover](./docs/cover.png)
## 使用
> Make sure `node >= 18`
如果你没有安装过 `pnpm`
```shell
npm install pnpm -g
```
安装依赖
```shell
pnpm install
```
获取 [OpenAI API key](https://platform.openai.com/overview) 到本地环境变量
```
# .env
OPENAI_API_KEY="Your Key"
```
运行服务
```shell
pnpm run service
```
运行网页
```shell
pnpm run dev
```
## License
MIT © [ChenZhaoYu](./license)

BIN
docs/cover-2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 94 KiB

View File

@@ -1,50 +1,54 @@
{
"name": "chatgpt-web",
"version": "1.0.2",
"description": "ChatGPT Web Bot",
"author": "ChenZhaoYu <chenzhaoyu1994@gami.com>",
"private": false,
"keywords": [
"chatgpt",
"chatbot",
"web",
"vue"
],
"scripts": {
"dev": "vite",
"service": "esno ./service/index.ts",
"build": "run-p type-check build-only",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore",
"release": "bumpp package.json --commit --push --tag"
},
"dependencies": {
"naive-ui": "^2.34.3",
"vue": "^3.2.45"
},
"devDependencies": {
"@antfu/eslint-config": "^0.35.2",
"@iconify/vue": "^4.1.0",
"@types/babel__core": "^7.20.0",
"@types/express": "^4.17.17",
"@types/node": "^18.11.12",
"@vitejs/plugin-vue": "^4.0.0",
"autoprefixer": "^10.4.13",
"axios": "^1.3.2",
"bumpp": "^8.2.1",
"chatgpt": "^4.2.0",
"dotenv": "^16.0.3",
"eslint": "^8.22.0",
"esno": "^0.16.3",
"express": "^4.18.2",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
"prettier": "^2.7.1",
"tailwindcss": "^3.2.6",
"typescript": "~4.7.4",
"vite": "^4.0.0",
"vue-tsc": "^1.0.12"
}
"name": "chatgpt-web",
"version": "2.1.0",
"private": false,
"description": "ChatGPT Web",
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
"keywords": [
"chatgpt-web",
"chatgpt",
"chatbot",
"vue"
],
"scripts": {
"dev": "vite",
"build": "run-p type-check build-only",
"preview": "vite preview",
"build-only": "vite build",
"type-check": "vue-tsc --noEmit",
"lint:fix": "eslint . --fix",
"bootstrap": "pnpm install && pnpm run common:prepare",
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml",
"common:prepare": "husky install"
},
"dependencies": {
"naive-ui": "^2.34.3",
"vue": "^3.2.47",
"vue-router": "^4.1.6"
},
"devDependencies": {
"@antfu/eslint-config": "^0.35.2",
"@commitlint/cli": "^17.4.3",
"@commitlint/config-conventional": "^17.4.3",
"@iconify/vue": "^4.1.0",
"@types/node": "^18.13.0",
"@vitejs/plugin-vue": "^4.0.0",
"autoprefixer": "^10.4.13",
"axios": "^1.3.2",
"eslint": "^8.34.0",
"husky": "^8.0.3",
"lint-staged": "^13.1.1",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.21",
"rimraf": "^4.1.2",
"tailwindcss": "^3.2.6",
"typescript": "~4.9.5",
"vite": "^4.1.1",
"vue-tsc": "^1.0.24"
},
"lint-staged": {
"*.{ts,tsx,vue}": [
"pnpm lint:fix"
]
}
}

2098
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

3
service/.env Normal file
View File

@@ -0,0 +1,3 @@
# OpenAI API Key - https://platform.openai.com/overview
# e.g: This key is invalid
OPENAI_API_KEY='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'

5
service/.eslintrc.json Normal file
View File

@@ -0,0 +1,5 @@
{
"root": true,
"ignorePatterns": ["build"],
"extends": ["@antfu"]
}

31
service/.gitignore vendored Normal file
View File

@@ -0,0 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
.DS_Store
dist
dist-ssr
coverage
*.local
/cypress/videos/
/cypress/screenshots/
# Editor directories and files
.vscode/*
!.vscode/settings.json
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
build

1
service/.npmrc Normal file
View File

@@ -0,0 +1 @@
enable-pre-post-scripts=true

3
service/.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"recommendations": ["dbaeumer.vscode-eslint"]
}

22
service/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,22 @@
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": [
"javascript",
"typescript",
"json",
"jsonc",
"json5",
"yaml"
],
"cSpell.words": [
"antfu",
"chatgpt",
"esno",
"GPTAPI",
"OPENAI"
]
}

View File

@@ -1,41 +0,0 @@
import dotenv from 'dotenv'
import { ChatGPTAPI } from 'chatgpt'
import express from 'express'
dotenv.config()
const app = express()
app.use(express.json())
async function chatAPI(message: string) {
if (!message)
throw new Error('Message is not defined')
if (!process.env.OPENAI_API_KEY)
throw new Error('OPENAI_API_KEY is not defined in .env file')
try {
const api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
const res = await api.sendMessage(message)
return res
}
catch (error) {
return error
}
}
app.all('*', (req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Content-Type')
res.header('Access-Control-Allow-Methods', '*')
next()
})
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
app.post('/chat', async (req, res) => {
const { message } = req.body
const response = await chatAPI(message)
res.send(response)
})

39
service/package.json Normal file
View File

@@ -0,0 +1,39 @@
{
"name": "chatgpt-web-service",
"version": "1.0.0",
"private": false,
"description": "ChatGPT Web Service",
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
"keywords": [
"chatgpt-web",
"chatgpt",
"chatbot",
"express"
],
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"start": "esno ./src/index.ts",
"prod": "esno ./build/index.js",
"build": "pnpm clean && tsup",
"clean": "rimraf build",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"dependencies": {
"chatgpt": "^4.3.2",
"express": "^4.18.2"
},
"devDependencies": {
"@antfu/eslint-config": "^0.35.2",
"@types/express": "^4.17.17",
"@types/node": "^18.13.0",
"dotenv": "^16.0.3",
"eslint": "^8.34.0",
"esno": "^0.16.3",
"rimraf": "^4.1.2",
"tsup": "^6.6.2",
"typescript": "^4.9.5"
}
}

3385
service/pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

45
service/src/chatgpt.ts Normal file
View File

@@ -0,0 +1,45 @@
import * as dotenv from 'dotenv'
import type { SendMessageOptions } from 'chatgpt'
import { ChatGPTAPI } from 'chatgpt'
import { sendResponse } from './utils'
export interface ChatContext {
conversationId?: string
parentMessageId?: string
}
dotenv.config()
const apiKey = process.env.OPENAI_API_KEY
if (apiKey === undefined)
throw new Error('OPENAI_API_KEY is not defined')
/**
* More Info: https://github.com/transitive-bullshit/chatgpt-api
*/
const api = new ChatGPTAPI({ apiKey, debug: false })
async function chatReply(
message: string,
lastContext?: { conversationId?: string; parentMessageId?: string },
) {
if (!message)
return sendResponse({ type: 'Fail', message: 'Message is empty' })
try {
let options: SendMessageOptions = {}
if (lastContext)
options = { ...lastContext }
const response = await api.sendMessage(message, { ...options })
return sendResponse({ type: 'Success', data: response })
}
catch (error: any) {
return sendResponse({ type: 'Fail', message: error.message })
}
}
export { chatReply }

27
service/src/index.ts Normal file
View File

@@ -0,0 +1,27 @@
import express from 'express'
import type { ChatContext } from './chatgpt'
import { chatReply } from './chatgpt'
const app = express()
app.use(express.json())
app.all('*', (_, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', 'Content-Type')
res.header('Access-Control-Allow-Methods', '*')
next()
})
app.post('/chat', async (req, res) => {
try {
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
const response = await chatReply(prompt, options)
res.send(response)
}
catch (error) {
res.send(error)
}
})
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))

View File

@@ -0,0 +1,22 @@
interface SendResponseOptions {
type: 'Success' | 'Fail'
message?: string
data?: any
}
export function sendResponse(options: SendResponseOptions) {
if (options.type === 'Success') {
return Promise.resolve({
message: options.message ?? null,
data: options.data ?? null,
status: options.type,
})
}
// eslint-disable-next-line prefer-promise-reject-errors
return Promise.reject({
message: options.message ?? 'Failed',
data: options.data ?? null,
status: options.type,
})
}

27
service/tsconfig.json Normal file
View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "es2020",
"lib": [
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"baseUrl": ".",
"outDir": "build",
"noEmit": true
},
"exclude": [
"node_modules",
"build"
],
"include": [
"**/*.ts"
]
}

13
service/tsup.config.ts Normal file
View File

@@ -0,0 +1,13 @@
import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/index.ts'],
outDir: 'build',
target: 'es2020',
format: ['cjs'],
splitting: false,
sourcemap: true,
minify: false,
shims: true,
dts: false,
})

View File

@@ -1,13 +1,12 @@
<script setup lang="ts">
import { GithubSite, NaiveProvider } from '@/components'
import Chat from '@/views/Chat/index.vue'
import { NConfigProvider } from 'naive-ui'
import { NaiveProvider } from '@/components/common'
</script>
<template>
<NaiveProvider>
<div class="h-full overflow-hidden pb-[50px] p-4">
<Chat />
<GithubSite />
</div>
</NaiveProvider>
<NConfigProvider class="h-full">
<NaiveProvider>
<RouterView />
</NaiveProvider>
</NConfigProvider>
</template>

17
src/api/index.ts Normal file
View File

@@ -0,0 +1,17 @@
import { post } from '@/utils/request'
export function fetchChatAPI<T = any>(
prompt: string,
options?: { conversationId?: string; parentMessageId?: string },
) {
return post<T>({
url: '/chat',
data: { prompt, options },
})
}
export function clearConversations<T = any>() {
return post<T>({
url: '/clear',
})
}

View File

@@ -1,10 +0,0 @@
<template>
<div class="fixed bottom-0 left-0 right-0 p-4 text-sm text-center text-neutral-500">
<span class="text-center">
Made By ChenZhaoYu -
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
Github
</a>
</span>
</div>
</template>

View File

@@ -1,27 +0,0 @@
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import { NConfigProvider, NMessageProvider, useMessage } from 'naive-ui'
function registerNaiveTools() {
window.$message = useMessage()
}
const NaiveProviderContent = defineComponent({
name: 'NaiveProviderContent',
setup() {
registerNaiveTools()
},
render() {
return h('div')
},
})
</script>
<template>
<NConfigProvider class="h-full">
<NMessageProvider>
<slot />
<NaiveProviderContent />
</NMessageProvider>
</NConfigProvider>
</template>

View File

@@ -0,0 +1,16 @@
<script lang="ts" setup>
interface Props {
reversal?: boolean
error?: boolean
}
defineProps<Props>()
</script>
<template>
<div class="p-2 mt-2 rounded-md" :class="[reversal ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]']">
<span class="leading-relaxed whitespace-pre-wrap" :class="[{ 'text-red-500': error }]">
<slot />
</span>
</div>
</template>

View File

@@ -6,6 +6,7 @@ interface Props {
message?: string
dateTime?: string
reversal?: boolean
error?: boolean
}
defineProps<Props>()
@@ -19,13 +20,13 @@ defineProps<Props>()
>
<Avatar :image="reversal" />
</div>
<div class="flex flex-col flex-1 text-sm" :class="[{ 'items-end': reversal }]">
<div class="flex flex-col flex-1 text-sm" :class="[reversal ? 'items-end' : 'items-start']">
<span class="text-xs text-[#b4bbc4]">
{{ dateTime }}
</span>
<div class="p-2 mt-2 rounded-md" :class="[reversal ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]']">
<Text>{{ message }}</Text>
</div>
<Text :reversal="reversal" :error="error">
{{ message }}
</Text>
</div>
</div>
</template>

View File

@@ -0,0 +1,114 @@
<script setup lang='ts'>
import { computed, nextTick, onMounted, ref } from 'vue'
import { NButton, NInput, useMessage } from 'naive-ui'
import type { ChatOptions, ChatProps } from './types'
import { Message } from './components'
import { Layout } from './layout'
import { fetchChatAPI } from '@/api'
import { HoverButton, SvgIcon } from '@/components/common'
const scrollRef = ref<HTMLDivElement>()
const ms = useMessage()
const prompt = ref('')
const loading = ref(false)
const list = ref<ChatProps[]>([])
const chatList = computed(() => list.value.filter(item => (!item.reversal && !item.error)))
function initChat() {
addMessage('Hi, I am ChatGPT, a chatbot based on GPT-3.')
}
onMounted(initChat)
async function handleSubmit() {
if (loading.value)
return
const message = prompt.value.trim()
if (!message || !message.length) {
ms.warning('Please enter a message')
return
}
addMessage(message, { reversal: true })
prompt.value = ''
let options: ChatOptions = {}
const lastContext = chatList.value[chatList.value.length - 1]?.options
if (lastContext)
options = { ...lastContext }
try {
loading.value = true
const { data } = await fetchChatAPI(message, options)
addMessage(data?.text ?? '', { options: { conversationId: data.conversationId, parentMessageId: data.id } })
}
catch (error: any) {
addMessage(`Error: ${error.message ?? 'Request failed, please try again later.'}`, { error: true })
}
finally {
loading.value = false
}
}
function handleEnter(event: KeyboardEvent) {
if (event.key === 'Enter')
handleSubmit()
}
function addMessage(
message: string,
args?: { reversal?: boolean; error?: boolean; options?: ChatOptions },
) {
list.value.push({
dateTime: new Date().toLocaleString(),
message,
reversal: args?.reversal ?? false,
error: args?.error ?? false,
options: args?.options ?? undefined,
})
nextTick(() => scrollRef.value && (scrollRef.value.scrollTop = scrollRef.value.scrollHeight))
}
function handleClear() {
list.value = []
setTimeout(initChat, 100)
}
</script>
<template>
<Layout>
<div class="flex flex-col h-full">
<main class="flex-1 overflow-hidden">
<div ref="scrollRef" class="h-full p-4 overflow-hidden overflow-y-auto">
<div>
<Message
v-for="(item, index) of list" :key="index" :date-time="item.dateTime" :message="item.message"
:reversal="item.reversal" :error="item.error"
/>
</div>
</div>
</main>
<footer class="p-4">
<div class="flex items-center justify-between space-x-2">
<HoverButton tooltip="Clear conversations" @click="handleClear">
<span class="text-xl text-[#4f555e]">
<SvgIcon icon="ri:delete-bin-line" />
</span>
</HoverButton>
<NInput v-model:value="prompt" placeholder="Type a message..." @keypress="handleEnter" />
<NButton type="primary" :loading="loading" @click="handleSubmit">
<template #icon>
<SvgIcon icon="ri:send-plane-fill" />
</template>
</NButton>
</div>
</footer>
</div>
</Layout>
</template>

View File

@@ -0,0 +1,19 @@
<script setup lang='ts'>
import { NLayout, NLayoutContent } from 'naive-ui'
import Sider from './sider/index.vue'
</script>
<template>
<div class="h-full overflow-hidden border rounded-md shadow-md min-w-[640px]">
<NLayout class="h-full" has-sider>
<Sider />
<NLayoutContent class="h-full">
<slot />
</NLayoutContent>
</NLayout>
</div>
</template>
<style>
</style>

View File

@@ -0,0 +1,3 @@
import Layout from './Layout.vue'
export { Layout }

View File

@@ -0,0 +1,15 @@
<script setup lang='ts'>
import { HoverButton, SvgIcon, UserAvatar } from '@/components/common'
</script>
<template>
<footer class="flex items-center justify-between p-4 overflow-hidden border-t">
<UserAvatar />
<HoverButton tooltip="Setting">
<span class="text-xl text-[#4f555e]">
<SvgIcon icon="ri:settings-4-line" />
</span>
</HoverButton>
</footer>
</template>

View File

@@ -0,0 +1,14 @@
<script setup lang='ts'>
import { NScrollbar } from 'naive-ui'
import ListItem from './ListItem.vue'
</script>
<template>
<NScrollbar class="px-4">
<div class="flex flex-col gap-2 text-sm">
<ListItem text="Learning correlation" />
<ListItem text="Write Code" />
<ListItem text="docs..." />
</div>
</NScrollbar>
</template>

View File

@@ -0,0 +1,52 @@
<script setup lang='ts'>
import { SvgIcon } from '@/components/common'
interface Props {
text: string
}
interface Emit {
(e: 'click',): void
(e: 'edit',): void
(e: 'delete',): void
}
defineProps<Props>()
const emit = defineEmits<Emit>()
function handleClick(event: Event) {
emit('click')
event.preventDefault()
}
function handleEdit() {
emit('edit')
}
function handleDelete() {
emit('delete')
}
</script>
<template>
<a
class="relative flex items-center gap-3 px-3 py-3 break-all rounded-md cursor-pointer bg-neutral-50 pr-14 hover:bg-neutral-100 group"
@click="handleClick"
>
<span>
<SvgIcon icon="ri:message-3-line" />
</span>
<div class="relative flex-1 overflow-hidden break-all text-ellipsis whitespace-nowrap max-h-5">
<span>{{ text }}</span>
</div>
<div class="absolute z-10 flex visible right-1">
<button class="p-1" @click="handleEdit">
<SvgIcon icon="ri:edit-line" />
</button>
<button class="p-1" @click="handleDelete">
<SvgIcon icon="ri:delete-bin-line" />
</button>
</div>
</a>
</template>

View File

@@ -0,0 +1,65 @@
<script setup lang='ts'>
import { ref, watch } from 'vue'
import { NButton, NLayoutSider, useMessage } from 'naive-ui'
import List from './List.vue'
import Footer from './Footer.vue'
interface Props {
collapsed?: boolean
}
interface Emit {
(e: 'update:collapsed', value: boolean): void
}
const props = withDefaults(defineProps<Props>(), {
collapsed: false,
})
const emit = defineEmits<Emit>()
const ms = useMessage()
const collapsed = ref(props.collapsed)
watch(
() => props.collapsed,
(value: boolean) => {
collapsed.value = value
},
{ immediate: true },
)
function handleAdd() {
ms.info('Coming soon...')
}
function handleCollapsed() {
collapsed.value = !collapsed.value
emit('update:collapsed', collapsed.value)
}
</script>
<template>
<NLayoutSider
:collapsed="collapsed"
:collapsed-width="0"
:width="260"
collapse-mode="width"
show-trigger="arrow-circle"
bordered
@update:collapsed="handleCollapsed"
>
<div class="flex flex-col h-full">
<main class="flex-1 min-h-0 overflow-hidden">
<div class="p-4">
<NButton dashed block @click="handleAdd">
New chat
</NButton>
</div>
<List />
</main>
<Footer />
</div>
</NLayoutSider>
</template>

View File

@@ -0,0 +1,12 @@
export interface ChatOptions {
conversationId?: string
parentMessageId?: string
}
export interface ChatProps {
dateTime: string
message: string
reversal?: boolean
error?: boolean
options?: ChatOptions
}

View File

@@ -0,0 +1,3 @@
import Chat from './Chat/index.vue'
export { Chat }

View File

@@ -0,0 +1,20 @@
<script setup lang='ts'>
interface Emit {
(e: 'click'): void
}
const emit = defineEmits<Emit>()
function handleClick() {
emit('click')
}
</script>
<template>
<button
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100"
@click="handleClick"
>
<slot />
</button>
</template>

View File

@@ -0,0 +1,46 @@
<script setup lang='ts'>
import { computed } from 'vue'
import type { PopoverPlacement } from 'naive-ui'
import { NTooltip } from 'naive-ui'
import Button from './Button.vue'
interface Props {
tooltip?: string
placement?: PopoverPlacement
}
interface Emit {
(e: 'click'): void
}
const props = withDefaults(defineProps<Props>(), {
tooltip: '',
placement: 'bottom',
})
const emit = defineEmits<Emit>()
const showTooltip = computed(() => Boolean(props.tooltip))
function handleClick() {
emit('click')
}
</script>
<template>
<div v-if="showTooltip">
<NTooltip :placement="placement" trigger="hover">
<template #trigger>
<Button @click="handleClick">
<slot />
</Button>
</template>
{{ tooltip }}
</NTooltip>
</div>
<div v-else>
<Button @click="handleClick">
<slot />
</Button>
</div>
</template>

View File

@@ -0,0 +1,43 @@
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import {
NDialogProvider,
NLoadingBarProvider,
NMessageProvider,
NNotificationProvider,
useDialog,
useLoadingBar,
useMessage,
useNotification,
} from 'naive-ui'
function registerNaiveTools() {
window.$loadingBar = useLoadingBar()
window.$dialog = useDialog()
window.$message = useMessage()
window.$notification = useNotification()
}
const NaiveProviderContent = defineComponent({
name: 'NaiveProviderContent',
setup() {
registerNaiveTools()
},
render() {
return h('div')
},
})
</script>
<template>
<NLoadingBarProvider>
<NDialogProvider>
<NNotificationProvider>
<NMessageProvider>
<slot />
<NaiveProviderContent />
</NMessageProvider>
</NNotificationProvider>
</NDialogProvider>
</NLoadingBarProvider>
</template>

View File

@@ -0,0 +1,23 @@
<script setup lang='ts'>
import { GithubSite } from '@/components/custom'
</script>
<template>
<div class="flex items-center">
<div class="w-10 h-10 overflow-hidden rounded-full">
<img class="object-cover" src="@/assets/avatar.jpg" alt="avatar">
</div>
<div class="ml-2">
<h2 class="font-bold text-md">
ChenZhaoYu
</h2>
<p class="text-xs text-gray-500">
<GithubSite />
</p>
</div>
</div>
</template>
<style>
</style>

View File

@@ -0,0 +1,6 @@
import HoverButton from './HoverButton/index.vue'
import NaiveProvider from './NaiveProvider/index.vue'
import SvgIcon from './SvgIcon/index.vue'
import UserAvatar from './UserAvatar/index.vue'
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar }

View File

@@ -0,0 +1,8 @@
<template>
<div class="text-center text-neutral-500">
<span> Star on</span>
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
GitHub
</a>
</div>
</template>

View File

@@ -0,0 +1,3 @@
import GithubSite from './GithubSite.vue'
export { GithubSite }

View File

@@ -1,5 +0,0 @@
import NaiveProvider from './NaiveProvider.vue'
import Icon from './Icon.vue'
import GithubSite from './GithubSite.vue'
export { NaiveProvider, Icon, GithubSite }

View File

@@ -1,6 +1,8 @@
import './styles/global.css'
import { createApp } from 'vue'
import App from './App.vue'
import './styles/global.css'
import { setupRouter } from '@/router'
/** Tailwind's Preflight Style Override */
function naiveStyleOverride() {
@@ -10,9 +12,10 @@ function naiveStyleOverride() {
}
/** Setup */
function bootstrap() {
async function bootstrap() {
const app = createApp(App)
naiveStyleOverride()
await setupRouter(app)
app.mount('#app')
}

22
src/router/index.ts Normal file
View File

@@ -0,0 +1,22 @@
import type { App } from 'vue'
import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHashHistory } from 'vue-router'
const routes: RouteRecordRaw[] = [
{
path: '/',
name: 'Home',
component: () => import('@/views/home/index.vue'),
},
]
export const router = createRouter({
history: createWebHashHistory(),
routes,
scrollBehavior: () => ({ left: 0, top: 0 }),
})
export async function setupRouter(app: App) {
app.use(router)
await router.isReady()
}

View File

@@ -1,3 +1,6 @@
interface Window {
$loadingBar?: import('naive-ui').LoadingBarProviderInst;
$dialog?: import('naive-ui').DialogProviderInst;
$message?: import('naive-ui').MessageProviderInst;
$notification?: import('naive-ui').NotificationProviderInst;
}

View File

@@ -0,0 +1,29 @@
import axios, { type AxiosResponse } from 'axios'
const service = axios.create({
baseURL: import.meta.env.VITE_GLOB_API_URL,
timeout: 10 * 1000,
})
service.interceptors.request.use(
(config) => {
return config
},
(error) => {
return Promise.reject(error.response)
},
)
service.interceptors.response.use(
(response: AxiosResponse): AxiosResponse => {
if (response.status === 200)
return response
throw new Error(response.status.toString())
},
(error) => {
return Promise.reject(error)
},
)
export default service

View File

@@ -0,0 +1,72 @@
import type { AxiosResponse } from 'axios'
import request from './axios'
export interface HttpOption {
url: string
data?: any
method?: string
headers?: any
beforeRequest?: () => void
afterRequest?: () => void
}
export interface ExtraOption {
notification?: boolean
}
export interface Response<T = any> {
data: T
message: string | null
status: string
}
function http<T = any>({ url, data, method, headers, beforeRequest, afterRequest }: HttpOption) {
const successHandler = (res: AxiosResponse<Response<T>>) => {
if (res.data.status === 'Success')
return res.data
return Promise.reject(res.data)
}
const failHandler = (error: Response<Error>) => {
afterRequest?.()
throw new Error(error?.message || 'Error')
}
beforeRequest?.()
method = method || 'GET'
const params = Object.assign(typeof data === 'function' ? data() : data ?? {}, {})
return method === 'GET'
? request.get(url, { params }).then(successHandler, failHandler)
: request.post(url, params, { headers }).then(successHandler, failHandler)
}
export function get<T = any>(
{ url, data, method = 'GET', beforeRequest, afterRequest }: HttpOption,
): Promise<Response<T>> {
return http<T>({
url,
method,
data,
beforeRequest,
afterRequest,
})
}
export function post<T = any>(
{ url, data, method = 'POST', headers, beforeRequest, afterRequest }: HttpOption,
): Promise<Response<T>> {
return http<T>({
url,
method,
data,
headers,
beforeRequest,
afterRequest,
})
}
export default post

View File

@@ -1,34 +0,0 @@
<script setup lang='ts'>
import { Icon } from '@/components'
interface Props {
user?: boolean
date?: string
message?: string
error?: boolean
}
defineProps<Props>()
</script>
<template>
<div class="flex w-full mb-6" :class="[{ 'flex-row-reverse': user }]">
<div
class="flex items-center justify-center rounded-full overflow-hidden w-[32px] h-[32px]"
:class="[user ? 'ml-3' : 'mr-3']"
>
<img v-if="user" src="@/assets/avatar.jpg" class="object-cover w-full h-full " alt="avatar">
<Icon v-else local-icon="logo" class="text-[26px]" />
</div>
<div class="flex flex-col flex-1 text-sm" :class="[{ 'items-end': user }]">
<span class="text-xs text-[#b4bbc4]">
{{ date }}
</span>
<div class="p-2 mt-2 rounded-md" :class="[user ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]']">
<span class="leading-relaxed whitespace-pre" :class="[{ 'text-red-500': error }]">
{{ message }}
</span>
</div>
</div>
</div>
</template>

View File

@@ -1,5 +0,0 @@
<template>
<span class="leading-relaxed whitespace-pre-wrap">
<slot />
</span>
</template>

View File

@@ -1,109 +0,0 @@
<script setup lang='ts'>
import { nextTick, onMounted, ref } from 'vue'
import { NButton, NInput, NPopover, useMessage } from 'naive-ui'
import { Message } from './components'
import { fetchChatAPI } from './request'
import { Icon } from '@/components'
interface ListProps {
dateTime: string
message: string
reversal?: boolean
}
const scrollRef = ref<HTMLDivElement>()
const ms = useMessage()
const value = ref('')
const loading = ref(false)
const list = ref<ListProps[]>([])
onMounted(initChat)
function initChat() {
addMessage('Hi, I am ChatGPT, a chatbot based on GPT-3.', false)
}
function handleClear() {
list.value = []
setTimeout(initChat, 100)
}
function handleEnter(event: KeyboardEvent) {
if (event.key === 'Enter')
handleSubmit()
}
async function handleSubmit() {
if (!value.value) {
ms.warning('Please enter a message')
return
}
addMessage(value.value, true)
try {
loading.value = true
const { text } = await fetchChatAPI(value.value)
value.value = ''
addMessage(text, false)
}
catch (error: any) {
addMessage(error.message ?? 'Request failed, please try again later.', false)
}
finally {
loading.value = false
}
}
function addMessage(message: string, reversal = false) {
list.value.push({ dateTime: new Date().toLocaleString(), message, reversal })
nextTick(() => scrollRef.value && (scrollRef.value.scrollTop = scrollRef.value.scrollHeight))
}
</script>
<template>
<div class="flex flex-col h-full overflow-hidden border rounded-md shadow-md">
<header class="flex items-center justify-between p-4">
<h1 class="text-xl font-bold">
ChatGPT Web
</h1>
<div>
<NPopover>
<template #trigger>
<button
class="w-[40px] h-[40px] rounded-full hover:bg-neutral-100 transition flex justify-center items-center"
@click="handleClear"
>
<Icon icon="ri:delete-bin-6-line" />
</button>
</template>
<span>Clear</span>
</NPopover>
</div>
</header>
<main class="flex-1 overflow-hidden border-y">
<div ref="scrollRef" class="h-full p-4 overflow-hidden overflow-y-auto">
<div>
<Message
v-for="(item, index) of list" :key="index" :date-time="item.dateTime" :message="item.message"
:reversal="item.reversal"
/>
</div>
</div>
</main>
<footer class="p-4">
<div class="flex items-center justify-between space-x-2">
<NInput v-model:value="value" :disabled="loading" placeholder="Type a message..." @keyup="handleEnter" />
<NButton type="primary" :loading="loading" @click="handleSubmit">
<template #icon>
<Icon icon="ri:send-plane-fill" />
</template>
</NButton>
</div>
</footer>
</div>
</template>

View File

@@ -1,27 +0,0 @@
import axios from 'axios'
async function fetchChatAPI(message: string) {
const url = `${import.meta.env.VITE_GLOB_API_URL}/chat`
if (!message || message.trim() === '')
return
try {
const { status, data } = await axios.post(url, { message })
if (status === 200) {
if (data.text)
return Promise.resolve(data)
if (data.statusText)
return Promise.reject(new Error(data.statusText))
}
return Promise.reject(new Error('Request failed'))
}
catch (error) {
return Promise.reject(error)
}
}
export { fetchChatAPI }

13
src/views/home/index.vue Normal file
View File

@@ -0,0 +1,13 @@
<script setup lang='ts'>
import { Chat } from '@/components/business'
</script>
<template>
<div class="h-full p-4 overflow-hidden">
<Chat />
</div>
</template>
<style>
</style>

View File

@@ -1,22 +1,22 @@
{
"compilerOptions": {
"baseUrl": ".",
"module": "ESNext",
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"moduleResolution": "node",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@/*": ["./src/*"]
},
"types": ["vite/client", "node", "naive-ui/volar"]
},
"exclude": ["node_modules", "dist"]
"compilerOptions": {
"baseUrl": ".",
"module": "ESNext",
"target": "ESNext",
"lib": ["DOM", "ESNext"],
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"moduleResolution": "node",
"resolveJsonModule": true,
"noUnusedLocals": true,
"strictNullChecks": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@/*": ["./src/*"]
},
"types": ["vite/client", "node", "naive-ui/volar"]
},
"exclude": ["node_modules", "dist", "service"]
}