Compare commits

...

4 Commits

Author SHA1 Message Date
ChenZhaoYu
c0f8e4316e chore: version 2.6.1 2023-02-22 14:43:55 +08:00
Redon
bf5c0cdf04 fix: 手动打包 Proxy 问题(#91)
* perf: 检查代码

* feat: proxy setting

* chore: 调整为测试环境使用 `proxy`
2023-02-22 14:29:05 +08:00
Redon
66cecb6049 Update README.md 2023-02-22 10:40:26 +08:00
闫冰
808ae600c2 chore: 新增 Railway 部署模版! (#85)
* 新增使用 Railway 免费 一键部署模版!

* 修改描述

* 修改模版的必填项以及新增超时时间参数

* 移除推广code

* Update README.md

---------

Co-authored-by: Redon <790348264@qq.com>
2023-02-22 10:36:11 +08:00
11 changed files with 91 additions and 28 deletions

5
.env
View File

@@ -1,6 +1,5 @@
# Glob API URL
VITE_GLOB_API_URL=/api
VITE_APP_API_BASE_URL=http://localhost:3002/
VITE_GLOB_API_URL=http://localhost:3002
# Glob API Timeout (ms)
VITE_GLOB_API_TIMEOUT=100000

1
.env.development Normal file
View File

@@ -0,0 +1 @@
VITE_GLOB_HTTP_PROXY=Y

View File

@@ -1,3 +1,13 @@
## v2.6.1
`2023-02-22`
### Feature
- 新增 `Railway` 部署模版
### BugFix
- 手动打包 `Proxy` 问题
## v2.6.0
`2023-02-21`

View File

@@ -1,10 +1,36 @@
# ChatGPT Web
使用 `express``vue3` 搭建的支持 `ChatGPT` 双模型演示网页
> 使用 `express` 和 `vue3` 搭建的支持 `ChatGPT` 双模型演示网页
![cover](./docs/cover.png)
![cover2](./docs/cover2.png)
- [ChatGPT Web](#chatgpt-web)
- [介绍](#介绍)
- [待实现路线](#待实现路线)
- [前置要求](#前置要求)
- [Node](#node)
- [PNPM](#pnpm)
- [填写密钥](#填写密钥)
- [安装依赖](#安装依赖)
- [后端](#后端)
- [前端](#前端)
- [测试环境运行](#测试环境运行)
- [后端服务](#后端服务)
- [前端网页](#前端网页)
- [打包](#打包)
- [使用 Docker](#使用-docker)
- [Docker 参数示例](#docker-参数示例)
- [Docker build \& Run](#docker-build--run)
- [Docker compose](#docker-compose)
- [使用 Railway 部署](#使用-railway-部署)
- [Railway 环境变量](#railway-环境变量)
- [手动打包](#手动打包)
- [后端服务](#后端服务-1)
- [前端网页](#前端网页-1)
- [常见问题](#常见问题)
- [参与贡献](#参与贡献)
- [License](#license)
## 介绍
支持双模型,提供了两种非官方 `ChatGPT API` 方法
@@ -52,7 +78,7 @@ API_REVERSE_PROXY=
### Node
`node` 需要 `^16 || ^18` 版本(或者 `node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
`node` 需要 `^16 || ^18` 版本(`node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
```shell
node -v
@@ -81,7 +107,7 @@ OPENAI_ACCESS_TOKEN=
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
### 后端服务
### 后端
进入文件夹 `/service` 运行以下命令
@@ -89,7 +115,7 @@ OPENAI_ACCESS_TOKEN=
pnpm install
```
### 网页
### 前端
根目录下运行以下命令
```shell
pnpm bootstrap
@@ -114,7 +140,7 @@ pnpm dev
### 使用 Docker
### Docker 参数示例
#### Docker 参数示例
- `OPENAI_API_KEY` 二选一
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
@@ -123,7 +149,7 @@ pnpm dev
![docker](./docs/docker.png)
### Docker build & Run
#### Docker build & Run
```bash
docker build -t chatgpt-web .
@@ -138,7 +164,7 @@ docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key
http://localhost:3002/
```
### Docker compose
#### Docker compose
[Hub 地址](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
@@ -161,9 +187,24 @@ services:
TIMEOUT_MS: 60000
```
### 使用 Railway 部署
## 手动打包
### 后端服务
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc)
#### Railway 环境变量
| 环境变量名称 | 必填 | 备注 |
| --------------------------- | ---- | ----------------------- |
| `PORT` | 必填 | 默认 `3002` |
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒, |
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
| `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) |
> 注意: `Railway` 修改环境变量会重新 `Deploy`
### 手动打包
#### 后端服务
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。
@@ -181,7 +222,7 @@ pnpm prod
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
### 前端网页
#### 前端网页
1、修改根目录下 `.env``VITE_APP_API_BASE_URL` 为你的实际后端接口地址
@@ -193,7 +234,7 @@ PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
pnpm build
```
### 常见问题
## 常见问题
Q: 为什么 `Git` 提交总是报错?
A: 因为有提交信息验证,请遵循 [Commit 指南](./CONTRIBUTING.md)

1
config/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from './proxy'

16
config/proxy.ts Normal file
View File

@@ -0,0 +1,16 @@
import type { ProxyOptions } from 'vite'
export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) {
if (!isOpenProxy)
return
const proxy: Record<string, string | ProxyOptions> = {
'/api': {
target: viteEnv.VITE_GLOB_API_URL,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
},
}
return proxy
}

View File

@@ -1,6 +1,6 @@
{
"name": "chatgpt-web",
"version": "2.6.0",
"version": "2.6.1",
"private": false,
"description": "ChatGPT Web",
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",

View File

@@ -3,5 +3,5 @@
interface ImportMetaEnv {
readonly VITE_GLOB_API_URL: string;
readonly VITE_GLOB_API_TIMEOUT: string;
readonly VITE_APP_API_BASE_URL: string;
readonly VITE_GLOB_HTTP_PROXY: 'Y' | 'N';
}

View File

@@ -1,8 +1,6 @@
function includeCode(text: string | null | undefined) {
const regexp = /^(?:\s{4}|\t).+/gm
if (text?.includes(' = ') || text?.match(regexp))
return true
return false
return !!(text?.includes(' = ') || text?.match(regexp))
}
export default includeCode

View File

@@ -1,7 +1,7 @@
import axios, { type AxiosResponse } from 'axios'
const service = axios.create({
baseURL: import.meta.env.VITE_GLOB_API_URL,
baseURL: import.meta.env.VITE_GLOB_HTTP_PROXY === 'Y' ? '/api' : import.meta.env.VITE_GLOB_API_URL,
timeout: !isNaN(+import.meta.env.VITE_GLOB_API_TIMEOUT) ? Number(import.meta.env.VITE_GLOB_API_TIMEOUT) : 60 * 1000,
})

View File

@@ -1,10 +1,13 @@
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createViteProxy } from './config'
export default defineConfig((env) => {
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
const isOpenProxy = viteEnv.VITE_GLOB_HTTP_PROXY === 'Y'
return {
resolve: {
alias: {
@@ -13,16 +16,10 @@ export default defineConfig((env) => {
},
plugins: [vue()],
server: {
port: 1002,
host: '0.0.0.0',
port: 1002,
open: false,
proxy: {
'/api': {
target: viteEnv.VITE_APP_API_BASE_URL,
changeOrigin: true, // 允许跨域
rewrite: path => path.replace('/api/', '/'),
},
},
proxy: createViteProxy(isOpenProxy, viteEnv),
},
build: {
reportCompressedSize: false,