mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +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
|
|
@ -1,80 +1,101 @@
|
|||
import { useEffect, useState } from 'react';
|
||||
import { EModelEndpoint } from 'librechat-data-provider';
|
||||
import { useMultipleKeys } from '~/hooks/Input';
|
||||
import { useFormContext, Controller } from 'react-hook-form';
|
||||
import InputWithLabel from './InputWithLabel';
|
||||
import type { TConfigProps } from '~/common';
|
||||
import { isJson } from '~/utils/json';
|
||||
|
||||
const OpenAIConfig = ({ userKey, setUserKey, endpoint }: TConfigProps) => {
|
||||
const [showPanel, setShowPanel] = useState(endpoint === EModelEndpoint.azureOpenAI);
|
||||
const { getMultiKey: getAzure, setMultiKey: setAzure } = useMultipleKeys(setUserKey);
|
||||
|
||||
useEffect(() => {
|
||||
if (isJson(userKey)) {
|
||||
setShowPanel(true);
|
||||
}
|
||||
setUserKey('');
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!showPanel && isJson(userKey)) {
|
||||
setUserKey('');
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [showPanel]);
|
||||
|
||||
const OpenAIConfig = ({
|
||||
endpoint,
|
||||
userProvideURL,
|
||||
}: {
|
||||
endpoint: EModelEndpoint | string;
|
||||
userProvideURL?: boolean | null;
|
||||
}) => {
|
||||
const { control } = useFormContext();
|
||||
const isAzure = endpoint === EModelEndpoint.azureOpenAI;
|
||||
return (
|
||||
<>
|
||||
{!showPanel ? (
|
||||
<form className="flex-wrap">
|
||||
{!isAzure && (
|
||||
<Controller
|
||||
name="apiKey"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="apiKey"
|
||||
{...field}
|
||||
label={`${isAzure ? 'Azure q' : ''}OpenAI API Key`}
|
||||
labelClassName="mb-1"
|
||||
inputClassName="mb-2"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{isAzure && (
|
||||
<>
|
||||
<InputWithLabel
|
||||
id={endpoint}
|
||||
value={userKey ?? ''}
|
||||
onChange={(e: { target: { value: string } }) => setUserKey(e.target.value ?? '')}
|
||||
label={'OpenAI API Key'}
|
||||
<Controller
|
||||
name="azureOpenAIApiKey"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="azureOpenAIApiKey"
|
||||
{...field}
|
||||
label={'Azure OpenAI API Key'}
|
||||
labelClassName="mb-1"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<InputWithLabel
|
||||
id={'instanceNameLabel'}
|
||||
value={getAzure('azureOpenAIApiInstanceName', userKey) ?? ''}
|
||||
onChange={(e: { target: { value: string } }) =>
|
||||
setAzure('azureOpenAIApiInstanceName', e.target.value ?? '', userKey)
|
||||
}
|
||||
label={'Azure OpenAI Instance Name'}
|
||||
<Controller
|
||||
name="azureOpenAIApiInstanceName"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="azureOpenAIApiInstanceName"
|
||||
{...field}
|
||||
label={'Azure OpenAI Instance Name'}
|
||||
labelClassName="mb-1"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<InputWithLabel
|
||||
id={'deploymentNameLabel'}
|
||||
value={getAzure('azureOpenAIApiDeploymentName', userKey) ?? ''}
|
||||
onChange={(e: { target: { value: string } }) =>
|
||||
setAzure('azureOpenAIApiDeploymentName', e.target.value ?? '', userKey)
|
||||
}
|
||||
label={'Azure OpenAI Deployment Name'}
|
||||
<Controller
|
||||
name="azureOpenAIApiDeploymentName"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="azureOpenAIApiDeploymentName"
|
||||
{...field}
|
||||
label={'Azure OpenAI Deployment Name'}
|
||||
labelClassName="mb-1"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<InputWithLabel
|
||||
id={'versionLabel'}
|
||||
value={getAzure('azureOpenAIApiVersion', userKey) ?? ''}
|
||||
onChange={(e: { target: { value: string } }) =>
|
||||
setAzure('azureOpenAIApiVersion', e.target.value ?? '', userKey)
|
||||
}
|
||||
label={'Azure OpenAI API Version'}
|
||||
/>
|
||||
|
||||
<InputWithLabel
|
||||
id={'apiKeyLabel'}
|
||||
value={getAzure('azureOpenAIApiKey', userKey) ?? ''}
|
||||
onChange={(e: { target: { value: string } }) =>
|
||||
setAzure('azureOpenAIApiKey', e.target.value ?? '', userKey)
|
||||
}
|
||||
label={'Azure OpenAI API Key'}
|
||||
<Controller
|
||||
name="azureOpenAIApiVersion"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="azureOpenAIApiVersion"
|
||||
{...field}
|
||||
label={'Azure OpenAI API Version'}
|
||||
labelClassName="mb-1"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
{userProvideURL && (
|
||||
<Controller
|
||||
name="baseURL"
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InputWithLabel
|
||||
id="baseURL"
|
||||
{...field}
|
||||
label={'API Base URL'}
|
||||
subLabel={'(Optional)'}
|
||||
labelClassName="mb-1"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue