mirror of
https://github.com/LLM-Red-Team/glm-free-api.git
synced 2024-12-22 17:09:22 +08:00
支持Render部署和Vercel部署方式
This commit is contained in:
parent
0e13700824
commit
32884af017
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
dist/
|
dist/
|
||||||
node_modules/
|
node_modules/
|
||||||
logs/
|
logs/
|
||||||
|
.vercel
|
||||||
|
35
README.md
35
README.md
@ -37,6 +37,8 @@ Moonshot AI(Kimi.ai)接口转API [kimi-free-api](https://github.com/LLM-Red-
|
|||||||
* [多账号接入](#多账号接入)
|
* [多账号接入](#多账号接入)
|
||||||
* [Docker部署](#Docker部署)
|
* [Docker部署](#Docker部署)
|
||||||
* [Docker-compose部署](#Docker-compose部署)
|
* [Docker-compose部署](#Docker-compose部署)
|
||||||
|
* [Render部署](#Render部署)
|
||||||
|
* [Vercel部署](#Vercel部署)
|
||||||
* [原生部署](#原生部署)
|
* [原生部署](#原生部署)
|
||||||
* [接口列表](#接口列表)
|
* [接口列表](#接口列表)
|
||||||
* [对话补全](#对话补全)
|
* [对话补全](#对话补全)
|
||||||
@ -61,6 +63,12 @@ Moonshot AI(Kimi.ai)接口转API [kimi-free-api](https://github.com/LLM-Red-
|
|||||||
|
|
||||||
https://udify.app/chat/Pe89TtaX3rKXM8NS
|
https://udify.app/chat/Pe89TtaX3rKXM8NS
|
||||||
|
|
||||||
|
## 测试接口
|
||||||
|
|
||||||
|
此接口实例部署在[Render](#Render部署)上面,遇到容器回收可能导致响应速度较慢,仅供测试,建议自行部署。
|
||||||
|
|
||||||
|
https://glm-free-api-ij4o.onrender.com
|
||||||
|
|
||||||
## 效果示例
|
## 效果示例
|
||||||
|
|
||||||
### 验明正身Demo
|
### 验明正身Demo
|
||||||
@ -163,6 +171,33 @@ services:
|
|||||||
- TZ=Asia/Shanghai
|
- TZ=Asia/Shanghai
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Render部署
|
||||||
|
|
||||||
|
**注意:部分部署区域可能无法连接glm,如容器日志出现请求超时或无法连接,请切换其他区域部署!**
|
||||||
|
**注意:免费账户的容器实例将在一段时间不活动时自动停止运行,这会导致下次请求时遇到50秒或更长的延迟,建议通过 GET `/ping` 请求来维持容器活动**
|
||||||
|
|
||||||
|
1. fork本项目到你的github账号下。
|
||||||
|
|
||||||
|
2. 访问 [Render](https://dashboard.render.com/) 并登录你的github账号。
|
||||||
|
|
||||||
|
3. 构建你的 Web Service(New+ -> Build and deploy from a Git repository -> Connect你fork的项目 -> 选择部署区域 -> 选择实例类型为Free -> Create Web Service)。
|
||||||
|
|
||||||
|
4. 等待构建完成后,复制分配的域名并拼接URL访问即可。
|
||||||
|
|
||||||
|
### Vercel部署
|
||||||
|
|
||||||
|
**注意:Vercel免费账户的请求响应超时时间为10秒,但接口响应通常较久,可能会遇到Vercel返回的504超时错误!**
|
||||||
|
|
||||||
|
请先确保安装了Node.js环境。
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm i -g vercel --registry http://registry.npmmirror.com
|
||||||
|
vercel login
|
||||||
|
git clone https://github.com/LLM-Red-Team/glm-free-api
|
||||||
|
cd glm-free-api
|
||||||
|
vercel --prod
|
||||||
|
```
|
||||||
|
|
||||||
## 原生部署
|
## 原生部署
|
||||||
|
|
||||||
请准备一台具有公网IP的服务器并将8000端口开放。
|
请准备一台具有公网IP的服务器并将8000端口开放。
|
||||||
|
@ -9,13 +9,15 @@ import { format as dateFormat } from 'date-fns';
|
|||||||
import config from './config.ts';
|
import config from './config.ts';
|
||||||
import util from './util.ts';
|
import util from './util.ts';
|
||||||
|
|
||||||
|
const isVercelEnv = process.env.VERCEL;
|
||||||
|
|
||||||
class LogWriter {
|
class LogWriter {
|
||||||
|
|
||||||
#buffers = [];
|
#buffers = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
fs.ensureDirSync(config.system.logDirPath);
|
!isVercelEnv && fs.ensureDirSync(config.system.logDirPath);
|
||||||
this.work();
|
!isVercelEnv && this.work();
|
||||||
}
|
}
|
||||||
|
|
||||||
push(content) {
|
push(content) {
|
||||||
@ -24,16 +26,16 @@ class LogWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeSync(buffer) {
|
writeSync(buffer) {
|
||||||
fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
!isVercelEnv && fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
async write(buffer) {
|
async write(buffer) {
|
||||||
await fs.appendFile(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
!isVercelEnv && await fs.appendFile(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
flush() {
|
flush() {
|
||||||
if(!this.#buffers.length) return;
|
if(!this.#buffers.length) return;
|
||||||
fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), Buffer.concat(this.#buffers));
|
!isVercelEnv && fs.appendFileSync(path.join(config.system.logDirPath, `/${util.getDateString()}.log`), Buffer.concat(this.#buffers));
|
||||||
}
|
}
|
||||||
|
|
||||||
work() {
|
work() {
|
||||||
|
27
vercel.json
Normal file
27
vercel.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"src": "./dist/*.html",
|
||||||
|
"use": "@vercel/static"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "./dist/index.js",
|
||||||
|
"use": "@vercel/node"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"src": "/",
|
||||||
|
"dest": "/dist/welcome.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"src": "/(.*)",
|
||||||
|
"dest": "/dist",
|
||||||
|
"headers": {
|
||||||
|
"Access-Control-Allow-Credentials": "true",
|
||||||
|
"Access-Control-Allow-Methods": "GET,OPTIONS,PATCH,DELETE,POST,PUT",
|
||||||
|
"Access-Control-Allow-Headers": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, Content-Type, Authorization"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user