Skip to content

Commit

Permalink
feat: openai base url
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Apr 25, 2023
1 parent ce68791 commit fb08f61
Show file tree
Hide file tree
Showing 21 changed files with 47 additions and 385 deletions.
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# proxy
AXIOS_PROXY_HOST=127.0.0.1
AXIOS_PROXY_PORT_FAST=7890
AXIOS_PROXY_PORT_NORMAL=7890
AXIOS_PROXY_PORT=7890
queueTask=1
parentUrl=https://hostname/api/openapi/startEvents
# email
Expand All @@ -16,6 +15,7 @@ aliTemplateCode=SMS_xxx
TOKEN_KEY=xxx
# openai
OPENAIKEY=sk-xxx
OPENAI_BASE_URL=https://api.openai.com/v1
# db
MONGODB_URI=mongodb://username:[email protected]:27017/test?authSource=admin
PG_HOST=0.0.0.0
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Fast GPT 允许你使用自己的 openai API KEY 来快速的调用 openai 接
```bash
# proxy(不需要代理可忽略)
AXIOS_PROXY_HOST=127.0.0.1
AXIOS_PROXY_PORT_FAST=7890
AXIOS_PROXY_PORT_NORMAL=7890
AXIOS_PROXY_PORT=7890
# 中转方案,修改 openai 的 base url
OPENAI_BASE_URL=https://api.openai.com/v1
# 是否开启队列任务。 1-开启,0-关闭(请求parentUrl去执行任务,单机时直接填1)
queueTask=1
parentUrl=https://hostname/api/openapi/startEvents
# email,参考 nodeMail 获取参数
Expand Down Expand Up @@ -181,32 +183,24 @@ services:
restart: always
container_name: fast-gpt
environment:
# 代理(不需要代理,可去掉下面三个参数)
- AXIOS_PROXY_HOST=127.0.0.1
- AXIOS_PROXY_PORT_FAST=7890
- AXIOS_PROXY_PORT_NORMAL=7890
# 邮箱
- AXIOS_PROXY_PORT=7890
- [email protected]
- MAILE_CODE=xxxx
# 阿里云短信
- aliAccessKeyId=xxxx
- aliAccessKeySecret=xxxx
- aliSignName=xxxxx
- aliTemplateCode=SMS_xxxx
# 登录 key
- TOKEN_KEY=xxxx
# 是否开启队列任务。 1-开启,0-关闭(请求parentUrl去执行任务,单机时直接填1)
- queueTask=1
- parentUrl=https://hostname/api/openapi/startEvents
# db
- MONGODB_URI=mongodb://username:[email protected]:27017/?authSource=admin
- MONGODB_NAME=xxx
- PG_HOST=0.0.0.0
- PG_PORT=8100
- PG_USER=xxx
- PG_PASSWORD=xxx
- PG_DB_NAME=xxx
# openai 账号
- OPENAIKEY=sk-xxxxx
nginx:
image: nginx:alpine3.17
Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/chat/chatGpt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { connectToDatabase } from '@/service/mongo';
import { getOpenAIApi, authChat } from '@/service/utils/auth';
import { httpsAgent, openaiChatFilter } from '@/service/utils/tools';
import { axiosConfig, openaiChatFilter } from '@/service/utils/tools';
import { ChatItemType } from '@/types/chat';
import { jsonRes } from '@/service/response';
import { PassThrough } from 'stream';
Expand Down Expand Up @@ -88,7 +88,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{
timeout: 40000,
responseType: 'stream',
httpsAgent: httpsAgent(!userApiKey)
...axiosConfig
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/chat/vectorGpt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { connectToDatabase } from '@/service/mongo';
import { authChat } from '@/service/utils/auth';
import { httpsAgent, systemPromptFilter, openaiChatFilter } from '@/service/utils/tools';
import { axiosConfig, systemPromptFilter, openaiChatFilter } from '@/service/utils/tools';
import { ChatItemType } from '@/types/chat';
import { jsonRes } from '@/service/response';
import { PassThrough } from 'stream';
Expand Down Expand Up @@ -150,7 +150,7 @@ ${
{
timeout: 40000,
responseType: 'stream',
httpsAgent: httpsAgent(!userApiKey)
...axiosConfig
}
);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/api/model/data/fetchingUrlData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { jsonRes } from '@/service/response';
import { connectToDatabase } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import axios from 'axios';
import { httpsAgent } from '@/service/utils/tools';
import { axiosConfig } from '@/service/utils/tools';

/**
* 读取网站的内容
Expand All @@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)

const data = await axios
.get(url, {
httpsAgent: httpsAgent(false)
httpsAgent: axiosConfig.httpsAgent
})
.then((res) => res.data as string);

Expand Down
31 changes: 1 addition & 30 deletions src/pages/api/model/del.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { Chat, Model, Training, connectToDatabase } from '@/service/mongo';
import { Chat, Model, connectToDatabase } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import { getUserApiOpenai } from '@/service/utils/openai';
import { TrainingStatusEnum } from '@/constants/model';
import { TrainingItemType } from '@/types/training';
import { httpsAgent } from '@/service/utils/tools';
import { PgClient } from '@/service/pg';

/* 获取我的模型 */
Expand Down Expand Up @@ -47,31 +43,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
modelId
});

// 查看是否正在训练
const training: TrainingItemType | null = await Training.findOne({
modelId,
status: TrainingStatusEnum.pending
});

// 如果正在训练,需要删除openai上的相关信息
if (training) {
const { openai } = await getUserApiOpenai(userId);
// 获取训练记录
const tuneRecord = await openai.retrieveFineTune(training.tuneId, {
httpsAgent: httpsAgent(false)
});

// 删除训练文件
openai.deleteFile(tuneRecord.data.training_files[0].id, { httpsAgent: httpsAgent(false) });
// 取消训练
openai.cancelFineTune(training.tuneId, { httpsAgent: httpsAgent(false) });
}

// 删除对应训练记录
await Training.deleteMany({
modelId
});

// 删除模型
await Model.deleteOne({
_id: modelId,
Expand Down
52 changes: 0 additions & 52 deletions src/pages/api/model/train/getTrainings.ts

This file was deleted.

106 changes: 0 additions & 106 deletions src/pages/api/model/train/putTrainStatus.ts

This file was deleted.

Loading

0 comments on commit fb08f61

Please sign in to comment.