2024-01-26 09:27:20 -05:00
|
|
|
import { EModelEndpoint } from 'librechat-data-provider';
|
2024-02-28 14:27:19 -05:00
|
|
|
import { useFormContext, Controller } from 'react-hook-form';
|
2023-07-06 11:47:08 -04:00
|
|
|
import InputWithLabel from './InputWithLabel';
|
|
|
|
|
|
2024-02-28 14:27:19 -05:00
|
|
|
const OpenAIConfig = ({
|
|
|
|
|
endpoint,
|
|
|
|
|
userProvideURL,
|
|
|
|
|
}: {
|
|
|
|
|
endpoint: EModelEndpoint | string;
|
|
|
|
|
userProvideURL?: boolean | null;
|
|
|
|
|
}) => {
|
|
|
|
|
const { control } = useFormContext();
|
|
|
|
|
const isAzure = endpoint === EModelEndpoint.azureOpenAI;
|
2023-07-06 11:47:08 -04:00
|
|
|
return (
|
2024-02-28 14:27:19 -05:00
|
|
|
<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 && (
|
2023-07-06 11:47:08 -04:00
|
|
|
<>
|
2024-02-28 14:27:19 -05:00
|
|
|
<Controller
|
|
|
|
|
name="azureOpenAIApiKey"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<InputWithLabel
|
|
|
|
|
id="azureOpenAIApiKey"
|
|
|
|
|
{...field}
|
|
|
|
|
label={'Azure OpenAI API Key'}
|
|
|
|
|
labelClassName="mb-1"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-07-06 11:47:08 -04:00
|
|
|
/>
|
2024-02-28 14:27:19 -05:00
|
|
|
<Controller
|
|
|
|
|
name="azureOpenAIApiInstanceName"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<InputWithLabel
|
|
|
|
|
id="azureOpenAIApiInstanceName"
|
|
|
|
|
{...field}
|
|
|
|
|
label={'Azure OpenAI Instance Name'}
|
|
|
|
|
labelClassName="mb-1"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-07-06 11:47:08 -04:00
|
|
|
/>
|
2024-02-28 14:27:19 -05:00
|
|
|
<Controller
|
|
|
|
|
name="azureOpenAIApiDeploymentName"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<InputWithLabel
|
|
|
|
|
id="azureOpenAIApiDeploymentName"
|
|
|
|
|
{...field}
|
|
|
|
|
label={'Azure OpenAI Deployment Name'}
|
|
|
|
|
labelClassName="mb-1"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-07-06 11:47:08 -04:00
|
|
|
/>
|
2024-02-28 14:27:19 -05:00
|
|
|
<Controller
|
|
|
|
|
name="azureOpenAIApiVersion"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<InputWithLabel
|
|
|
|
|
id="azureOpenAIApiVersion"
|
|
|
|
|
{...field}
|
|
|
|
|
label={'Azure OpenAI API Version'}
|
|
|
|
|
labelClassName="mb-1"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-07-06 11:47:08 -04:00
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-02-28 14:27:19 -05:00
|
|
|
{userProvideURL && (
|
|
|
|
|
<Controller
|
|
|
|
|
name="baseURL"
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<InputWithLabel
|
|
|
|
|
id="baseURL"
|
|
|
|
|
{...field}
|
|
|
|
|
label={'API Base URL'}
|
|
|
|
|
subLabel={'(Optional)'}
|
|
|
|
|
labelClassName="mb-1"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</form>
|
2023-07-06 11:47:08 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default OpenAIConfig;
|