feat: openai base url

This commit is contained in:
archer
2023-04-25 20:02:35 +08:00
parent ce68791c3c
commit fb08f61eb5
21 changed files with 47 additions and 385 deletions

View File

@@ -8,7 +8,8 @@ import mongoose from 'mongoose';
export const getOpenAIApi = (apiKey: string) => {
const configuration = new Configuration({
apiKey
apiKey,
basePath: process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1'
});
return new OpenAIApi(configuration, undefined);

View File

@@ -2,7 +2,7 @@ import type { NextApiResponse } from 'next';
import type { PassThrough } from 'stream';
import { createParser, ParsedEvent, ReconnectInterval } from 'eventsource-parser';
import { getOpenAIApi } from '@/service/utils/auth';
import { httpsAgent } from './tools';
import { axiosConfig } from './tools';
import { User } from '../models/user';
import { formatPrice } from '@/utils/user';
import { embeddingModel } from '@/constants/model';
@@ -85,7 +85,7 @@ export const openaiCreateEmbedding = async ({
},
{
timeout: 60000,
httpsAgent: httpsAgent(isPay)
...axiosConfig
}
)
.then((res) => ({

View File

@@ -84,9 +84,10 @@ export const authOpenApiKey = async (req: NextApiRequest) => {
}
};
/* 代理 */
export const httpsAgent = (fast: boolean) =>
fast ? global.httpsAgentFast : global.httpsAgentNormal;
/* openai axios config */
export const axiosConfig = {
httpsAgent: global.httpsAgent
};
/* delete invalid symbol */
const simplifyStr = (str: string) =>