Skip to content

Commit

Permalink
🦙 refactor: Normalize Ollama Config Names (#4657)
Browse files Browse the repository at this point in the history
  • Loading branch information
danny-avila authored Nov 7, 2024
1 parent c27b26c commit d60a0af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions api/server/services/Config/loadConfigEndpoints.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
const { isUserProvided, normalizeEndpointName } = require('~/server/utils');
const { getCustomConfig } = require('./getCustomConfig');
const { isUserProvided } = require('~/server/utils');

/**
* Load config endpoints from the cached configuration object
Expand Down Expand Up @@ -29,7 +29,8 @@ async function loadConfigEndpoints(req) {

for (let i = 0; i < customEndpoints.length; i++) {
const endpoint = customEndpoints[i];
const { baseURL, apiKey, name, iconURL, modelDisplayLabel } = endpoint;
const { baseURL, apiKey, name: configName, iconURL, modelDisplayLabel } = endpoint;
const name = normalizeEndpointName(configName);

const resolvedApiKey = extractEnvVariable(apiKey);
const resolvedBaseURL = extractEnvVariable(baseURL);
Expand Down
11 changes: 1 addition & 10 deletions api/server/services/Config/loadConfigModels.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const { Providers } = require('@librechat/agents');
const { EModelEndpoint, extractEnvVariable } = require('librechat-data-provider');
const { isUserProvided, normalizeEndpointName } = require('~/server/utils');
const { fetchModels } = require('~/server/services/ModelService');
const { getCustomConfig } = require('./getCustomConfig');
const { isUserProvided } = require('~/server/utils');

/**
* @param {string} name
* @returns {string}
*/
function normalizeEndpointName(name = '') {
return name.toLowerCase() === Providers.OLLAMA ? Providers.OLLAMA : name;
}

/**
* Load config endpoints from the cached configuration object
Expand Down
15 changes: 13 additions & 2 deletions api/server/utils/handleText.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
defaultRetrievalModels,
defaultAssistantsVersion,
} = require('librechat-data-provider');
const { Providers } = require('@librechat/agents');
const { getCitations, citeText } = require('./citations');
const partialRight = require('lodash/partialRight');
const { sendMessage } = require('./streamResponse');
Expand Down Expand Up @@ -212,13 +213,23 @@ function generateConfig(key, baseURL, endpoint) {
return config;
}

/**
* Normalize the endpoint name to system-expected value.
* @param {string} name
* @returns {string}
*/
function normalizeEndpointName(name = '') {
return name.toLowerCase() === Providers.OLLAMA ? Providers.OLLAMA : name;
}

module.exports = {
createOnProgress,
isEnabled,
handleText,
formatSteps,
formatAction,
addSpaceIfNeeded,
isUserProvided,
generateConfig,
addSpaceIfNeeded,
createOnProgress,
normalizeEndpointName,
};

0 comments on commit d60a0af

Please sign in to comment.