Skip to content

Commit

Permalink
Feat/add ai rate limit schema (#1343)
Browse files Browse the repository at this point in the history
* feat: added ai rate limit plugins schemas

This PR adds a schema for the AI rate limiting plugin and the models provider field

* feat: added ai rate limit plugins schemas

* feat(n): add logo for new AI Rate Limiting Plugin [KM-92]

add logo for new AI Rate Limiting Plugins
  • Loading branch information
AntoineJac authored Apr 19, 2024
1 parent 504eeec commit d57ac6a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/entities/entities-plugins/fixtures/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ export const kmAvailablePlugins = {
version: '3.6.0',
priority: 777,
},
'ai-rate-limiting-advanced': {
version: '3.7.0',
priority: 905,
},
'ai-prompt-template': {
version: '3.6.0',
priority: 773,
Expand Down Expand Up @@ -441,6 +445,7 @@ export const kongPluginNames = [
'ai-proxy',
'ai-request-transformer',
'ai-response-transformer',
'ai-rate-limiting-advanced',
'app-dynamics',
'aws-lambda',
'azure-functions',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { customFields, getSharedFormName } from '@kong-ui-public/forms'
import { PLUGIN_METADATA } from '../definitions/metadata'
import { aiPromptDecoratorSchema } from '../definitions/schemas/AIPromptDecorator'
import { aiPromptTemplateSchema } from '../definitions/schemas/AIPromptTemplate'
import { aiRateLimitingAdvancedSchema } from '../definitions/schemas/AIRateLimitingAdvanced'
import { applicationRegistrationSchema } from '../definitions/schemas/ApplicationRegistration'
import { ArrayStringFieldSchema } from '../definitions/schemas/ArrayStringFieldSchema'
import { dataDogSchema } from '../definitions/schemas/Datadog'
Expand Down Expand Up @@ -133,6 +134,10 @@ export const useSchemas = (entityId?: string, options?: UseSchemasOptions) => {
...aiPromptTemplateSchema,
},

'ai-rate-limiting-advanced': {
...aiRateLimitingAdvancedSchema,
},

'vault-auth': {
...vaultAuthSchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ export const PLUGIN_METADATA: Record<string, Omit<PluginMetaData<I18nMessageSour
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE],
useLegacyForm: true,
},
'ai-rate-limiting-advanced': {
descriptionKey: 'plugins.meta.ai-rate-limiting-advanced.description',
group: PluginGroup.TRAFFIC_CONTROL,
isEnterprise: true,
nameKey: 'plugins.meta.ai-rate-limiting-advanced.name',
scope: [PluginScope.GLOBAL, PluginScope.SERVICE, PluginScope.ROUTE, PluginScope.CONSUMER, PluginScope.CONSUMER_GROUP],
useLegacyForm: true,
},
'aws-lambda': {
descriptionKey: 'plugins.meta.aws-lambda.description',
group: PluginGroup.SERVERLESS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { AIRateLimitingAdvancedSchema } from '../../types/plugins/ai-rate-limiting-advanced'
import { arrayCardContainerFieldSchema } from './ArrayCardContainerFields'

export const aiRateLimitingAdvancedSchema: AIRateLimitingAdvancedSchema = {
'config-llm_providers': {
...arrayCardContainerFieldSchema,
newElementButtonLabel: '+ Add Provider',
items: {
type: 'object',
schema: {
fields: [{
label: 'Window Size',
model: 'window_size',
help: 'Window size to apply a limit to (defined in seconds)',
type: 'input',
inputType: 'number',
}, {
label: 'Name',
model: 'name',
help: 'The llm providers.',
type: 'select',
values: [
'anthropic',
'azure',
'cohere',
'llama2',
'mistral',
'openai',
'requestPrompt',
],
}, {
label: 'Limit',
model: 'limit',
help: 'Limit applied to the llm provider.',
type: 'input',
inputType: 'number',
}],
},
},
},
}
4 changes: 4 additions & 0 deletions packages/entities/entities-plugins/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@
"name": "AI Response Transformer",
"description": "Use an LLM to transform API responses from the upstream service, before returning to the user."
},
"ai-rate-limiting-advanced": {
"name": "AI Rate Limiting Advanced",
"description": "Provides rate limiting for the providers used by any AI plugins."
},
"aws-lambda": {
"name": "AWS Lambda",
"description": "Invoke and manage AWS Lambda functions from Kong"
Expand Down
2 changes: 2 additions & 0 deletions packages/entities/entities-plugins/src/types/plugin-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { RateLimitingSchema } from './plugins/rate-limiting'
import type { RouteByHeaderSchema } from './plugins/route-by-header'
import type { AIPromptDecoratorSchema } from './plugins/ai-prompt-decorator'
import type { AIPromptTemplateSchema } from './plugins/ai-prompt-template'
import type { AIRateLimitingAdvancedSchema } from './plugins/ai-rate-limiting-advanced'
import type { VaultAuthSchema } from './plugins/vault-auth'
import type { GraphQLRateLimitingAdvancedSchema } from './plugins/graphql-rate-limiting-advanced'
import type { SAMLSchema } from './plugins/saml'
Expand Down Expand Up @@ -205,6 +206,7 @@ export interface CustomSchemas {
'route-by-header': RouteByHeaderSchema
'ai-prompt-decorator': AIPromptDecoratorSchema
'ai-prompt-template': AIPromptTemplateSchema
'ai-rate-limiting-advanced': AIRateLimitingAdvancedSchema
'vault-auth': VaultAuthSchema
'graphql-rate-limiting-advanced': GraphQLRateLimitingAdvancedSchema
'response-ratelimiting': RateLimitingSchema
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Field, ItemsSchema, CommonSchemaFields } from './shared'

type FieldForKeyValuePairs = Field & {
newElementButtonLabelClasses?: string
newElementButtonLabel?: string
keyInputPlaceholder?: string
valueInputPlaceholder?: string
}

type ItemsSchemaForKeyValuePairs = Omit<ItemsSchema, 'schema'> & {
schema: {
fields: FieldForKeyValuePairs[]
}
}

export interface AIRateLimitingAdvancedSchema extends CommonSchemaFields {
'config-llm_providers': {
type: string
showRemoveButton: boolean
newElementButtonLabelClasses: string
itemContainerComponent: string
fieldClasses: string

newElementButtonLabel: string
items: ItemsSchemaForKeyValuePairs
}
}

0 comments on commit d57ac6a

Please sign in to comment.