进入目录:ChatGPT-Next-Web/app/config/server.ts
,找到如下代码,添加这三行即可
export const getServerSideConfig = () => {
if (typeof process === "undefined") {
throw Error(
"[Server Config] you are importing a nodejs-only module outside of nodejs",
);
}
//添加以下两行
const apiKeys = (process.env.OPENAI_API_KEY ?? '').split(',')
const apiKey = apiKeys.at(Math.floor(Math.random() *apiKeys.length)) ?? ''
return {
apiKey,
code: process.env.CODE,
codes: ACCESS_CODES,
needCode: ACCESS_CODES.size > 0,
baseUrl: process.env.BASE_URL,
proxyUrl: process.env.PROXY_URL,
isVercel: !!process.env.VERCEL,
hideUserApiKey: !!process.env.HIDE_USER_API_KEY,
enableGPT4: !process.env.DISABLE_GPT4,
};
如果是用Vercel部署,则在Vercel上修改环境变量OPENAI_API_KEY,key与key之间用逗号隔开即可,然后重新redeploy