File size: 1,741 Bytes
f0743f4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import { EModelEndpoint, extractEnvVariable, normalizeEndpointName } from 'librechat-data-provider';
import type { TCustomEndpoints, TEndpoint, TConfig } from 'librechat-data-provider';
import type { TCustomEndpointsConfig } from '~/types/endpoints';
import { isUserProvided } from '~/utils';
/**
* Load config endpoints from the cached configuration object
* @param customEndpointsConfig - The configuration object
*/
export function loadCustomEndpointsConfig(
customEndpoints?: TCustomEndpoints,
): TCustomEndpointsConfig | undefined {
if (!customEndpoints) {
return;
}
const customEndpointsConfig: TCustomEndpointsConfig = {};
if (Array.isArray(customEndpoints)) {
const filteredEndpoints = customEndpoints.filter(
(endpoint) =>
endpoint.baseURL &&
endpoint.apiKey &&
endpoint.name &&
endpoint.models &&
(endpoint.models.fetch || endpoint.models.default),
);
for (let i = 0; i < filteredEndpoints.length; i++) {
const endpoint = filteredEndpoints[i] as TEndpoint;
const {
baseURL,
apiKey,
name: configName,
iconURL,
modelDisplayLabel,
customParams,
} = endpoint;
const name = normalizeEndpointName(configName);
const resolvedApiKey = extractEnvVariable(apiKey ?? '');
const resolvedBaseURL = extractEnvVariable(baseURL ?? '');
customEndpointsConfig[name] = {
type: EModelEndpoint.custom,
userProvide: isUserProvided(resolvedApiKey),
userProvideURL: isUserProvided(resolvedBaseURL),
customParams: customParams as TConfig['customParams'],
modelDisplayLabel,
iconURL,
};
}
}
return customEndpointsConfig;
}
|