perf: 专线代理配置

This commit is contained in:
archer
2023-04-08 20:49:15 +08:00
parent 52d00d0562
commit 705ac1c27e
15 changed files with 52 additions and 32 deletions

View File

@@ -76,7 +76,7 @@ export async function generateAbstract(next = false): Promise<any> {
},
{
timeout: 120000,
httpsAgent
httpsAgent: httpsAgent(!userApiKey)
}
);

View File

@@ -91,7 +91,7 @@ export async function generateQA(next = false): Promise<any> {
},
{
timeout: 180000,
httpsAgent
httpsAgent: httpsAgent(!userApiKey)
}
)
.then((res) => {

View File

@@ -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';

View File

@@ -85,7 +85,7 @@ export const openaiCreateEmbedding = async ({
},
{
timeout: 60000,
httpsAgent
httpsAgent: httpsAgent(isPay)
}
)
.then((res) => ({

View File

@@ -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) => {