diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml index ab5b7fa0ceb7..e55e6865f9b6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/publisher-api.yaml @@ -10177,39 +10177,6 @@ components: type: string llmProviderApiVersion: type: string - throttlingConfiguration: - type: object - required: - - isTokenBasedThrottlingEnabled - properties: - productionMaxPromptTokenCount: - type: integer - description: "Maximum prompt token count for production" - format: int64 - productionMaxCompletionTokenCount: - type: integer - description: "Maximum completion token count for production" - format: int64 - productionMaxTotalTokenCount: - type: integer - description: "Maximum total token count for production" - format: int64 - sandboxMaxPromptTokenCount: - type: integer - description: "Maximum prompt token count for sandbox" - format: int64 - sandboxMaxCompletionTokenCount: - type: integer - description: "Maximum completion token count for sandbox" - format: int64 - sandboxMaxTotalTokenCount: - type: integer - description: "Maximum total token count for sandbox" - format: int64 - isTokenBasedThrottlingEnabled: - type: boolean - default: false - description: "Whether token-based throttling is enabled" scopes: type: array items: @@ -11821,7 +11788,7 @@ components: example: 1000 productionTimeUnit: type: string - description: "Time unit for the production in milliseconds. Possible values are 1sec, 1min, 1hour" + description: "Time unit for the production." default: SECOND enum: - SECOND @@ -11833,12 +11800,45 @@ components: example: 1000 sandboxTimeUnit: type: string - description: "Time unit for the sandbox in milliseconds. Possible values are 1sec, 1min, 1hour" + description: "Time unit for the sandbox." default: SECOND enum: - SECOND - MINUTE - HOUR + tokenBasedThrottlingConfiguration: + type: object + required: + - isTokenBasedThrottlingEnabled + properties: + productionMaxPromptTokenCount: + type: integer + description: "Maximum prompt token count for production" + format: int64 + productionMaxCompletionTokenCount: + type: integer + description: "Maximum completion token count for production" + format: int64 + productionMaxTotalTokenCount: + type: integer + description: "Maximum total token count for production" + format: int64 + sandboxMaxPromptTokenCount: + type: integer + description: "Maximum prompt token count for sandbox" + format: int64 + sandboxMaxCompletionTokenCount: + type: integer + description: "Maximum completion token count for sandbox" + format: int64 + sandboxMaxTotalTokenCount: + type: integer + description: "Maximum total token count for sandbox" + format: int64 + isTokenBasedThrottlingEnabled: + type: boolean + default: false + description: "Whether token-based throttling is enabled" APIBusinessInformation: type: object properties: diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationDTO.java index d78f08bcd479..e4aaf5bfe846 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationDTO.java @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIAiConfigurationThrottlingConfigurationDTO; import javax.validation.constraints.*; @@ -23,7 +22,6 @@ public class APIAiConfigurationDTO { private String llmProviderName = null; private String llmProviderApiVersion = null; - private APIAiConfigurationThrottlingConfigurationDTO throttlingConfiguration = null; /** **/ @@ -59,24 +57,6 @@ public void setLlmProviderApiVersion(String llmProviderApiVersion) { this.llmProviderApiVersion = llmProviderApiVersion; } - /** - **/ - public APIAiConfigurationDTO throttlingConfiguration(APIAiConfigurationThrottlingConfigurationDTO throttlingConfiguration) { - this.throttlingConfiguration = throttlingConfiguration; - return this; - } - - - @ApiModelProperty(value = "") - @Valid - @JsonProperty("throttlingConfiguration") - public APIAiConfigurationThrottlingConfigurationDTO getThrottlingConfiguration() { - return throttlingConfiguration; - } - public void setThrottlingConfiguration(APIAiConfigurationThrottlingConfigurationDTO throttlingConfiguration) { - this.throttlingConfiguration = throttlingConfiguration; - } - @Override public boolean equals(java.lang.Object o) { @@ -88,13 +68,12 @@ public boolean equals(java.lang.Object o) { } APIAiConfigurationDTO apIAiConfiguration = (APIAiConfigurationDTO) o; return Objects.equals(llmProviderName, apIAiConfiguration.llmProviderName) && - Objects.equals(llmProviderApiVersion, apIAiConfiguration.llmProviderApiVersion) && - Objects.equals(throttlingConfiguration, apIAiConfiguration.throttlingConfiguration); + Objects.equals(llmProviderApiVersion, apIAiConfiguration.llmProviderApiVersion); } @Override public int hashCode() { - return Objects.hash(llmProviderName, llmProviderApiVersion, throttlingConfiguration); + return Objects.hash(llmProviderName, llmProviderApiVersion); } @Override @@ -104,7 +83,6 @@ public String toString() { sb.append(" llmProviderName: ").append(toIndentedString(llmProviderName)).append("\n"); sb.append(" llmProviderApiVersion: ").append(toIndentedString(llmProviderApiVersion)).append("\n"); - sb.append(" throttlingConfiguration: ").append(toIndentedString(throttlingConfiguration)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsDTO.java index 8a47222723c2..8836148b5c1b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsDTO.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMaxTpsTokenBasedThrottlingConfigurationDTO; import javax.validation.constraints.*; @@ -88,6 +89,7 @@ public static SandboxTimeUnitEnum fromValue(String v) { } } private SandboxTimeUnitEnum sandboxTimeUnit = SandboxTimeUnitEnum.SECOND; + private APIMaxTpsTokenBasedThrottlingConfigurationDTO tokenBasedThrottlingConfiguration = null; /** **/ @@ -107,7 +109,7 @@ public void setProduction(Long production) { } /** - * Time unit for the production in milliseconds. Possible values are 1sec, 1min, 1hour + * Time unit for the production. **/ public APIMaxTpsDTO productionTimeUnit(ProductionTimeUnitEnum productionTimeUnit) { this.productionTimeUnit = productionTimeUnit; @@ -115,7 +117,7 @@ public APIMaxTpsDTO productionTimeUnit(ProductionTimeUnitEnum productionTimeUnit } - @ApiModelProperty(value = "Time unit for the production in milliseconds. Possible values are 1sec, 1min, 1hour") + @ApiModelProperty(value = "Time unit for the production.") @JsonProperty("productionTimeUnit") public ProductionTimeUnitEnum getProductionTimeUnit() { return productionTimeUnit; @@ -142,7 +144,7 @@ public void setSandbox(Long sandbox) { } /** - * Time unit for the sandbox in milliseconds. Possible values are 1sec, 1min, 1hour + * Time unit for the sandbox. **/ public APIMaxTpsDTO sandboxTimeUnit(SandboxTimeUnitEnum sandboxTimeUnit) { this.sandboxTimeUnit = sandboxTimeUnit; @@ -150,7 +152,7 @@ public APIMaxTpsDTO sandboxTimeUnit(SandboxTimeUnitEnum sandboxTimeUnit) { } - @ApiModelProperty(value = "Time unit for the sandbox in milliseconds. Possible values are 1sec, 1min, 1hour") + @ApiModelProperty(value = "Time unit for the sandbox.") @JsonProperty("sandboxTimeUnit") public SandboxTimeUnitEnum getSandboxTimeUnit() { return sandboxTimeUnit; @@ -159,6 +161,24 @@ public void setSandboxTimeUnit(SandboxTimeUnitEnum sandboxTimeUnit) { this.sandboxTimeUnit = sandboxTimeUnit; } + /** + **/ + public APIMaxTpsDTO tokenBasedThrottlingConfiguration(APIMaxTpsTokenBasedThrottlingConfigurationDTO tokenBasedThrottlingConfiguration) { + this.tokenBasedThrottlingConfiguration = tokenBasedThrottlingConfiguration; + return this; + } + + + @ApiModelProperty(value = "") + @Valid + @JsonProperty("tokenBasedThrottlingConfiguration") + public APIMaxTpsTokenBasedThrottlingConfigurationDTO getTokenBasedThrottlingConfiguration() { + return tokenBasedThrottlingConfiguration; + } + public void setTokenBasedThrottlingConfiguration(APIMaxTpsTokenBasedThrottlingConfigurationDTO tokenBasedThrottlingConfiguration) { + this.tokenBasedThrottlingConfiguration = tokenBasedThrottlingConfiguration; + } + @Override public boolean equals(java.lang.Object o) { @@ -172,12 +192,13 @@ public boolean equals(java.lang.Object o) { return Objects.equals(production, apIMaxTps.production) && Objects.equals(productionTimeUnit, apIMaxTps.productionTimeUnit) && Objects.equals(sandbox, apIMaxTps.sandbox) && - Objects.equals(sandboxTimeUnit, apIMaxTps.sandboxTimeUnit); + Objects.equals(sandboxTimeUnit, apIMaxTps.sandboxTimeUnit) && + Objects.equals(tokenBasedThrottlingConfiguration, apIMaxTps.tokenBasedThrottlingConfiguration); } @Override public int hashCode() { - return Objects.hash(production, productionTimeUnit, sandbox, sandboxTimeUnit); + return Objects.hash(production, productionTimeUnit, sandbox, sandboxTimeUnit, tokenBasedThrottlingConfiguration); } @Override @@ -189,6 +210,7 @@ public String toString() { sb.append(" productionTimeUnit: ").append(toIndentedString(productionTimeUnit)).append("\n"); sb.append(" sandbox: ").append(toIndentedString(sandbox)).append("\n"); sb.append(" sandboxTimeUnit: ").append(toIndentedString(sandboxTimeUnit)).append("\n"); + sb.append(" tokenBasedThrottlingConfiguration: ").append(toIndentedString(tokenBasedThrottlingConfiguration)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationThrottlingConfigurationDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsTokenBasedThrottlingConfigurationDTO.java similarity index 75% rename from components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationThrottlingConfigurationDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsTokenBasedThrottlingConfigurationDTO.java index 989b34f00343..00b1f0100463 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIAiConfigurationThrottlingConfigurationDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/gen/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/dto/APIMaxTpsTokenBasedThrottlingConfigurationDTO.java @@ -18,7 +18,7 @@ -public class APIAiConfigurationThrottlingConfigurationDTO { +public class APIMaxTpsTokenBasedThrottlingConfigurationDTO { private Long productionMaxPromptTokenCount = null; private Long productionMaxCompletionTokenCount = null; @@ -31,7 +31,7 @@ public class APIAiConfigurationThrottlingConfigurationDTO { /** * Maximum prompt token count for production **/ - public APIAiConfigurationThrottlingConfigurationDTO productionMaxPromptTokenCount(Long productionMaxPromptTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO productionMaxPromptTokenCount(Long productionMaxPromptTokenCount) { this.productionMaxPromptTokenCount = productionMaxPromptTokenCount; return this; } @@ -49,7 +49,7 @@ public void setProductionMaxPromptTokenCount(Long productionMaxPromptTokenCount) /** * Maximum completion token count for production **/ - public APIAiConfigurationThrottlingConfigurationDTO productionMaxCompletionTokenCount(Long productionMaxCompletionTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO productionMaxCompletionTokenCount(Long productionMaxCompletionTokenCount) { this.productionMaxCompletionTokenCount = productionMaxCompletionTokenCount; return this; } @@ -67,7 +67,7 @@ public void setProductionMaxCompletionTokenCount(Long productionMaxCompletionTok /** * Maximum total token count for production **/ - public APIAiConfigurationThrottlingConfigurationDTO productionMaxTotalTokenCount(Long productionMaxTotalTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO productionMaxTotalTokenCount(Long productionMaxTotalTokenCount) { this.productionMaxTotalTokenCount = productionMaxTotalTokenCount; return this; } @@ -85,7 +85,7 @@ public void setProductionMaxTotalTokenCount(Long productionMaxTotalTokenCount) { /** * Maximum prompt token count for sandbox **/ - public APIAiConfigurationThrottlingConfigurationDTO sandboxMaxPromptTokenCount(Long sandboxMaxPromptTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO sandboxMaxPromptTokenCount(Long sandboxMaxPromptTokenCount) { this.sandboxMaxPromptTokenCount = sandboxMaxPromptTokenCount; return this; } @@ -103,7 +103,7 @@ public void setSandboxMaxPromptTokenCount(Long sandboxMaxPromptTokenCount) { /** * Maximum completion token count for sandbox **/ - public APIAiConfigurationThrottlingConfigurationDTO sandboxMaxCompletionTokenCount(Long sandboxMaxCompletionTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO sandboxMaxCompletionTokenCount(Long sandboxMaxCompletionTokenCount) { this.sandboxMaxCompletionTokenCount = sandboxMaxCompletionTokenCount; return this; } @@ -121,7 +121,7 @@ public void setSandboxMaxCompletionTokenCount(Long sandboxMaxCompletionTokenCoun /** * Maximum total token count for sandbox **/ - public APIAiConfigurationThrottlingConfigurationDTO sandboxMaxTotalTokenCount(Long sandboxMaxTotalTokenCount) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO sandboxMaxTotalTokenCount(Long sandboxMaxTotalTokenCount) { this.sandboxMaxTotalTokenCount = sandboxMaxTotalTokenCount; return this; } @@ -139,7 +139,7 @@ public void setSandboxMaxTotalTokenCount(Long sandboxMaxTotalTokenCount) { /** * Whether token-based throttling is enabled **/ - public APIAiConfigurationThrottlingConfigurationDTO isTokenBasedThrottlingEnabled(Boolean isTokenBasedThrottlingEnabled) { + public APIMaxTpsTokenBasedThrottlingConfigurationDTO isTokenBasedThrottlingEnabled(Boolean isTokenBasedThrottlingEnabled) { this.isTokenBasedThrottlingEnabled = isTokenBasedThrottlingEnabled; return this; } @@ -164,14 +164,14 @@ public boolean equals(java.lang.Object o) { if (o == null || getClass() != o.getClass()) { return false; } - APIAiConfigurationThrottlingConfigurationDTO apIAiConfigurationThrottlingConfiguration = (APIAiConfigurationThrottlingConfigurationDTO) o; - return Objects.equals(productionMaxPromptTokenCount, apIAiConfigurationThrottlingConfiguration.productionMaxPromptTokenCount) && - Objects.equals(productionMaxCompletionTokenCount, apIAiConfigurationThrottlingConfiguration.productionMaxCompletionTokenCount) && - Objects.equals(productionMaxTotalTokenCount, apIAiConfigurationThrottlingConfiguration.productionMaxTotalTokenCount) && - Objects.equals(sandboxMaxPromptTokenCount, apIAiConfigurationThrottlingConfiguration.sandboxMaxPromptTokenCount) && - Objects.equals(sandboxMaxCompletionTokenCount, apIAiConfigurationThrottlingConfiguration.sandboxMaxCompletionTokenCount) && - Objects.equals(sandboxMaxTotalTokenCount, apIAiConfigurationThrottlingConfiguration.sandboxMaxTotalTokenCount) && - Objects.equals(isTokenBasedThrottlingEnabled, apIAiConfigurationThrottlingConfiguration.isTokenBasedThrottlingEnabled); + APIMaxTpsTokenBasedThrottlingConfigurationDTO apIMaxTpsTokenBasedThrottlingConfiguration = (APIMaxTpsTokenBasedThrottlingConfigurationDTO) o; + return Objects.equals(productionMaxPromptTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.productionMaxPromptTokenCount) && + Objects.equals(productionMaxCompletionTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.productionMaxCompletionTokenCount) && + Objects.equals(productionMaxTotalTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.productionMaxTotalTokenCount) && + Objects.equals(sandboxMaxPromptTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.sandboxMaxPromptTokenCount) && + Objects.equals(sandboxMaxCompletionTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.sandboxMaxCompletionTokenCount) && + Objects.equals(sandboxMaxTotalTokenCount, apIMaxTpsTokenBasedThrottlingConfiguration.sandboxMaxTotalTokenCount) && + Objects.equals(isTokenBasedThrottlingEnabled, apIMaxTpsTokenBasedThrottlingConfiguration.isTokenBasedThrottlingEnabled); } @Override @@ -182,7 +182,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class APIAiConfigurationThrottlingConfigurationDTO {\n"); + sb.append("class APIMaxTpsTokenBasedThrottlingConfigurationDTO {\n"); sb.append(" productionMaxPromptTokenCount: ").append(toIndentedString(productionMaxPromptTokenCount)).append("\n"); sb.append(" productionMaxCompletionTokenCount: ").append(toIndentedString(productionMaxCompletionTokenCount)).append("\n"); diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java index fd28c70d51f3..5804fb64cb86 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/APIMappingUtil.java @@ -37,6 +37,7 @@ import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.WorkflowStatus; import org.wso2.carbon.apimgt.api.dto.APIEndpointValidationDTO; +import org.wso2.carbon.apimgt.api.model.AIConfiguration; import org.wso2.carbon.apimgt.api.model.API; import org.wso2.carbon.apimgt.api.model.APICategory; import org.wso2.carbon.apimgt.api.model.APIIdentifier; @@ -78,6 +79,7 @@ import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIListDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMaxTpsDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMaxTpsTokenBasedThrottlingConfigurationDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMetadataDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMetadataListDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMonetizationInfoDTO; @@ -146,6 +148,7 @@ import static org.wso2.carbon.apimgt.impl.utils.APIUtil.getDefaultWebsubSubscriptionConfiguration; import static org.wso2.carbon.apimgt.impl.utils.APIUtil.handleException; +import static org.wso2.carbon.apimgt.rest.api.publisher.v1.common.mappings.PublisherCommonUtils.buildThrottlingConfigurationDTO; /** * This class used for mapping utility to API. @@ -467,7 +470,8 @@ public static API fromDTOtoAPI(APIDTO dto, String provider) throws APIManagement model.setAsyncTransportProtocols(asyncTransports); } if (dto.getAiConfiguration() != null) { - model.setAiConfiguration(PublisherCommonUtils.convertToAiConfiguration(dto.getAiConfiguration())); + model.setAiConfiguration( + PublisherCommonUtils.convertToAiConfiguration(dto.getAiConfiguration(), dto.getMaxTps())); } return model; } @@ -1649,6 +1653,13 @@ private static void setMaxTpsFromModelToApiDTO(API api, APIDTO dto) { maxTpsDTO.setSandboxTimeUnit(APIMaxTpsDTO.SandboxTimeUnitEnum.valueOf( convertFromMilliseconds(api.getSandboxTimeUnit()))); } + AIConfiguration aiConfiguration = api.getAiConfiguration(); + if (aiConfiguration.getTokenBasedThrottlingConfiguration() != null + && aiConfiguration.getTokenBasedThrottlingConfiguration().isTokenBasedThrottlingEnabled()) { + APIMaxTpsTokenBasedThrottlingConfigurationDTO throttlingConfigurationsDTO + = buildThrottlingConfigurationDTO(aiConfiguration.getTokenBasedThrottlingConfiguration()); + maxTpsDTO.setTokenBasedThrottlingConfiguration(throttlingConfigurationsDTO); + } dto.setMaxTps(maxTpsDTO); } catch (NumberFormatException e) { //logs the error and continues as this is not a blocker diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java index 73f49d5fa245..aec3f04df15d 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1.common/src/main/java/org/wso2/carbon/apimgt/rest/api/publisher/v1/common/mappings/PublisherCommonUtils.java @@ -80,10 +80,11 @@ import org.wso2.carbon.apimgt.rest.api.common.RestApiConstants; import org.wso2.carbon.apimgt.rest.api.common.annotations.Scope; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIAiConfigurationDTO; -import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIAiConfigurationThrottlingConfigurationDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIInfoAdditionalPropertiesMapDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMaxTpsDTO; +import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIMaxTpsTokenBasedThrottlingConfigurationDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIOperationsDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.APIProductDTO; import org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.AdvertiseInfoDTO; @@ -1485,7 +1486,7 @@ public static API prepareToCreateAPIByDTO(APIDTO body, APIProvider apiProvider, apiToAdd.setOrganization(organization); apiToAdd.setGatewayType(body.getGatewayType()); if (body.getAiConfiguration() != null) { - apiToAdd.setAiConfiguration(convertToAiConfiguration(body.getAiConfiguration())); + apiToAdd.setAiConfiguration(convertToAiConfiguration(body.getAiConfiguration(), body.getMaxTps())); apiToAdd.setSubtype(APIConstants.API_SUBTYPE_AI_API); } else { apiToAdd.setSubtype(APIConstants.API_SUBTYPE_DEFAULT); @@ -1501,14 +1502,14 @@ public static API prepareToCreateAPIByDTO(APIDTO body, APIProvider apiProvider, * @return The converted AIConfiguration object. * @throws APIManagementException If an error occurs during the conversion. */ - public static AIConfiguration convertToAiConfiguration(APIAiConfigurationDTO dto) { + public static AIConfiguration convertToAiConfiguration(APIAiConfigurationDTO dto, APIMaxTpsDTO maxTpsDTO) { AIConfiguration aiConfiguration = new AIConfiguration(); aiConfiguration.setLlmProviderName(dto.getLlmProviderName()); aiConfiguration.setLlmProviderApiVersion(dto.getLlmProviderApiVersion()); - if (dto.getThrottlingConfiguration() != null - && dto.getThrottlingConfiguration().isIsTokenBasedThrottlingEnabled()) { - TokenBaseThrottlingCountHolder throttlingConfig = buildThrottlingConfiguration(dto); + if (maxTpsDTO != null + && maxTpsDTO.getTokenBasedThrottlingConfiguration().isIsTokenBasedThrottlingEnabled()) { + TokenBaseThrottlingCountHolder throttlingConfig = buildThrottlingConfiguration(maxTpsDTO); aiConfiguration.setTokenBasedThrottlingConfiguration(throttlingConfig); } @@ -1521,9 +1522,9 @@ public static AIConfiguration convertToAiConfiguration(APIAiConfigurationDTO dto * @param dto The APIAiConfigurationDTO to extract data from. * @return The TokenBaseThrottlingCountHolder object. */ - private static TokenBaseThrottlingCountHolder buildThrottlingConfiguration(APIAiConfigurationDTO dto) { + private static TokenBaseThrottlingCountHolder buildThrottlingConfiguration(APIMaxTpsDTO dto) { - APIAiConfigurationThrottlingConfigurationDTO throttlingConfigDTO = dto.getThrottlingConfiguration(); + APIMaxTpsTokenBasedThrottlingConfigurationDTO throttlingConfigDTO = dto.getTokenBasedThrottlingConfiguration(); TokenBaseThrottlingCountHolder throttlingConfig = new TokenBaseThrottlingCountHolder(); if (throttlingConfigDTO.getProductionMaxPromptTokenCount() != null) { @@ -1567,12 +1568,6 @@ public static APIAiConfigurationDTO convertToApiAiConfigurationDTO(AIConfigurati APIAiConfigurationDTO dto = new APIAiConfigurationDTO(); dto.setLlmProviderName(aiConfiguration.getLlmProviderName()); dto.setLlmProviderApiVersion(aiConfiguration.getLlmProviderApiVersion()); - if (aiConfiguration.getTokenBasedThrottlingConfiguration() != null) { - APIAiConfigurationThrottlingConfigurationDTO throttlingConfigurationsDTO = - buildThrottlingConfigurationDTO(aiConfiguration.getTokenBasedThrottlingConfiguration()); - dto.setThrottlingConfiguration(throttlingConfigurationsDTO); - } - return dto; } @@ -1581,11 +1576,11 @@ public static APIAiConfigurationDTO convertToApiAiConfigurationDTO(AIConfigurati * * @return The built APIAiConfigurationThrottlingConfigurationDTO object. */ - private static APIAiConfigurationThrottlingConfigurationDTO buildThrottlingConfigurationDTO( + public static APIMaxTpsTokenBasedThrottlingConfigurationDTO buildThrottlingConfigurationDTO( TokenBaseThrottlingCountHolder throttlingConfig) { - APIAiConfigurationThrottlingConfigurationDTO throttlingConfigurationsDTO = - new APIAiConfigurationThrottlingConfigurationDTO(); + APIMaxTpsTokenBasedThrottlingConfigurationDTO throttlingConfigurationsDTO = + new APIMaxTpsTokenBasedThrottlingConfigurationDTO(); try { if (throttlingConfig.getProductionMaxPromptTokenCount() != null) { throttlingConfigurationsDTO.setProductionMaxPromptTokenCount( diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml index ab5b7fa0ceb7..e55e6865f9b6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.publisher.v1/src/main/resources/publisher-api.yaml @@ -10177,39 +10177,6 @@ components: type: string llmProviderApiVersion: type: string - throttlingConfiguration: - type: object - required: - - isTokenBasedThrottlingEnabled - properties: - productionMaxPromptTokenCount: - type: integer - description: "Maximum prompt token count for production" - format: int64 - productionMaxCompletionTokenCount: - type: integer - description: "Maximum completion token count for production" - format: int64 - productionMaxTotalTokenCount: - type: integer - description: "Maximum total token count for production" - format: int64 - sandboxMaxPromptTokenCount: - type: integer - description: "Maximum prompt token count for sandbox" - format: int64 - sandboxMaxCompletionTokenCount: - type: integer - description: "Maximum completion token count for sandbox" - format: int64 - sandboxMaxTotalTokenCount: - type: integer - description: "Maximum total token count for sandbox" - format: int64 - isTokenBasedThrottlingEnabled: - type: boolean - default: false - description: "Whether token-based throttling is enabled" scopes: type: array items: @@ -11821,7 +11788,7 @@ components: example: 1000 productionTimeUnit: type: string - description: "Time unit for the production in milliseconds. Possible values are 1sec, 1min, 1hour" + description: "Time unit for the production." default: SECOND enum: - SECOND @@ -11833,12 +11800,45 @@ components: example: 1000 sandboxTimeUnit: type: string - description: "Time unit for the sandbox in milliseconds. Possible values are 1sec, 1min, 1hour" + description: "Time unit for the sandbox." default: SECOND enum: - SECOND - MINUTE - HOUR + tokenBasedThrottlingConfiguration: + type: object + required: + - isTokenBasedThrottlingEnabled + properties: + productionMaxPromptTokenCount: + type: integer + description: "Maximum prompt token count for production" + format: int64 + productionMaxCompletionTokenCount: + type: integer + description: "Maximum completion token count for production" + format: int64 + productionMaxTotalTokenCount: + type: integer + description: "Maximum total token count for production" + format: int64 + sandboxMaxPromptTokenCount: + type: integer + description: "Maximum prompt token count for sandbox" + format: int64 + sandboxMaxCompletionTokenCount: + type: integer + description: "Maximum completion token count for sandbox" + format: int64 + sandboxMaxTotalTokenCount: + type: integer + description: "Maximum total token count for sandbox" + format: int64 + isTokenBasedThrottlingEnabled: + type: boolean + default: false + description: "Whether token-based throttling is enabled" APIBusinessInformation: type: object properties: