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

* Fixbranch (#43) * move components to web package (#37) * move components * fix * openapi config * fix team share bug --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com> Co-authored-by: archer <545436317@qq.com> * fix: http variable and ai base url * remove log --------- Co-authored-by: yst <77910600+yu-and-liu@users.noreply.github.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
24 lines
709 B
TypeScript
24 lines
709 B
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
|
|
});
|
|
};
|