mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
Some checks failed
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Has been cancelled
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
* 🔧 fix: Correct URL Construction in fetchModels Function Updated the URL construction in the fetchModels function to ensure proper formatting by removing trailing slashes from the base URL. This change prevents potential issues with API endpoint calls. * 🔧 fix: Remove OLLAMA from Known Custom Providers Updated the isKnownCustomProvider function and providerConfigMap to exclude OLLAMA as a known custom provider, streamlining the provider checks and configurations. * 🔧 test: Enhance fetchModels Tests for URL Construction Added new test cases to validate the URL construction in the fetchModels function, ensuring it handles trailing slashes correctly and appends query parameters as expected. This improves the robustness of the API endpoint calls. * chore: remove ollama provider-specific handling * chore: Refactor imports to use isUserProvided from @librechat/api
76 lines
2.7 KiB
JavaScript
76 lines
2.7 KiB
JavaScript
const { Providers } = require('@librechat/agents');
|
|
const { EModelEndpoint } = require('librechat-data-provider');
|
|
const { getCustomEndpointConfig } = require('@librechat/api');
|
|
const initAnthropic = require('~/server/services/Endpoints/anthropic/initialize');
|
|
const getBedrockOptions = require('~/server/services/Endpoints/bedrock/options');
|
|
const initOpenAI = require('~/server/services/Endpoints/openAI/initialize');
|
|
const initCustom = require('~/server/services/Endpoints/custom/initialize');
|
|
const initGoogle = require('~/server/services/Endpoints/google/initialize');
|
|
|
|
/** Check if the provider is a known custom provider
|
|
* @param {string | undefined} [provider] - The provider string
|
|
* @returns {boolean} - True if the provider is a known custom provider, false otherwise
|
|
*/
|
|
function isKnownCustomProvider(provider) {
|
|
return [Providers.XAI, Providers.DEEPSEEK, Providers.OPENROUTER].includes(
|
|
provider?.toLowerCase() || '',
|
|
);
|
|
}
|
|
|
|
const providerConfigMap = {
|
|
[Providers.XAI]: initCustom,
|
|
[Providers.DEEPSEEK]: initCustom,
|
|
[Providers.OPENROUTER]: initCustom,
|
|
[EModelEndpoint.openAI]: initOpenAI,
|
|
[EModelEndpoint.google]: initGoogle,
|
|
[EModelEndpoint.azureOpenAI]: initOpenAI,
|
|
[EModelEndpoint.anthropic]: initAnthropic,
|
|
[EModelEndpoint.bedrock]: getBedrockOptions,
|
|
};
|
|
|
|
/**
|
|
* Get the provider configuration and override endpoint based on the provider string
|
|
* @param {Object} params
|
|
* @param {string} params.provider - The provider string
|
|
* @param {AppConfig} params.appConfig - The application configuration
|
|
* @returns {{
|
|
* getOptions: (typeof providerConfigMap)[keyof typeof providerConfigMap],
|
|
* overrideProvider: string,
|
|
* customEndpointConfig?: TEndpoint
|
|
* }}
|
|
*/
|
|
function getProviderConfig({ provider, appConfig }) {
|
|
let getOptions = providerConfigMap[provider];
|
|
let overrideProvider = provider;
|
|
/** @type {TEndpoint | undefined} */
|
|
let customEndpointConfig;
|
|
|
|
if (!getOptions && providerConfigMap[provider.toLowerCase()] != null) {
|
|
overrideProvider = provider.toLowerCase();
|
|
getOptions = providerConfigMap[overrideProvider];
|
|
} else if (!getOptions) {
|
|
customEndpointConfig = getCustomEndpointConfig({ endpoint: provider, appConfig });
|
|
if (!customEndpointConfig) {
|
|
throw new Error(`Provider ${provider} not supported`);
|
|
}
|
|
getOptions = initCustom;
|
|
overrideProvider = Providers.OPENAI;
|
|
}
|
|
|
|
if (isKnownCustomProvider(overrideProvider) && !customEndpointConfig) {
|
|
customEndpointConfig = getCustomEndpointConfig({ endpoint: provider, appConfig });
|
|
if (!customEndpointConfig) {
|
|
throw new Error(`Provider ${provider} not supported`);
|
|
}
|
|
}
|
|
|
|
return {
|
|
getOptions,
|
|
overrideProvider,
|
|
customEndpointConfig,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
getProviderConfig,
|
|
};
|