mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00
feat: user openai account
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { UserModelSchema } from '@/types/mongoSchema';
|
||||
import { Configuration, OpenAIApi } from 'openai';
|
||||
|
||||
export const openaiBaseUrl = 'https://api.openai.com/v1';
|
||||
@@ -5,22 +6,22 @@ export const baseUrl = process.env.ONEAPI_URL || process.env.OPENAI_BASE_URL ||
|
||||
|
||||
export const systemAIChatKey = process.env.ONEAPI_KEY || process.env.OPENAIKEY || '';
|
||||
|
||||
export const getAIChatApi = (props?: { base?: string; apikey?: string }) => {
|
||||
export const getAIChatApi = (props?: UserModelSchema['openaiAccount']) => {
|
||||
return new OpenAIApi(
|
||||
new Configuration({
|
||||
basePath: props?.base || baseUrl,
|
||||
apiKey: props?.apikey || systemAIChatKey
|
||||
basePath: props?.baseUrl || baseUrl,
|
||||
apiKey: props?.key || systemAIChatKey
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
/* openai axios config */
|
||||
export const axiosConfig = (props?: { base?: string; apikey?: string }) => {
|
||||
export const axiosConfig = (props?: UserModelSchema['openaiAccount']) => {
|
||||
return {
|
||||
baseURL: props?.base || baseUrl, // 此处仅对非 npm 模块有效
|
||||
baseURL: props?.baseUrl || baseUrl, // 此处仅对非 npm 模块有效
|
||||
httpsAgent: global.httpsAgent,
|
||||
headers: {
|
||||
Authorization: `Bearer ${props?.apikey || systemAIChatKey}`,
|
||||
Authorization: `Bearer ${props?.key || systemAIChatKey}`,
|
||||
auth: process.env.OPENAI_BASE_URL_AUTH || ''
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user