Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AI API endpoint security issues and add AI / LLM text changes #829

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions portals/publisher/src/main/webapp/site/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
"Apis.Create.AIAPI.ApiCreateAIAPI.back": "Back",
"Apis.Create.AIAPI.ApiCreateAIAPI.cancel": "Cancel",
"Apis.Create.AIAPI.ApiCreateAIAPI.create": "Create",
"Apis.Create.AIAPI.ApiCreateAIAPI.heading": "Create an API using an AI Service provider API definition.",
"Apis.Create.AIAPI.ApiCreateAIAPI.heading": "Create an API using an AI/LLM Service provider API definition.",
"Apis.Create.AIAPI.ApiCreateAIAPI.next": "Next",
"Apis.Create.AIAPI.ApiCreateAIAPI.sub.heading": "Create an API using an existing AI Service provider API definition.",
"Apis.Create.AIAPI.ApiCreateAIAPI.wizard.one": "Provide AI Service provider API",
"Apis.Create.AIAPI.ApiCreateAIAPI.sub.heading": "Create an API using an existing AI/LLM Service provider API definition.",
"Apis.Create.AIAPI.ApiCreateAIAPI.wizard.one": "Provide AI/LLM Service provider API",
"Apis.Create.AIAPI.ApiCreateAIAPI.wizard.two": "Create API",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model": "API version",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model.empty": "No AI Service Provider selected.",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model.empty": "No AI/LLM Service Provider selected.",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model.helper": "Select API version for the API",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model.placeholder": "Search API version",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider": "AI Service Provider",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.empty": "Loading AI Service Providers...",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.helper.text": "Select AI Service Provider for the API",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.placeholder": "Search AI Service Provider",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider": "AI/LLM Service Provider",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.empty": "No AI/LLM Service Provider defined.",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.helper.text": "Select AI/LLM Service Provider for the API",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.loading": "Loading AI/LLM Service Providers...",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.placeholder": "Search AI/LLM Service Provider",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.LLM.Provider.fetch.error": "Something went wrong while fetching LLM Providers",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.LLMProvider.API.Definition.fetch.error": "Something went wrong while fetching LLM Provider API Definition",
"Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.LLMProvider.API.Definition.validation.failure.error": "Error while validating the LLM Provider API Definition",
Expand Down Expand Up @@ -726,6 +727,7 @@
"Apis.Details.Endpoints.Endpoints.delete.sequence.backend.error": "Error Deleting Sandbox Sequence Backend",
"Apis.Details.Endpoints.Endpoints.endpoints.header": "Endpoints",
"Apis.Details.Endpoints.Endpoints.missing.accessKey.secretKey.error": "Access Key, Secret Key and Region should not be empty",
"Apis.Details.Endpoints.Endpoints.missing.endpoint.ai.error": "Production & Sandbox Endpoint Security should be added",
"Apis.Details.Endpoints.Endpoints.missing.endpoint.error": "Either one of Production or Sandbox Endpoints should be added.",
"Apis.Details.Endpoints.Endpoints.missing.prod.endpoint.loadbalance": "Default Production Endpoint should not be empty",
"Apis.Details.Endpoints.Endpoints.missing.prototype.url": "Prototype Endpoint URL should not be empty",
Expand Down Expand Up @@ -1566,7 +1568,7 @@
"Apis.Details.TryOutConsole.token.helper": "Generate or provide an internal API Key",
"Apis.Details.TryOutConsole.token.label": "Internal API Key",
"Apis.Details.components.APIDetailsTopMenu.advertise.only.label": "Third Party",
"Apis.Details.components.APIDetailsTopMenu.ai.api.label": "AI API",
"Apis.Details.components.APIDetailsTopMenu.ai.api.label": "AI/LLM API",
"Apis.Details.components.APIDetailsTopMenu.created.by": "Created by:",
"Apis.Details.components.APIDetailsTopMenu.current.api": "Current API",
"Apis.Details.components.APIDetailsTopMenu.error": "Something went wrong while downloading the API.",
Expand Down Expand Up @@ -1625,7 +1627,7 @@
"Apis.Details.local.Scopes.heading.edit.heading": "Local Scopes",
"Apis.Details.local.Scopes.heading.scope.heading": "Local Scopes",
"Apis.Details.scopes.Edit.text.editor.edit": "Edit",
"Apis.Listing.AIAPI.ai.api": "AI API",
"Apis.Listing.AIAPI.ai.api": "AI/LLM API",
"Apis.Listing.ApiTableView.context": "Context",
"Apis.Listing.ApiTableView.items.per.page": "Items per page",
"Apis.Listing.ApiTableView.name": "Name",
Expand All @@ -1640,8 +1642,8 @@
"Apis.Listing.ApiThumb.owners.technical": "Technical",
"Apis.Listing.ApiThumb.version": "Version",
"Apis.Listing.Components.Create.API": "Create API",
"Apis.Listing.SampleAPI.SampleAPI.ai.api.create.title": "Create AI API",
"Apis.Listing.SampleAPI.SampleAPI.ai.api.import.content": "Create AI APIs by importing AI service provider APIs",
"Apis.Listing.SampleAPI.SampleAPI.ai.api.create.title": "Create AI/LLM API",
"Apis.Listing.SampleAPI.SampleAPI.ai.api.import.content": "Create AI/LLM APIs by importing service provider APIs",
"Apis.Listing.SampleAPI.SampleAPI.create.new": "Let’s get started !",
"Apis.Listing.SampleAPI.SampleAPI.create.new.description": "Choose your option to create an API",
"Apis.Listing.SampleAPI.SampleAPI.graphql.api": "GraphQL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function apiInputsReducer(currentState, inputAction) {
}
}
/**
* Handle API creation from AI Service Provider API Definition.
* Handle API creation from AI/LLM Service Provider API Definition.
*
* @export
* @param {*} props
Expand Down Expand Up @@ -189,13 +189,13 @@ export default function ApiCreateAIAPI(props) {
<Typography variant='h5'>
<FormattedMessage
id='Apis.Create.AIAPI.ApiCreateAIAPI.heading'
defaultMessage='Create an API using an AI Service provider API definition.'
defaultMessage='Create an API using an AI/LLM Service provider API definition.'
/>
</Typography>
<Typography variant='caption'>
<FormattedMessage
id='Apis.Create.AIAPI.ApiCreateAIAPI.sub.heading'
defaultMessage='Create an API using an existing AI Service provider API definition.'
defaultMessage='Create an API using an existing AI/LLM Service provider API definition.'
/>
</Typography>
</>
Expand All @@ -207,7 +207,7 @@ export default function ApiCreateAIAPI(props) {
<StepLabel>
<FormattedMessage
id='Apis.Create.AIAPI.ApiCreateAIAPI.wizard.one'
defaultMessage='Provide AI Service provider API'
defaultMessage='Provide AI/LLM Service provider API'
/>
</StepLabel>
</Step>
Expand Down Expand Up @@ -238,6 +238,7 @@ export default function ApiCreateAIAPI(props) {
multiGateway={multiGateway}
api={apiInputs}
isAPIProduct={false}
hideEndpoint
/>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default function ProvideAIOpenAPI(props) {
fullWidth
id='AI-providers-autocomplete'
options={getUniqueProviderList(llmProviders)}
noOptionsText='No AI Service Provider defined'
noOptionsText='No AI/LLM Service Provider defined'
value={selectedProvider}
onChange={(e, newValue) => {
setSelectedProvider(newValue);
Expand All @@ -156,25 +156,25 @@ export default function ProvideAIOpenAPI(props) {
<>
<FormattedMessage
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider'
defaultMessage='AI Service Provider'
defaultMessage='AI/LLM Service Provider'
/>
<sup className={classes.mandatoryStar}>*</sup>
</>
) : (
<FormattedMessage
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.empty'
defaultMessage='No AI Service Provider defined.'
defaultMessage='No AI/LLM Service Provider defined.'
/>
)
}
placeholder={intl.formatMessage({
id: 'Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.placeholder',
defaultMessage: 'Search AI Service Provider'
defaultMessage: 'Search AI/LLM Service Provider'
})}
helperText={(
<FormattedMessage
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.helper.text'
defaultMessage='Select AI Service Provider for the API'
defaultMessage='Select AI/LLM Service Provider for the API'
/>
)}
margin='dense'
Expand All @@ -193,7 +193,7 @@ export default function ProvideAIOpenAPI(props) {
fullWidth
id='AI-model-autocomplete'
options={llmProviders.list.filter((model) => model.name === selectedProvider)}
noOptionsText='No AI Service Provider selected'
noOptionsText='No AI/LLM Service Provider selected'
getOptionLabel={(option) =>
option.apiVersion
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export default function ProvideAIOpenAPI(props) {
) : (
<FormattedMessage
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.model.empty'
defaultMessage='No AI Service Provider selected.'
defaultMessage='No AI/LLM Service Provider selected.'
/>
)
}
Expand Down Expand Up @@ -280,8 +280,8 @@ export default function ProvideAIOpenAPI(props) {
<Grid item xs={12} sx={{ mb: 2 }}>
<Typography>
<FormattedMessage
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.empty'
defaultMessage='Loading AI Service Providers...'
id='Apis.Create.AIAPI.Steps.ProvideAIOpenAPI.AI.provider.loading'
defaultMessage='Loading AI/LLM Service Providers...'
/>
</Typography>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { isRestricted } from 'AppData/AuthManager';
import BackendRateLimitingForm from './BackendRateLimitingForm';

/**
* Backend Rate Limiting for AI APIs
* Backend Rate Limiting for AI/LLM APIs
*
* @export
* @param {*} props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import RequestCountRateLimit from './RequestCountRateLimit';
import RequestCountRateLimitUnit from './RequestCountRateLimitUnit';

/**
* Backend Rate Limiting for AI APIs
* Backend Rate Limiting for AI/LLM APIs
*
* @export
* @param {*} props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import ServiceEndpoint from './ServiceEndpoint';
import CustomBackend from './CustomBackend';
import { API_SECURITY_KEY_TYPE_PRODUCTION } from '../Configuration/components/APISecurity/components/apiSecurityConstants';
import { API_SECURITY_KEY_TYPE_SANDBOX } from '../Configuration/components/APISecurity/components/apiSecurityConstants';
import API from 'AppData/api';
import AIEndpointAuth from './AIEndpointAuth';

const PREFIX = 'EndpointOverview';
Expand Down Expand Up @@ -194,6 +193,7 @@ function EndpointOverview(props) {
setIsValidSequenceBackend,
isCustomBackendSelected,
setIsCustomBackendSelected,
apiKeyParamConfig,
} = props;
const { endpointConfig } = api;
const [endpointType, setEndpointType] = useState(endpointTypes[0]);
Expand All @@ -219,23 +219,6 @@ function EndpointOverview(props) {
(api.serviceInfo) });
const [servicesList, setServicesList] = useState([]);

const [apiKeyParamConfig, setApiKeyParamConfig] = useState({
authHeader: null,
authQueryParameter: null
});

useEffect(() => {
if (api.subtypeConfiguration?.subtype === 'AIAPI') {
API.getLLMProviderEndpointConfiguration(JSON.parse(api.subtypeConfiguration.configuration).llmProviderId)
.then((response) => {
if (response.body) {
const config = response.body;
setApiKeyParamConfig(config);
}
});
}
}, []);

const handleToggleEndpointSecurity = () => {
const tmpSecurityInfo = !endpointSecurityInfo ? {
production: CONSTS.DEFAULT_ENDPOINT_SECURITY,
Expand Down Expand Up @@ -409,7 +392,7 @@ function EndpointOverview(props) {
const endpointProp = 'production_endpoints';
if (endpointCategory[category]) {
delete endpointConfigCopy[endpointProp];
if (endpointConfigCopy?.endpoint_security?.production !== null) {
if (endpointConfigCopy?.endpoint_security?.production) {
delete endpointConfigCopy.endpoint_security.production;
}
if (endpointConfigCopy.endpointType === 'failover') {
Expand All @@ -427,7 +410,7 @@ function EndpointOverview(props) {
const endpointProp = 'sandbox_endpoints';
if (endpointCategory[category]) {
delete endpointConfigCopy[endpointProp];
if (endpointConfigCopy?.endpoint_security?.sandbox !== null) {
if (endpointConfigCopy?.endpoint_security?.sandbox) {
delete endpointConfigCopy.endpoint_security.sandbox;
}
if (endpointConfigCopy.endpointType === 'failover') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { APIContext } from 'AppComponents/Apis/Details/components/ApiContext';
import cloneDeep from 'lodash.clonedeep';
import { isRestricted } from 'AppData/AuthManager';
import { Alert } from 'AppComponents/Shared';

import API from 'AppData/api';
import EndpointOverview from './EndpointOverview';
import { createEndpointConfig, getEndpointTemplateByType } from './endpointUtils';
import { API_SECURITY_KEY_TYPE_PRODUCTION,
Expand Down Expand Up @@ -107,6 +109,22 @@ function Endpoints(props) {
const [productionBackendList, setProductionBackendList] = useState([]);
const [isValidSequenceBackend, setIsValidSequenceBackend] = useState(false);
const [isCustomBackendSelected, setIsCustomBackendSelected] = useState(false);
const [apiKeyParamConfig, setApiKeyParamConfig] = useState({
authHeader: null,
authQueryParameter: null
});

useEffect(() => {
if (api.subtypeConfiguration?.subtype === 'AIAPI') {
API.getLLMProviderEndpointConfiguration(JSON.parse(api.subtypeConfiguration.configuration).llmProviderId)
.then((response) => {
if (response.body) {
const config = response.body;
setApiKeyParamConfig(config);
}
});
}
}, []);

const apiReducer = (initState, configAction) => {
const tmpEndpointConfig = cloneDeep(initState.endpointConfig);
Expand Down Expand Up @@ -453,7 +471,7 @@ function Endpoints(props) {
}
}
} else if (production.type === 'apikey') {
if (production.apiKeyValue === null) {
if (production.apiKeyValue === null && endpointConfig.production_endpoints) {
return {
isValid: false,
message: intl.formatMessage({
Expand Down Expand Up @@ -507,7 +525,7 @@ function Endpoints(props) {
}
}
} else if (sandbox.type === 'apikey') {
if (sandbox.apiKeyValue === null) {
if (sandbox.apiKeyValue === null && endpointConfig.sandbox_endpoints) {
return {
isValid: false,
message: intl.formatMessage({
Expand All @@ -527,11 +545,12 @@ function Endpoints(props) {
}
}
} else if ((!endpointConfig || !endpointConfig.endpoint_security)
&& apiObject.subtypeConfiguration?.subtype === 'AIAPI' ) {
&& apiObject.subtypeConfiguration?.subtype === 'AIAPI'
&& (apiKeyParamConfig.authHeader || apiKeyParamConfig.authQueryParameter)) {
return {
isValid: false,
message: intl.formatMessage({
id: 'Apis.Details.Endpoints.Endpoints.missing.endpoint.error',
id: 'Apis.Details.Endpoints.Endpoints.missing.endpoint.ai.error',
defaultMessage: 'Production & Sandbox Endpoint Security should be added',
}),
};
Expand Down Expand Up @@ -734,6 +753,7 @@ function Endpoints(props) {
setIsValidSequenceBackend={setIsValidSequenceBackend}
isCustomBackendSelected={isCustomBackendSelected}
setIsCustomBackendSelected={setIsCustomBackendSelected}
apiKeyParamConfig={apiKeyParamConfig}
/>
</Grid>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ const APIDetailsTopMenu = (props) => {
>
<FormattedMessage
id='Apis.Details.components.APIDetailsTopMenu.ai.api.label'
defaultMessage='AI API'
defaultMessage='AI/LLM API'
/>
</MUIAlert>
)}
Expand Down
Loading
Loading