mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00

* perf: transcriptions api * perf: variable picker tip * perf: variable picker tip * perf: chat select app * feat: router to app detail * perf: variable avoid space * perf: variable picker * perf: doc2x icon and params * perf: sandbox support countToken * feat: sandbox support delay and countToken
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { UserModelSchema } from '@fastgpt/global/support/user/type';
|
|
import OpenAI from '@fastgpt/global/core/ai';
|
|
|
|
export const openaiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
|
|
|
|
export const getAIApi = (props?: {
|
|
userKey?: UserModelSchema['openaiAccount'];
|
|
timeout?: number;
|
|
}) => {
|
|
const { userKey, timeout } = props || {};
|
|
|
|
const baseUrl =
|
|
userKey?.baseUrl || global?.systemEnv?.oneapiUrl || process.env.ONEAPI_URL || openaiBaseUrl;
|
|
const apiKey = userKey?.key || global?.systemEnv?.chatApiKey || process.env.CHAT_API_KEY || '';
|
|
|
|
return new OpenAI({
|
|
baseURL: baseUrl,
|
|
apiKey,
|
|
httpAgent: global.httpsAgent,
|
|
timeout,
|
|
maxRetries: 2
|
|
});
|
|
};
|
|
|
|
export const getAxiosConfig = (props?: { userKey?: UserModelSchema['openaiAccount'] }) => {
|
|
const { userKey } = props || {};
|
|
|
|
const baseUrl =
|
|
userKey?.baseUrl || global?.systemEnv?.oneapiUrl || process.env.ONEAPI_URL || openaiBaseUrl;
|
|
const apiKey = userKey?.key || global?.systemEnv?.chatApiKey || process.env.CHAT_API_KEY || '';
|
|
|
|
return {
|
|
baseUrl,
|
|
authorization: `Bearer ${apiKey}`
|
|
};
|
|
};
|