perf: 专线代理配置
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user