Skip to content

Commit

Permalink
Append Bearer for MistralAI and OpenAI APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
PasanT9 committed Oct 24, 2024
1 parent 9190d9b commit 7c7e43c
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,24 @@ export default function AIEndpointAuth(props) {
const [isHeaderParameter] = useState(!!apiKeyParamConfig.authHeader);
const [showApiKey, setShowApiKey] = useState(false);

const subtypeConfig = api.subtypeConfiguration && JSON.parse(api.subtypeConfiguration.configuration);
const llmProviderName = subtypeConfig ? subtypeConfig.llmProviderName : null;

useEffect(() => {

let newApiKeyValue = api.endpointConfig?.endpoint_security?.[isProduction ?
'production' : 'sandbox']?.apiKeyValue === '' ? '' : null;

if ((llmProviderName === 'MistralAI' || llmProviderName === 'OpenAI') && newApiKeyValue !== '') {
newApiKeyValue = `Bearer ${newApiKeyValue}`;
}

saveEndpointSecurityConfig({
...CONSTS.DEFAULT_ENDPOINT_SECURITY,
type: 'apikey',
apiKeyIdentifier,
apiKeyIdentifierType,
apiKeyValue: api.endpointConfig?.endpoint_security?.[isProduction ?
'production' : 'sandbox']?.apiKeyValue === '' ? '' : null,
apiKeyValue: newApiKeyValue,
enabled: true,
}, isProduction ? 'production' : 'sandbox');
}, []);
Expand All @@ -55,12 +65,19 @@ export default function AIEndpointAuth(props) {
};

const handleApiKeyBlur = (event) => {

let updatedApiKeyValue = event.target.value === '********' ? '' : event.target.value;

if ((llmProviderName === 'MistralAI' || llmProviderName === 'OpenAI') && updatedApiKeyValue !== '') {
updatedApiKeyValue = `Bearer ${updatedApiKeyValue}`;
}

saveEndpointSecurityConfig({
...CONSTS.DEFAULT_ENDPOINT_SECURITY,
type: 'apikey',
apiKeyIdentifier,
apiKeyIdentifierType,
apiKeyValue: event.target.value === '********' ? '' : event.target.value,
apiKeyValue: updatedApiKeyValue,
enabled: true,
}, isProduction ? 'production' : 'sandbox');
};
Expand Down

0 comments on commit 7c7e43c

Please sign in to comment.