mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🔗 feat: User Provided Base URL for OpenAI endpoints (#1919)
* chore: bump browserslist-db@latest * refactor(EndpointService): simplify with `generateConfig`, utilize optional baseURL for OpenAI-based endpoints, use `isUserProvided` helper fn wherever needed * refactor(custom/initializeClient): use standardized naming for common variables * feat: user provided baseURL for openAI-based endpoints * refactor(custom/initializeClient): re-order operations * fix: knownendpoints enum definition and add FetchTokenConfig, bump data-provider * refactor(custom): use tokenKey dependent on userProvided conditions for caching and fetching endpointTokenConfig, anticipate token rates from custom config * refactor(custom): assure endpointTokenConfig is only accessed from cache if qualifies for fetching * fix(ci): update tests for initializeClient based on userProvideURL changes * fix(EndpointService): correct baseURL env var for assistants: `ASSISTANTS_BASE_URL` * fix: unnecessary run cancellation on res.close() when response.run is completed * feat(assistants): user provided URL option * ci: update tests and add test for `assistants` endpoint * chore: leaner condition for request closing * chore: more descriptive error message to provide keys again
This commit is contained in:
parent
53ae2d7bfb
commit
2f92b54787
17 changed files with 762 additions and 226 deletions
|
|
@ -20,9 +20,18 @@ const endpointComponents = {
|
|||
[EModelEndpoint.custom]: CustomConfig,
|
||||
[EModelEndpoint.azureOpenAI]: OpenAIConfig,
|
||||
[EModelEndpoint.gptPlugins]: OpenAIConfig,
|
||||
[EModelEndpoint.assistants]: OpenAIConfig,
|
||||
default: OtherConfig,
|
||||
};
|
||||
|
||||
const formSet: Set<string> = new Set([
|
||||
EModelEndpoint.openAI,
|
||||
EModelEndpoint.custom,
|
||||
EModelEndpoint.azureOpenAI,
|
||||
EModelEndpoint.gptPlugins,
|
||||
EModelEndpoint.assistants,
|
||||
]);
|
||||
|
||||
const EXPIRY = {
|
||||
THIRTY_MINUTES: { display: 'in 30 minutes', value: 30 * 60 * 1000 },
|
||||
TWO_HOURS: { display: 'in 2 hours', value: 2 * 60 * 60 * 1000 },
|
||||
|
|
@ -47,6 +56,10 @@ const SetKeyDialog = ({
|
|||
defaultValues: {
|
||||
apiKey: '',
|
||||
baseURL: '',
|
||||
azureOpenAIApiKey: '',
|
||||
azureOpenAIApiInstanceName: '',
|
||||
azureOpenAIApiDeploymentName: '',
|
||||
azureOpenAIApiVersion: '',
|
||||
// TODO: allow endpoint definitions from user
|
||||
// name: '',
|
||||
// TODO: add custom endpoint models defined by user
|
||||
|
|
@ -76,10 +89,26 @@ const SetKeyDialog = ({
|
|||
onOpenChange(false);
|
||||
};
|
||||
|
||||
if (endpoint === EModelEndpoint.custom || endpointType === EModelEndpoint.custom) {
|
||||
if (formSet.has(endpoint) || formSet.has(endpointType ?? '')) {
|
||||
// TODO: handle other user provided options besides baseURL and apiKey
|
||||
methods.handleSubmit((data) => {
|
||||
const isAzure = endpoint === EModelEndpoint.azureOpenAI;
|
||||
const isOpenAIBase =
|
||||
isAzure ||
|
||||
endpoint === EModelEndpoint.openAI ||
|
||||
endpoint === EModelEndpoint.gptPlugins ||
|
||||
endpoint === EModelEndpoint.assistants;
|
||||
if (isAzure) {
|
||||
data.apiKey = 'n/a';
|
||||
}
|
||||
|
||||
const emptyValues = Object.keys(data).filter((key) => {
|
||||
if (!isAzure && key.startsWith('azure')) {
|
||||
return false;
|
||||
}
|
||||
if (isOpenAIBase && key === 'baseURL') {
|
||||
return false;
|
||||
}
|
||||
if (key === 'baseURL' && !userProvideURL) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -92,10 +121,22 @@ const SetKeyDialog = ({
|
|||
status: 'error',
|
||||
});
|
||||
onOpenChange(true);
|
||||
} else {
|
||||
saveKey(JSON.stringify(data));
|
||||
methods.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
const { apiKey, baseURL, ...azureOptions } = data;
|
||||
const userProvidedData = { apiKey, baseURL };
|
||||
if (isAzure) {
|
||||
userProvidedData.apiKey = JSON.stringify({
|
||||
azureOpenAIApiKey: azureOptions.azureOpenAIApiKey,
|
||||
azureOpenAIApiInstanceName: azureOptions.azureOpenAIApiInstanceName,
|
||||
azureOpenAIApiDeploymentName: azureOptions.azureOpenAIApiDeploymentName,
|
||||
azureOpenAIApiVersion: azureOptions.azureOpenAIApiVersion,
|
||||
});
|
||||
}
|
||||
|
||||
saveKey(JSON.stringify(userProvidedData));
|
||||
methods.reset();
|
||||
})();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue