mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 00:17:31 +00:00
perf: 专线代理配置
This commit is contained in:
@@ -96,7 +96,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
{
|
||||
timeout: 40000,
|
||||
responseType: 'stream',
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(!userApiKey)
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -141,7 +141,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
{
|
||||
timeout: 40000,
|
||||
responseType: 'stream',
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(!userApiKey)
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
const data = await axios
|
||||
.get(url, {
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(false)
|
||||
})
|
||||
.then((res) => res.data as string);
|
||||
|
||||
|
@@ -68,12 +68,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
if (training) {
|
||||
const { openai } = await getUserApiOpenai(userId);
|
||||
// 获取训练记录
|
||||
const tuneRecord = await openai.retrieveFineTune(training.tuneId, { httpsAgent });
|
||||
const tuneRecord = await openai.retrieveFineTune(training.tuneId, {
|
||||
httpsAgent: httpsAgent(false)
|
||||
});
|
||||
|
||||
// 删除训练文件
|
||||
openai.deleteFile(tuneRecord.data.training_files[0].id, { httpsAgent });
|
||||
openai.deleteFile(tuneRecord.data.training_files[0].id, { httpsAgent: httpsAgent(false) });
|
||||
// 取消训练
|
||||
openai.cancelFineTune(training.tuneId, { httpsAgent });
|
||||
openai.cancelFineTune(training.tuneId, { httpsAgent: httpsAgent(false) });
|
||||
}
|
||||
|
||||
// 删除对应训练记录
|
||||
|
@@ -46,11 +46,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
const { openai } = await getUserApiOpenai(userId);
|
||||
|
||||
// 获取 openai 的训练情况
|
||||
const { data } = await openai.retrieveFineTune(training.tuneId, { httpsAgent });
|
||||
const { data } = await openai.retrieveFineTune(training.tuneId, {
|
||||
httpsAgent: httpsAgent(false)
|
||||
});
|
||||
// console.log(data);
|
||||
if (data.status === OpenAiTuneStatusEnum.succeeded) {
|
||||
// 删除训练文件
|
||||
openai.deleteFile(data.training_files[0].id, { httpsAgent });
|
||||
openai.deleteFile(data.training_files[0].id, { httpsAgent: httpsAgent(false) });
|
||||
|
||||
// 更新模型状态和模型内容
|
||||
await Model.findByIdAndUpdate(modelId, {
|
||||
@@ -75,7 +77,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
/* 取消微调 */
|
||||
if (data.status === OpenAiTuneStatusEnum.cancelled) {
|
||||
// 删除训练文件
|
||||
openai.deleteFile(data.training_files[0].id, { httpsAgent });
|
||||
openai.deleteFile(data.training_files[0].id, { httpsAgent: httpsAgent(false) });
|
||||
|
||||
// 更新模型
|
||||
await Model.findByIdAndUpdate(modelId, {
|
||||
|
@@ -75,7 +75,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
// @ts-ignore
|
||||
fs.createReadStream(file.filepath),
|
||||
'fine-tune',
|
||||
{ httpsAgent }
|
||||
{ httpsAgent: httpsAgent(false) }
|
||||
);
|
||||
uploadFileId = uploadRes.data.id; // 记录上传文件的 ID
|
||||
|
||||
@@ -87,7 +87,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
suffix: model.name,
|
||||
n_epochs: 4
|
||||
},
|
||||
{ httpsAgent }
|
||||
{ httpsAgent: httpsAgent(false) }
|
||||
);
|
||||
|
||||
trainId = trainRes.data.id; // 记录训练 ID
|
||||
@@ -117,9 +117,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
// @ts-ignore
|
||||
if (openai) {
|
||||
// @ts-ignore
|
||||
uploadFileId && openai.deleteFile(uploadFileId, { httpsAgent });
|
||||
uploadFileId && openai.deleteFile(uploadFileId, { httpsAgent: httpsAgent(false) });
|
||||
// @ts-ignore
|
||||
trainId && openai.cancelFineTune(trainId, { httpsAgent });
|
||||
trainId && openai.cancelFineTune(trainId, { httpsAgent: httpsAgent(false) });
|
||||
}
|
||||
|
||||
jsonRes(res, {
|
||||
|
@@ -111,7 +111,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
{
|
||||
timeout: 120000,
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(true)
|
||||
}
|
||||
);
|
||||
|
||||
@@ -201,7 +201,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
{
|
||||
timeout: 120000,
|
||||
responseType: isStream ? 'stream' : 'json',
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(true)
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -163,7 +163,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
{
|
||||
timeout: 120000,
|
||||
responseType: isStream ? 'stream' : 'json',
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(true)
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -76,7 +76,7 @@ export async function generateAbstract(next = false): Promise<any> {
|
||||
},
|
||||
{
|
||||
timeout: 120000,
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(!userApiKey)
|
||||
}
|
||||
);
|
||||
|
||||
|
@@ -91,7 +91,7 @@ export async function generateQA(next = false): Promise<any> {
|
||||
},
|
||||
{
|
||||
timeout: 180000,
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(!userApiKey)
|
||||
}
|
||||
)
|
||||
.then((res) => {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import mongoose from 'mongoose';
|
||||
import { generateQA } from './events/generateQA';
|
||||
import { generateAbstract } from './events/generateAbstract';
|
||||
import { generateVector } from './events/generateVector';
|
||||
import tunnel from 'tunnel';
|
||||
|
||||
/**
|
||||
* 连接 MongoDB 数据库
|
||||
@@ -28,8 +28,27 @@ export async function connectToDatabase(): Promise<void> {
|
||||
}
|
||||
|
||||
generateQA();
|
||||
// generateAbstract();
|
||||
generateVector(true);
|
||||
|
||||
// 创建代理对象
|
||||
if (
|
||||
process.env.AXIOS_PROXY_HOST &&
|
||||
process.env.AXIOS_PROXY_PORT_FAST &&
|
||||
process.env.AXIOS_PROXY_PORT_NORMAL
|
||||
) {
|
||||
global.httpsAgentFast = tunnel.httpsOverHttp({
|
||||
proxy: {
|
||||
host: process.env.AXIOS_PROXY_HOST,
|
||||
port: +process.env.AXIOS_PROXY_PORT_FAST
|
||||
}
|
||||
});
|
||||
global.httpsAgentNormal = tunnel.httpsOverHttp({
|
||||
proxy: {
|
||||
host: process.env.AXIOS_PROXY_HOST,
|
||||
port: +process.env.AXIOS_PROXY_PORT_NORMAL
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export * from './models/authCode';
|
||||
|
@@ -85,7 +85,7 @@ export const openaiCreateEmbedding = async ({
|
||||
},
|
||||
{
|
||||
timeout: 60000,
|
||||
httpsAgent
|
||||
httpsAgent: httpsAgent(isPay)
|
||||
}
|
||||
)
|
||||
.then((res) => ({
|
||||
|
@@ -83,15 +83,8 @@ export const authOpenApiKey = async (req: NextApiRequest) => {
|
||||
};
|
||||
|
||||
/* 代理 */
|
||||
export const httpsAgent =
|
||||
process.env.AXIOS_PROXY_HOST && process.env.AXIOS_PROXY_PORT
|
||||
? tunnel.httpsOverHttp({
|
||||
proxy: {
|
||||
host: process.env.AXIOS_PROXY_HOST,
|
||||
port: +process.env.AXIOS_PROXY_PORT
|
||||
}
|
||||
})
|
||||
: undefined;
|
||||
export const httpsAgent = (fast: boolean) =>
|
||||
fast ? global.httpsAgentFast : global.httpsAgentNormal;
|
||||
|
||||
/* tokens 截断 */
|
||||
export const openaiChatFilter = (prompts: ChatItemType[], maxTokens: number) => {
|
||||
|
4
src/types/index.d.ts
vendored
4
src/types/index.d.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import type { Mongoose } from 'mongoose';
|
||||
import type { RedisClientType } from 'redis';
|
||||
import type { Agent } from 'http';
|
||||
|
||||
declare global {
|
||||
var mongodb: Mongoose | string | null;
|
||||
@@ -8,6 +9,9 @@ declare global {
|
||||
var generatingAbstract: boolean;
|
||||
var generatingVector: boolean;
|
||||
var QRCode: any;
|
||||
var httpsAgentFast: Agent;
|
||||
var httpsAgentNormal: Agent;
|
||||
|
||||
interface Window {
|
||||
['pdfjs-dist/build/pdf']: any;
|
||||
}
|
||||
|
Reference in New Issue
Block a user