From 73a871c9a83671f014fa83a4f0fe366075954936 Mon Sep 17 00:00:00 2001 From: Savindu Dimal Date: Thu, 5 Sep 2024 14:51:20 +0530 Subject: [PATCH] Refactor code Rename class names and variables to be more meaningful --- ...AIQuotaLimit.java => AIAPIQuotaLimit.java} | 26 +++---- .../api/model/policy/PolicyConstants.java | 4 +- .../apimgt/impl/ThrottlePolicyConstants.java | 4 +- .../carbon/apimgt/impl/dao/ApiMgtDAO.java | 40 +++++----- .../impl/dao/SubscriptionValidationDAO.java | 24 +++--- .../impl/dao/constants/SQLConstants.java | 20 ++--- .../SubscriptionValidationSQLConstants.java | 12 +-- .../carbon/apimgt/impl/utils/APIUtil.java | 19 +++-- ...aLimitDTO.java => AIAPIQuotaLimitDTO.java} | 72 ++++++++--------- .../service/dto/ThrottleLimitDTO.java | 24 +++--- .../utils/SubscriptionValidationDataUtil.java | 34 ++++---- .../src/main/resources/api.yaml | 16 ++-- .../swagger.json | 41 +++++++++- ...fDTO.java => AIAPIQuotaLimitAllOfDTO.java} | 68 ++++++++-------- ...aLimitDTO.java => AIAPIQuotaLimitDTO.java} | 78 +++++++++---------- .../api/admin/v1/dto/ThrottleLimitDTO.java | 30 +++---- .../v1/impl/ThrottlingApiServiceImpl.java | 6 +- .../api/admin/v1/utils/RestApiAdminUtils.java | 22 +++--- .../throttling/CommonThrottleMappingUtil.java | 68 ++++++++-------- ...SubscriptionThrottlePolicyMappingUtil.java | 22 ++++-- .../src/main/resources/admin-api.yaml | 33 ++++---- .../src/main/resources/admin-api.yaml | 33 ++++---- ...AIQuotaLimit.java => AIAPIQuotaLimit.java} | 22 +++--- .../policy/deployer/dto/QuotaPolicy.java | 14 ++-- .../utils/ThrottlePolicyTemplateBuilder.java | 2 +- .../throttle_policy_template_ai_sub.xml | 14 ++-- 26 files changed, 396 insertions(+), 352 deletions(-) rename components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/{AIQuotaLimit.java => AIAPIQuotaLimit.java} (67%) rename components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/{AIQuotaLimitDTO.java => AIAPIQuotaLimitDTO.java} (64%) rename components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/{AIQuotaLimitAllOfDTO.java => AIAPIQuotaLimitAllOfDTO.java} (50%) rename components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/{AIQuotaLimitDTO.java => AIAPIQuotaLimitDTO.java} (59%) rename components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/{AIQuotaLimit.java => AIAPIQuotaLimit.java} (71%) diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIQuotaLimit.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIAPIQuotaLimit.java similarity index 67% rename from components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIQuotaLimit.java rename to components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIAPIQuotaLimit.java index 2eb8ae9b5e1a..b3e929d55b5e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIQuotaLimit.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/AIAPIQuotaLimit.java @@ -18,11 +18,11 @@ package org.wso2.carbon.apimgt.api.model.policy; -public class AIQuotaLimit extends Limit { +public class AIAPIQuotaLimit extends Limit { private long requestCount; private long totalTokenCount; - private long requestTokenCount; - private long responseTokenCount; + private long promptTokenCount; + private long completionTokenCount; public long getRequestCount() { return requestCount; @@ -40,26 +40,26 @@ public void setTotalTokenCount(long totalTokenCount) { this.totalTokenCount = totalTokenCount; } - public long getRequestTokenCount() { - return requestTokenCount; + public long getPromptTokenCount() { + return promptTokenCount; } - public void setRequestTokenCount(long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public void setPromptTokenCount(long promptTokenCount) { + this.promptTokenCount = promptTokenCount; } - public long getResponseTokenCount() { - return responseTokenCount; + public long getCompletionTokenCount() { + return completionTokenCount; } - public void setResponseTokenCount(long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public void setCompletionTokenCount(long completionTokenCount) { + this.completionTokenCount = completionTokenCount; } @Override public String toString() { - return "RequestCountLimit [requestCount=" + requestCount + ",totalTokenCount=" + totalTokenCount - + ", requestTokenCount=" + requestTokenCount + ", responseTokenCount=" + responseTokenCount + return "RequestCountLimit [requestCount=" + requestCount + ", totalTokenCount=" + totalTokenCount + + ", promptTokenCount=" + promptTokenCount + ", completionTokenCount=" + completionTokenCount + ", toString()=" + super.toString() + "]"; } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/PolicyConstants.java b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/PolicyConstants.java index b828a9e9c52c..760302f6ff7e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/PolicyConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/model/policy/PolicyConstants.java @@ -42,9 +42,9 @@ public class PolicyConstants { public static final String EVENT_COUNT_TYPE = "eventCount"; - public static final String AI_QUOTA_TYPE = "aiQuota"; + public static final String AI_API_QUOTA_TYPE = "aiApiQuota"; - public static final String AI_QUOTA_TYPE_ENUM_VALUE = "AIQUOTALIMIT"; + public static final String AI_API_QUOTA_TYPE_ENUM_VALUE = "AIAPIQUOTALIMIT"; public static final String DATE_QUERY = "date"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ThrottlePolicyConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ThrottlePolicyConstants.java index 64afdb477848..ebef1dbf2558 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ThrottlePolicyConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/ThrottlePolicyConstants.java @@ -54,9 +54,9 @@ public class ThrottlePolicyConstants { public static final String COLUMN_TOTAL_TOKEN_COUNT = "TOTAL_TOKEN_COUNT"; - public static final String COLUMN_REQUEST_TOKEN_COUNT = "REQUEST_TOKEN_COUNT"; + public static final String COLUMN_PROMPT_TOKEN_COUNT = "PROMPT_TOKEN_COUNT"; - public static final String COLUMN_RESPONSE_TOKEN_COUNT = "RESPONSE_TOKEN_COUNT"; + public static final String COLUMN_COMPLETION_TOKEN_COUNT = "COMPLETION_TOKEN_COUNT"; public static final String COLUMN_APPLICABLE_LEVEL = "APPLICABLE_LEVEL"; diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java index 2433e0f59f81..3a4e843eaf54 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/ApiMgtDAO.java @@ -88,7 +88,7 @@ import org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData; import org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.CustomComplexityDetails; import org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.APIPolicy; import org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; @@ -11452,11 +11452,11 @@ public void addSubscriptionPolicy(SubscriptionPolicy policy) throws APIManagemen policyStatement.setInt(15, policy.getGraphQLMaxDepth()); policyStatement.setInt(16, policy.getGraphQLMaxComplexity()); policyStatement.setString(17, policy.getBillingPlan()); - if (PolicyConstants.AI_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { - AIQuotaLimit limit = (AIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); + if (PolicyConstants.AI_API_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { + AIAPIQuotaLimit limit = (AIAPIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); policyStatement.setLong(18, limit.getTotalTokenCount()); - policyStatement.setLong(19, limit.getRequestTokenCount()); - policyStatement.setLong(20, limit.getResponseTokenCount()); + policyStatement.setLong(19, limit.getPromptTokenCount()); + policyStatement.setLong(20, limit.getCompletionTokenCount()); } else { policyStatement.setLong(18, 0); policyStatement.setLong(19, 0); @@ -13114,13 +13114,13 @@ public void updateSubscriptionPolicy(SubscriptionPolicy policy) throws APIManage updateStatement.setLong(6, 0); updateStatement.setLong(7, 0); updateStatement.setLong(8, 0); - } else if (PolicyConstants.AI_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { - AIQuotaLimit limit = (AIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { + AIAPIQuotaLimit limit = (AIAPIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); updateStatement.setLong(4, limit.getRequestCount()); updateStatement.setString(5, null); updateStatement.setLong(6, limit.getTotalTokenCount()); - updateStatement.setLong(7, limit.getRequestTokenCount()); - updateStatement.setLong(8, limit.getResponseTokenCount()); + updateStatement.setLong(7, limit.getPromptTokenCount()); + updateStatement.setLong(8, limit.getCompletionTokenCount()); } updateStatement.setLong(9, policy.getDefaultQuotaPolicy().getLimit().getUnitTime()); @@ -13398,8 +13398,8 @@ private void setCommonParametersForPolicy(PreparedStatement policyStatement, Pol EventCountLimit limit = (EventCountLimit) policy.getDefaultQuotaPolicy().getLimit(); policyStatement.setLong(6, limit.getEventCount()); policyStatement.setString(7, null); - } else if (PolicyConstants.AI_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { - AIQuotaLimit limit = (AIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equalsIgnoreCase(policy.getDefaultQuotaPolicy().getType())) { + AIAPIQuotaLimit limit = (AIAPIQuotaLimit) policy.getDefaultQuotaPolicy().getLimit(); policyStatement.setLong(6, limit.getRequestCount()); policyStatement.setString(7, null); } @@ -13463,15 +13463,15 @@ private void setCommonPolicyDetails(Policy policy, ResultSet resultSet) throws S eventCountLimit.setEventCount(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_QUOTA)); quotaPolicy.setLimit(eventCountLimit); } else if (resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_QUOTA_POLICY_TYPE) - .equalsIgnoreCase(PolicyConstants.AI_QUOTA_TYPE)) { - AIQuotaLimit aiQuotaLimit = new AIQuotaLimit(); - aiQuotaLimit.setUnitTime(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_UNIT_TIME)); - aiQuotaLimit.setTimeUnit(resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_TIME_UNIT)); - aiQuotaLimit.setRequestCount(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_QUOTA)); - aiQuotaLimit.setTotalTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_TOTAL_TOKEN_COUNT)); - aiQuotaLimit.setRequestTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_REQUEST_TOKEN_COUNT)); - aiQuotaLimit.setResponseTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_RESPONSE_TOKEN_COUNT)); - quotaPolicy.setLimit(aiQuotaLimit); + .equalsIgnoreCase(PolicyConstants.AI_API_QUOTA_TYPE)) { + AIAPIQuotaLimit AIAPIQuotaLimit = new AIAPIQuotaLimit(); + AIAPIQuotaLimit.setUnitTime(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_UNIT_TIME)); + AIAPIQuotaLimit.setTimeUnit(resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_TIME_UNIT)); + AIAPIQuotaLimit.setRequestCount(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_QUOTA)); + AIAPIQuotaLimit.setTotalTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_TOTAL_TOKEN_COUNT)); + AIAPIQuotaLimit.setPromptTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_PROMPT_TOKEN_COUNT)); + AIAPIQuotaLimit.setCompletionTokenCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_COMPLETION_TOKEN_COUNT)); + quotaPolicy.setLimit(AIAPIQuotaLimit); } policy.setUUID(resultSet.getString(ThrottlePolicyConstants.COLUMN_UUID)); diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java index e320e1402166..ed6c32feb581 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/SubscriptionValidationDAO.java @@ -25,7 +25,7 @@ import org.wso2.carbon.apimgt.api.dto.ConditionDTO; import org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO; import org.wso2.carbon.apimgt.api.model.OperationPolicy; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; import org.wso2.carbon.apimgt.api.model.policy.EventCountLimit; import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants; @@ -1029,18 +1029,18 @@ private void setCommonProperties(Policy policy, ResultSet resultSet) throws SQLE eventCountLimit.setTimeUnit(resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_TIME_UNIT)); eventCountLimit.setUnitTime(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_UNIT_TIME)); quotaPolicy.setLimit(eventCountLimit); - } else if (PolicyConstants.AI_QUOTA_TYPE.equalsIgnoreCase(quotaPolicy.getType())) { - AIQuotaLimit aiQuotaLimit = new AIQuotaLimit(); - aiQuotaLimit.setUnitTime(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_UNIT_TIME)); - aiQuotaLimit.setTimeUnit(resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_TIME_UNIT)); - aiQuotaLimit.setRequestCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_QUOTA)); - aiQuotaLimit.setTotalTokenCount( + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equalsIgnoreCase(quotaPolicy.getType())) { + AIAPIQuotaLimit AIAPIQuotaLimit = new AIAPIQuotaLimit(); + AIAPIQuotaLimit.setUnitTime(resultSet.getInt(prefix + ThrottlePolicyConstants.COLUMN_UNIT_TIME)); + AIAPIQuotaLimit.setTimeUnit(resultSet.getString(prefix + ThrottlePolicyConstants.COLUMN_TIME_UNIT)); + AIAPIQuotaLimit.setRequestCount(resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_QUOTA)); + AIAPIQuotaLimit.setTotalTokenCount( resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_TOTAL_TOKEN_COUNT)); - aiQuotaLimit.setRequestTokenCount( - resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_REQUEST_TOKEN_COUNT)); - aiQuotaLimit.setResponseTokenCount( - resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_RESPONSE_TOKEN_COUNT)); - quotaPolicy.setLimit(aiQuotaLimit); + AIAPIQuotaLimit.setPromptTokenCount( + resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_PROMPT_TOKEN_COUNT)); + AIAPIQuotaLimit.setCompletionTokenCount( + resultSet.getLong(prefix + ThrottlePolicyConstants.COLUMN_COMPLETION_TOKEN_COUNT)); + quotaPolicy.setLimit(AIAPIQuotaLimit); } policy.setQuotaPolicy(quotaPolicy); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java index fdc903c45644..5ccca5d11b47 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SQLConstants.java @@ -2353,7 +2353,7 @@ public class SQLConstants { "INSERT INTO AM_POLICY_SUBSCRIPTION (NAME, DISPLAY_NAME, TENANT_ID, DESCRIPTION, QUOTA_TYPE, QUOTA, \n" + " QUOTA_UNIT, UNIT_TIME, TIME_UNIT, IS_DEPLOYED, UUID, RATE_LIMIT_COUNT, \n" + " RATE_LIMIT_TIME_UNIT,STOP_ON_QUOTA_REACH, MAX_DEPTH, MAX_COMPLEXITY, \n" + - " BILLING_PLAN, TOTAL_TOKEN_COUNT, REQUEST_TOKEN_COUNT, RESPONSE_TOKEN_COUNT, \n" + + " BILLING_PLAN, TOTAL_TOKEN_COUNT, PROMPT_TOKEN_COUNT, COMPLETION_TOKEN_COUNT, \n" + " MONETIZATION_PLAN,FIXED_RATE,BILLING_CYCLE,PRICE_PER_REQUEST,CURRENCY, \n" + " CONNECTIONS_COUNT) \n" + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; @@ -2361,7 +2361,7 @@ public class SQLConstants { "INSERT INTO AM_POLICY_SUBSCRIPTION (NAME, DISPLAY_NAME, TENANT_ID, DESCRIPTION, QUOTA_TYPE, QUOTA, \n" + " QUOTA_UNIT, UNIT_TIME, TIME_UNIT, IS_DEPLOYED, UUID, RATE_LIMIT_COUNT, \n" + " RATE_LIMIT_TIME_UNIT, STOP_ON_QUOTA_REACH, MAX_DEPTH, MAX_COMPLEXITY, \n" + - " BILLING_PLAN, TOTAL_TOKEN_COUNT, REQUEST_TOKEN_COUNT, RESPONSE_TOKEN_COUNT, CUSTOM_ATTRIBUTES, MONETIZATION_PLAN, \n" + + " BILLING_PLAN, TOTAL_TOKEN_COUNT, PROMPT_TOKEN_COUNT, COMPLETION_TOKEN_COUNT, CUSTOM_ATTRIBUTES, MONETIZATION_PLAN, \n" + " FIXED_RATE, BILLING_CYCLE, PRICE_PER_REQUEST, CURRENCY, CONNECTIONS_COUNT) \n" + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; @@ -2572,8 +2572,8 @@ public class SQLConstants { "QUOTA = ?, " + "QUOTA_UNIT = ?, " + "TOTAL_TOKEN_COUNT = ?, " + - "REQUEST_TOKEN_COUNT = ?, " + - "RESPONSE_TOKEN_COUNT = ?, " + + "PROMPT_TOKEN_COUNT = ?, " + + "COMPLETION_TOKEN_COUNT = ?, " + "UNIT_TIME = ?, " + "TIME_UNIT = ?, " + "RATE_LIMIT_COUNT = ?," + @@ -2599,8 +2599,8 @@ public class SQLConstants { "QUOTA = ?, " + "QUOTA_UNIT = ?, " + "TOTAL_TOKEN_COUNT = ?, " + - "REQUEST_TOKEN_COUNT = ?, " + - "RESPONSE_TOKEN_COUNT = ?, " + + "PROMPT_TOKEN_COUNT = ?, " + + "COMPLETION_TOKEN_COUNT = ?, " + "UNIT_TIME = ?, " + "TIME_UNIT = ?, " + "RATE_LIMIT_COUNT = ?," + @@ -2627,8 +2627,8 @@ public class SQLConstants { "QUOTA = ?, " + "QUOTA_UNIT = ?, " + "TOTAL_TOKEN_COUNT = ?, " + - "REQUEST_TOKEN_COUNT = ?, " + - "RESPONSE_TOKEN_COUNT = ?, " + + "PROMPT_TOKEN_COUNT = ?, " + + "COMPLETION_TOKEN_COUNT = ?, " + "UNIT_TIME = ?, " + "TIME_UNIT = ?, " + "RATE_LIMIT_COUNT = ?," + @@ -2654,8 +2654,8 @@ public class SQLConstants { "QUOTA = ?, " + "QUOTA_UNIT = ?, " + "TOTAL_TOKEN_COUNT = ?, " + - "REQUEST_TOKEN_COUNT = ?, " + - "RESPONSE_TOKEN_COUNT = ?, " + + "PROMPT_TOKEN_COUNT = ?, " + + "COMPLETION_TOKEN_COUNT = ?, " + "UNIT_TIME = ?, " + "TIME_UNIT = ?, " + "RATE_LIMIT_COUNT = ?," + diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java index f2ac43c4222a..6d4b167d4fb5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/dao/constants/SubscriptionValidationSQLConstants.java @@ -218,8 +218,8 @@ public class SubscriptionValidationSQLConstants { " APS.UNIT_TIME AS UNIT_TIME, " + " APS.TIME_UNIT AS TIME_UNIT, " + " APS.TOTAL_TOKEN_COUNT AS TOTAL_TOKEN_COUNT, " + - " APS.REQUEST_TOKEN_COUNT AS REQUEST_TOKEN_COUNT, " + - " APS.RESPONSE_TOKEN_COUNT AS RESPONSE_TOKEN_COUNT, " + + " APS.PROMPT_TOKEN_COUNT AS PROMPT_TOKEN_COUNT, " + + " APS.COMPLETION_TOKEN_COUNT AS COMPLETION_TOKEN_COUNT, " + " FROM " + " AM_POLICY_SUBSCRIPTION APS"; @@ -323,8 +323,8 @@ public class SubscriptionValidationSQLConstants { " APS.UNIT_TIME AS UNIT_TIME, " + " APS.TIME_UNIT AS TIME_UNIT, " + " APS.TOTAL_TOKEN_COUNT AS TOTAL_TOKEN_COUNT, " + - " APS.REQUEST_TOKEN_COUNT AS REQUEST_TOKEN_COUNT, " + - " APS.RESPONSE_TOKEN_COUNT AS RESPONSE_TOKEN_COUNT, " + + " APS.PROMPT_TOKEN_COUNT AS PROMPT_TOKEN_COUNT, " + + " APS.COMPLETION_TOKEN_COUNT AS COMPLETION_TOKEN_COUNT, " + " FROM " + " AM_POLICY_SUBSCRIPTION APS" + " WHERE " + @@ -347,8 +347,8 @@ public class SubscriptionValidationSQLConstants { " APS.UNIT_TIME AS UNIT_TIME, " + " APS.TIME_UNIT AS TIME_UNIT, " + " APS.TOTAL_TOKEN_COUNT AS TOTAL_TOKEN_COUNT, " + - " APS.REQUEST_TOKEN_COUNT AS REQUEST_TOKEN_COUNT, " + - " APS.RESPONSE_TOKEN_COUNT AS RESPONSE_TOKEN_COUNT, " + + " APS.PROMPT_TOKEN_COUNT AS PROMPT_TOKEN_COUNT, " + + " APS.COMPLETION_TOKEN_COUNT AS COMPLETION_TOKEN_COUNT, " + " FROM " + " AM_POLICY_SUBSCRIPTION APS" + " WHERE " + diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java index 984c666160a9..88d81c093cb6 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java @@ -85,7 +85,6 @@ import org.wso2.carbon.apimgt.api.NewPostLoginExecutor; import org.wso2.carbon.apimgt.api.OrganizationResolver; import org.wso2.carbon.apimgt.api.PasswordResolver; -import org.wso2.carbon.apimgt.api.ErrorHandler; import org.wso2.carbon.apimgt.api.doc.model.APIDefinition; import org.wso2.carbon.apimgt.api.doc.model.APIResource; import org.wso2.carbon.apimgt.api.doc.model.Operation; @@ -121,7 +120,7 @@ import org.wso2.carbon.apimgt.api.model.VHost; import org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration; import org.wso2.carbon.apimgt.api.model.graphql.queryanalysis.GraphqlComplexityInfo; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.APIPolicy; import org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; @@ -6482,11 +6481,11 @@ public static Map getTiersFromPolicies(String policyLevel, int ten tier.setRequestsPerMin(bandwidthLimit.getDataAmount()); tier.setRequestCount(bandwidthLimit.getDataAmount()); tier.setBandwidthDataUnit(bandwidthLimit.getDataUnit()); - } else if (limit instanceof AIQuotaLimit){ + } else if (limit instanceof AIAPIQuotaLimit){ // Todo: Need to implement this according to publisher and developer portals' requirements - AIQuotaLimit aiQuotaLimit = (AIQuotaLimit) limit; - tier.setRequestsPerMin(aiQuotaLimit.getRequestCount()); - tier.setRequestCount(aiQuotaLimit.getRequestCount()); + AIAPIQuotaLimit AIAPIQuotaLimit = (AIAPIQuotaLimit) limit; + tier.setRequestsPerMin(AIAPIQuotaLimit.getRequestCount()); + tier.setRequestCount(AIAPIQuotaLimit.getRequestCount()); } else { EventCountLimit eventCountLimit = (EventCountLimit) limit; tier.setRequestCount(eventCountLimit.getEventCount()); @@ -6565,11 +6564,11 @@ public static Tier getPolicyByName(String policyLevel, String policyName, String tier.setRequestsPerMin(bandwidthLimit.getDataAmount()); tier.setRequestCount(bandwidthLimit.getDataAmount()); tier.setBandwidthDataUnit(bandwidthLimit.getDataUnit()); - } else if (limit instanceof AIQuotaLimit) { + } else if (limit instanceof AIAPIQuotaLimit) { // Todo: Need to implement this according to publisher and developer portals' requirements - AIQuotaLimit aiQuotaLimit = (AIQuotaLimit) limit; - tier.setRequestsPerMin(aiQuotaLimit.getRequestCount()); - tier.setRequestCount(aiQuotaLimit.getRequestCount()); + AIAPIQuotaLimit AIAPIQuotaLimit = (AIAPIQuotaLimit) limit; + tier.setRequestsPerMin(AIAPIQuotaLimit.getRequestCount()); + tier.setRequestCount(AIAPIQuotaLimit.getRequestCount()); } else { EventCountLimit eventCountLimit = (EventCountLimit) limit; tier.setRequestCount(eventCountLimit.getEventCount()); diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIQuotaLimitDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIAPIQuotaLimitDTO.java similarity index 64% rename from components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIQuotaLimitDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIAPIQuotaLimitDTO.java index fc9b3d8e8f79..21be6964f5c9 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIQuotaLimitDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/AIAPIQuotaLimitDTO.java @@ -15,19 +15,19 @@ -public class AIQuotaLimitDTO { +public class AIAPIQuotaLimitDTO { private String timeUnit = null; private Integer unitTime = null; private Long requestCount = null; private Long totalTokenCount = null; - private Long requestTokenCount = null; - private Long responseTokenCount = null; + private Long promptTokenCount = null; + private Long completionTokenCount = null; /** * Unit of the time. Allowed values are \"sec\", \"min\", \"hour\", \"day\" **/ - public AIQuotaLimitDTO timeUnit(String timeUnit) { + public AIAPIQuotaLimitDTO timeUnit(String timeUnit) { this.timeUnit = timeUnit; return this; } @@ -46,7 +46,7 @@ public void setTimeUnit(String timeUnit) { /** * Time limit that the throttling limit applies. **/ - public AIQuotaLimitDTO unitTime(Integer unitTime) { + public AIAPIQuotaLimitDTO unitTime(Integer unitTime) { this.unitTime = unitTime; return this; } @@ -65,7 +65,7 @@ public void setUnitTime(Integer unitTime) { /** * Maximum number of requests allowed **/ - public AIQuotaLimitDTO requestCount(Long requestCount) { + public AIAPIQuotaLimitDTO requestCount(Long requestCount) { this.requestCount = requestCount; return this; } @@ -84,7 +84,7 @@ public void setRequestCount(Long requestCount) { /** * Maximum number of total tokens allowed **/ - public AIQuotaLimitDTO totalTokenCount(Long totalTokenCount) { + public AIAPIQuotaLimitDTO totalTokenCount(Long totalTokenCount) { this.totalTokenCount = totalTokenCount; return this; } @@ -100,39 +100,39 @@ public void setTotalTokenCount(Long totalTokenCount) { } /** - * Maximum number of request tokens allowed + * Maximum number of prompt tokens allowed **/ - public AIQuotaLimitDTO requestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public AIAPIQuotaLimitDTO promptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of request tokens allowed") - @JsonProperty("requestTokenCount") - public Long getRequestTokenCount() { - return requestTokenCount; + @ApiModelProperty(example = "300", value = "Maximum number of prompt tokens allowed") + @JsonProperty("promptTokenCount") + public Long getPromptTokenCount() { + return promptTokenCount; } - public void setRequestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public void setPromptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; } /** - * Maximum number of response tokens allowed + * Maximum number of completion tokens allowed **/ - public AIQuotaLimitDTO responseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public AIAPIQuotaLimitDTO completionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of response tokens allowed") - @JsonProperty("responseTokenCount") - public Long getResponseTokenCount() { - return responseTokenCount; + @ApiModelProperty(example = "300", value = "Maximum number of completion tokens allowed") + @JsonProperty("completionTokenCount") + public Long getCompletionTokenCount() { + return completionTokenCount; } - public void setResponseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public void setCompletionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; } @@ -144,31 +144,31 @@ public boolean equals(java.lang.Object o) { if (o == null || getClass() != o.getClass()) { return false; } - AIQuotaLimitDTO aiQuotaLimit = (AIQuotaLimitDTO) o; - return Objects.equals(timeUnit, aiQuotaLimit.timeUnit) && - Objects.equals(unitTime, aiQuotaLimit.unitTime) && - Objects.equals(requestCount, aiQuotaLimit.requestCount) && - Objects.equals(totalTokenCount, aiQuotaLimit.totalTokenCount) && - Objects.equals(requestTokenCount, aiQuotaLimit.requestTokenCount) && - Objects.equals(responseTokenCount, aiQuotaLimit.responseTokenCount); + AIAPIQuotaLimitDTO aiAPIQuotaLimit = (AIAPIQuotaLimitDTO) o; + return Objects.equals(timeUnit, aiAPIQuotaLimit.timeUnit) && + Objects.equals(unitTime, aiAPIQuotaLimit.unitTime) && + Objects.equals(requestCount, aiAPIQuotaLimit.requestCount) && + Objects.equals(totalTokenCount, aiAPIQuotaLimit.totalTokenCount) && + Objects.equals(promptTokenCount, aiAPIQuotaLimit.promptTokenCount) && + Objects.equals(completionTokenCount, aiAPIQuotaLimit.completionTokenCount); } @Override public int hashCode() { - return Objects.hash(timeUnit, unitTime, requestCount, totalTokenCount, requestTokenCount, responseTokenCount); + return Objects.hash(timeUnit, unitTime, requestCount, totalTokenCount, promptTokenCount, completionTokenCount); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class AIQuotaLimitDTO {\n"); + sb.append("class AIAPIQuotaLimitDTO {\n"); sb.append(" timeUnit: ").append(toIndentedString(timeUnit)).append("\n"); sb.append(" unitTime: ").append(toIndentedString(unitTime)).append("\n"); sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); sb.append(" totalTokenCount: ").append(toIndentedString(totalTokenCount)).append("\n"); - sb.append(" requestTokenCount: ").append(toIndentedString(requestTokenCount)).append("\n"); - sb.append(" responseTokenCount: ").append(toIndentedString(responseTokenCount)).append("\n"); + sb.append(" promptTokenCount: ").append(toIndentedString(promptTokenCount)).append("\n"); + sb.append(" completionTokenCount: ").append(toIndentedString(completionTokenCount)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/ThrottleLimitDTO.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/ThrottleLimitDTO.java index 0892e8ac222a..69c59ecf6563 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/ThrottleLimitDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/gen/java/org/wso2/carbon/apimgt/internal/service/dto/ThrottleLimitDTO.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonCreator; -import org.wso2.carbon.apimgt.internal.service.dto.AIQuotaLimitDTO; +import org.wso2.carbon.apimgt.internal.service.dto.AIAPIQuotaLimitDTO; import org.wso2.carbon.apimgt.internal.service.dto.BandwidthLimitDTO; import org.wso2.carbon.apimgt.internal.service.dto.EventCountLimitDTO; import org.wso2.carbon.apimgt.internal.service.dto.RequestCountLimitDTO; @@ -24,7 +24,7 @@ public class ThrottleLimitDTO { private RequestCountLimitDTO requestCount = null; private BandwidthLimitDTO bandwidth = null; private EventCountLimitDTO eventCount = null; - private AIQuotaLimitDTO aiQuota = null; + private AIAPIQuotaLimitDTO aiApiQuota = null; /** **/ @@ -96,19 +96,19 @@ public void setEventCount(EventCountLimitDTO eventCount) { /** **/ - public ThrottleLimitDTO aiQuota(AIQuotaLimitDTO aiQuota) { - this.aiQuota = aiQuota; + public ThrottleLimitDTO aiApiQuota(AIAPIQuotaLimitDTO aiApiQuota) { + this.aiApiQuota = aiApiQuota; return this; } @ApiModelProperty(value = "") - @JsonProperty("aiQuota") - public AIQuotaLimitDTO getAiQuota() { - return aiQuota; + @JsonProperty("aiApiQuota") + public AIAPIQuotaLimitDTO getAiApiQuota() { + return aiApiQuota; } - public void setAiQuota(AIQuotaLimitDTO aiQuota) { - this.aiQuota = aiQuota; + public void setAiApiQuota(AIAPIQuotaLimitDTO aiApiQuota) { + this.aiApiQuota = aiApiQuota; } @@ -125,12 +125,12 @@ public boolean equals(java.lang.Object o) { Objects.equals(requestCount, throttleLimit.requestCount) && Objects.equals(bandwidth, throttleLimit.bandwidth) && Objects.equals(eventCount, throttleLimit.eventCount) && - Objects.equals(aiQuota, throttleLimit.aiQuota); + Objects.equals(aiApiQuota, throttleLimit.aiApiQuota); } @Override public int hashCode() { - return Objects.hash(quotaType, requestCount, bandwidth, eventCount, aiQuota); + return Objects.hash(quotaType, requestCount, bandwidth, eventCount, aiApiQuota); } @Override @@ -142,7 +142,7 @@ public String toString() { sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); sb.append(" bandwidth: ").append(toIndentedString(bandwidth)).append("\n"); sb.append(" eventCount: ").append(toIndentedString(eventCount)).append("\n"); - sb.append(" aiQuota: ").append(toIndentedString(aiQuota)).append("\n"); + sb.append(" aiApiQuota: ").append(toIndentedString(aiApiQuota)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java index 2e543971cec5..ce886d361970 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/java/org/wso2/carbon/apimgt/internal/service/utils/SubscriptionValidationDataUtil.java @@ -25,7 +25,7 @@ import org.wso2.carbon.apimgt.api.dto.ConditionDTO; import org.wso2.carbon.apimgt.api.model.OperationPolicy; import org.wso2.carbon.apimgt.api.model.Scope; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; import org.wso2.carbon.apimgt.api.model.policy.EventCountLimit; import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants; @@ -42,7 +42,7 @@ import org.wso2.carbon.apimgt.api.model.subscription.Subscription; import org.wso2.carbon.apimgt.api.model.subscription.SubscriptionPolicy; import org.wso2.carbon.apimgt.api.model.subscription.URLMapping; -import org.wso2.carbon.apimgt.internal.service.dto.AIQuotaLimitDTO; +import org.wso2.carbon.apimgt.internal.service.dto.AIAPIQuotaLimitDTO; import org.wso2.carbon.apimgt.internal.service.dto.APIDTO; import org.wso2.carbon.apimgt.internal.service.dto.APIListDTO; import org.wso2.carbon.apimgt.internal.service.dto.ApiPolicyConditionGroupDTO; @@ -332,9 +332,9 @@ private static ThrottleLimitDTO getThrottleLimitDTO(Policy policy) { } else if (PolicyConstants.EVENT_COUNT_TYPE.equals(quotaPolicy.getType())) { EventCountLimit eventCountLimit = (EventCountLimit) quotaPolicy.getLimit(); defaultLimit.setEventCount(fromEventCountLimitToDTO(eventCountLimit)); - } else if (PolicyConstants.AI_QUOTA_TYPE.equals(quotaPolicy.getType())) { - AIQuotaLimit aiQuotaLimit = (AIQuotaLimit) quotaPolicy.getLimit(); - defaultLimit.setAiQuota(fromAIQuotaLimitToDTO(aiQuotaLimit)); + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equals(quotaPolicy.getType())) { + AIAPIQuotaLimit AIAPIQuotaLimit = (AIAPIQuotaLimit) quotaPolicy.getLimit(); + defaultLimit.setAiApiQuota(fromAIAPIQuotaLimitToDTO(AIAPIQuotaLimit)); } return defaultLimit; } @@ -413,20 +413,20 @@ private static EventCountLimitDTO fromEventCountLimitToDTO(EventCountLimit event } /** - * Converts a AI Quota Limit model object into a AI Quota Limit DTO object. + * Converts a AI API Quota Limit model object into a AI API Quota Limit DTO object. * - * @param aiQuotaLimit AI Quota Limit model object - * @return AI Quota Limit DTO object derived from model + * @param AIAPIQuotaLimit AI APIQuota Limit model object + * @return AI API Quota Limit DTO object derived from model */ - private static AIQuotaLimitDTO fromAIQuotaLimitToDTO(AIQuotaLimit aiQuotaLimit) { - - AIQuotaLimitDTO dto = new AIQuotaLimitDTO(); - dto.setTimeUnit(aiQuotaLimit.getTimeUnit()); - dto.setUnitTime(aiQuotaLimit.getUnitTime()); - dto.setRequestCount(aiQuotaLimit.getRequestCount()); - dto.setTotalTokenCount(aiQuotaLimit.getTotalTokenCount()); - dto.setRequestTokenCount(aiQuotaLimit.getRequestTokenCount()); - dto.setResponseTokenCount(aiQuotaLimit.getResponseTokenCount()); + private static AIAPIQuotaLimitDTO fromAIAPIQuotaLimitToDTO(AIAPIQuotaLimit AIAPIQuotaLimit) { + + AIAPIQuotaLimitDTO dto = new AIAPIQuotaLimitDTO(); + dto.setTimeUnit(AIAPIQuotaLimit.getTimeUnit()); + dto.setUnitTime(AIAPIQuotaLimit.getUnitTime()); + dto.setRequestCount(AIAPIQuotaLimit.getRequestCount()); + dto.setTotalTokenCount(AIAPIQuotaLimit.getTotalTokenCount()); + dto.setPromptTokenCount(AIAPIQuotaLimit.getPromptTokenCount()); + dto.setCompletionTokenCount(AIAPIQuotaLimit.getCompletionTokenCount()); return dto; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml index 8eee5672f8e1..86fc51f18986 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/src/main/resources/api.yaml @@ -1548,8 +1548,8 @@ definitions: $ref: '#/definitions/BandwidthLimit' eventCount: $ref: '#/definitions/EventCountLimit' - aiQuota: - $ref: '#/definitions/AIQuotaLimit' + aiApiQuota: + $ref: '#/definitions/AIAPIQuotaLimit' BurstLimit: title: Burst Limit object @@ -1618,9 +1618,9 @@ definitions: example: 3000 #----------------------------------------------------- - # The Throttling AI Quota Limit resource + # The Throttling AI API Quota Limit resource #----------------------------------------------------- - AIQuotaLimit: + AIAPIQuotaLimit: title: AI Quota Limit object allOf: - $ref: '#/definitions/ThrottleLimitBase' @@ -1637,14 +1637,14 @@ definitions: description: Maximum number of total tokens allowed format: int64 example: 1000 - requestTokenCount: + promptTokenCount: type: integer - description: Maximum number of request tokens allowed + description: Maximum number of prompt tokens allowed format: int64 example: 300 - responseTokenCount: + completionTokenCount: type: integer - description: Maximum number of response tokens allowed + description: Maximum number of completion tokens allowed format: int64 example: 300 diff --git a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json index a7fa59630d63..382c5e132c1b 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json +++ b/components/apimgt/org.wso2.carbon.apimgt.internal.service/swagger.json @@ -1354,8 +1354,8 @@ "type" : "string", "example" : "EXCHANGED", "description" : "The type of the tokens to be used (exchanged or without exchanged). Accepted values are EXCHANGED, DIRECT or BOTH.", - "enum" : [ "EXCHANGED", "DIRECT", "BOTH" ], - "default" : "DIRECT" + "default" : "DIRECT", + "enum" : [ "EXCHANGED", "DIRECT", "BOTH" ] } } }, @@ -1920,6 +1920,9 @@ }, "eventCount" : { "$ref" : "#/definitions/EventCountLimit" + }, + "aiApiQuota" : { + "$ref" : "#/definitions/AIAPIQuotaLimit" } }, "title" : "Throttle Limit" @@ -1994,6 +1997,40 @@ } } ] }, + "AIAPIQuotaLimit" : { + "title" : "AI Quota Limit object", + "allOf" : [ { + "$ref" : "#/definitions/ThrottleLimitBase" + }, { + "required" : [ "requestCount" ], + "properties" : { + "requestCount" : { + "type" : "integer", + "format" : "int64", + "example" : 1000, + "description" : "Maximum number of requests allowed" + }, + "totalTokenCount" : { + "type" : "integer", + "format" : "int64", + "example" : 1000, + "description" : "Maximum number of total tokens allowed" + }, + "promptTokenCount" : { + "type" : "integer", + "format" : "int64", + "example" : 300, + "description" : "Maximum number of prompt tokens allowed" + }, + "completionTokenCount" : { + "type" : "integer", + "format" : "int64", + "example" : 300, + "description" : "Maximum number of completion tokens allowed" + } + } + } ] + }, "APILoggingConfigList" : { "properties" : { "apis" : { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitAllOfDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitAllOfDTO.java similarity index 50% rename from components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitAllOfDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitAllOfDTO.java index 475a447e1c31..632f8d3e7dc0 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitAllOfDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitAllOfDTO.java @@ -18,23 +18,23 @@ -public class AIQuotaLimitAllOfDTO { +public class AIAPIQuotaLimitAllOfDTO { private Long requestCount = null; private Long totalTokenCount = null; - private Long requestTokenCount = null; - private Long responseTokenCount = null; + private Long promptTokenCount = null; + private Long completionTokenCount = null; /** * Maximum number of requests allowed **/ - public AIQuotaLimitAllOfDTO requestCount(Long requestCount) { + public AIAPIQuotaLimitAllOfDTO requestCount(Long requestCount) { this.requestCount = requestCount; return this; } - @ApiModelProperty(example = "30", required = true, value = "Maximum number of requests allowed") + @ApiModelProperty(example = "300", required = true, value = "Maximum number of requests allowed") @JsonProperty("requestCount") @NotNull public Long getRequestCount() { @@ -47,13 +47,13 @@ public void setRequestCount(Long requestCount) { /** * Maximum number of total tokens allowed **/ - public AIQuotaLimitAllOfDTO totalTokenCount(Long totalTokenCount) { + public AIAPIQuotaLimitAllOfDTO totalTokenCount(Long totalTokenCount) { this.totalTokenCount = totalTokenCount; return this; } - @ApiModelProperty(example = "1000", value = "Maximum number of total tokens allowed") + @ApiModelProperty(example = "800", value = "Maximum number of total tokens allowed") @JsonProperty("totalTokenCount") public Long getTotalTokenCount() { return totalTokenCount; @@ -63,39 +63,39 @@ public void setTotalTokenCount(Long totalTokenCount) { } /** - * Maximum number of request tokens allowed + * Maximum number of prompt tokens allowed **/ - public AIQuotaLimitAllOfDTO requestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public AIAPIQuotaLimitAllOfDTO promptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of request tokens allowed") - @JsonProperty("requestTokenCount") - public Long getRequestTokenCount() { - return requestTokenCount; + @ApiModelProperty(example = "400", value = "Maximum number of prompt tokens allowed") + @JsonProperty("promptTokenCount") + public Long getPromptTokenCount() { + return promptTokenCount; } - public void setRequestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public void setPromptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; } /** - * Maximum number of response tokens allowed + * Maximum number of completion tokens allowed **/ - public AIQuotaLimitAllOfDTO responseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public AIAPIQuotaLimitAllOfDTO completionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of response tokens allowed") - @JsonProperty("responseTokenCount") - public Long getResponseTokenCount() { - return responseTokenCount; + @ApiModelProperty(example = "500", value = "Maximum number of completion tokens allowed") + @JsonProperty("completionTokenCount") + public Long getCompletionTokenCount() { + return completionTokenCount; } - public void setResponseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public void setCompletionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; } @@ -107,27 +107,27 @@ public boolean equals(java.lang.Object o) { if (o == null || getClass() != o.getClass()) { return false; } - AIQuotaLimitAllOfDTO aiQuotaLimitAllOf = (AIQuotaLimitAllOfDTO) o; - return Objects.equals(requestCount, aiQuotaLimitAllOf.requestCount) && - Objects.equals(totalTokenCount, aiQuotaLimitAllOf.totalTokenCount) && - Objects.equals(requestTokenCount, aiQuotaLimitAllOf.requestTokenCount) && - Objects.equals(responseTokenCount, aiQuotaLimitAllOf.responseTokenCount); + AIAPIQuotaLimitAllOfDTO aiAPIQuotaLimitAllOf = (AIAPIQuotaLimitAllOfDTO) o; + return Objects.equals(requestCount, aiAPIQuotaLimitAllOf.requestCount) && + Objects.equals(totalTokenCount, aiAPIQuotaLimitAllOf.totalTokenCount) && + Objects.equals(promptTokenCount, aiAPIQuotaLimitAllOf.promptTokenCount) && + Objects.equals(completionTokenCount, aiAPIQuotaLimitAllOf.completionTokenCount); } @Override public int hashCode() { - return Objects.hash(requestCount, totalTokenCount, requestTokenCount, responseTokenCount); + return Objects.hash(requestCount, totalTokenCount, promptTokenCount, completionTokenCount); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class AIQuotaLimitAllOfDTO {\n"); + sb.append("class AIAPIQuotaLimitAllOfDTO {\n"); sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); sb.append(" totalTokenCount: ").append(toIndentedString(totalTokenCount)).append("\n"); - sb.append(" requestTokenCount: ").append(toIndentedString(requestTokenCount)).append("\n"); - sb.append(" responseTokenCount: ").append(toIndentedString(responseTokenCount)).append("\n"); + sb.append(" promptTokenCount: ").append(toIndentedString(promptTokenCount)).append("\n"); + sb.append(" completionTokenCount: ").append(toIndentedString(completionTokenCount)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitDTO.java similarity index 59% rename from components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitDTO.java rename to components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitDTO.java index 58b04b841650..1a23c170c11a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIQuotaLimitDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/AIAPIQuotaLimitDTO.java @@ -4,7 +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.admin.v1.dto.AIQuotaLimitAllOfDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIAPIQuotaLimitAllOfDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleLimitBaseDTO; import javax.validation.constraints.*; @@ -20,19 +20,19 @@ -public class AIQuotaLimitDTO { +public class AIAPIQuotaLimitDTO { private String timeUnit = null; private Integer unitTime = null; private Long requestCount = null; private Long totalTokenCount = null; - private Long requestTokenCount = null; - private Long responseTokenCount = null; + private Long promptTokenCount = null; + private Long completionTokenCount = null; /** * Unit of the time. Allowed values are \"sec\", \"min\", \"hour\", \"day\" **/ - public AIQuotaLimitDTO timeUnit(String timeUnit) { + public AIAPIQuotaLimitDTO timeUnit(String timeUnit) { this.timeUnit = timeUnit; return this; } @@ -51,7 +51,7 @@ public void setTimeUnit(String timeUnit) { /** * Time limit that the throttling limit applies. **/ - public AIQuotaLimitDTO unitTime(Integer unitTime) { + public AIAPIQuotaLimitDTO unitTime(Integer unitTime) { this.unitTime = unitTime; return this; } @@ -70,13 +70,13 @@ public void setUnitTime(Integer unitTime) { /** * Maximum number of requests allowed **/ - public AIQuotaLimitDTO requestCount(Long requestCount) { + public AIAPIQuotaLimitDTO requestCount(Long requestCount) { this.requestCount = requestCount; return this; } - @ApiModelProperty(example = "30", required = true, value = "Maximum number of requests allowed") + @ApiModelProperty(example = "300", required = true, value = "Maximum number of requests allowed") @JsonProperty("requestCount") @NotNull public Long getRequestCount() { @@ -89,13 +89,13 @@ public void setRequestCount(Long requestCount) { /** * Maximum number of total tokens allowed **/ - public AIQuotaLimitDTO totalTokenCount(Long totalTokenCount) { + public AIAPIQuotaLimitDTO totalTokenCount(Long totalTokenCount) { this.totalTokenCount = totalTokenCount; return this; } - @ApiModelProperty(example = "1000", value = "Maximum number of total tokens allowed") + @ApiModelProperty(example = "800", value = "Maximum number of total tokens allowed") @JsonProperty("totalTokenCount") public Long getTotalTokenCount() { return totalTokenCount; @@ -105,39 +105,39 @@ public void setTotalTokenCount(Long totalTokenCount) { } /** - * Maximum number of request tokens allowed + * Maximum number of prompt tokens allowed **/ - public AIQuotaLimitDTO requestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public AIAPIQuotaLimitDTO promptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of request tokens allowed") - @JsonProperty("requestTokenCount") - public Long getRequestTokenCount() { - return requestTokenCount; + @ApiModelProperty(example = "400", value = "Maximum number of prompt tokens allowed") + @JsonProperty("promptTokenCount") + public Long getPromptTokenCount() { + return promptTokenCount; } - public void setRequestTokenCount(Long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public void setPromptTokenCount(Long promptTokenCount) { + this.promptTokenCount = promptTokenCount; } /** - * Maximum number of response tokens allowed + * Maximum number of completion tokens allowed **/ - public AIQuotaLimitDTO responseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public AIAPIQuotaLimitDTO completionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; return this; } - @ApiModelProperty(example = "300", value = "Maximum number of response tokens allowed") - @JsonProperty("responseTokenCount") - public Long getResponseTokenCount() { - return responseTokenCount; + @ApiModelProperty(example = "500", value = "Maximum number of completion tokens allowed") + @JsonProperty("completionTokenCount") + public Long getCompletionTokenCount() { + return completionTokenCount; } - public void setResponseTokenCount(Long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public void setCompletionTokenCount(Long completionTokenCount) { + this.completionTokenCount = completionTokenCount; } @@ -149,31 +149,31 @@ public boolean equals(java.lang.Object o) { if (o == null || getClass() != o.getClass()) { return false; } - AIQuotaLimitDTO aiQuotaLimit = (AIQuotaLimitDTO) o; - return Objects.equals(timeUnit, aiQuotaLimit.timeUnit) && - Objects.equals(unitTime, aiQuotaLimit.unitTime) && - Objects.equals(requestCount, aiQuotaLimit.requestCount) && - Objects.equals(totalTokenCount, aiQuotaLimit.totalTokenCount) && - Objects.equals(requestTokenCount, aiQuotaLimit.requestTokenCount) && - Objects.equals(responseTokenCount, aiQuotaLimit.responseTokenCount); + AIAPIQuotaLimitDTO aiAPIQuotaLimit = (AIAPIQuotaLimitDTO) o; + return Objects.equals(timeUnit, aiAPIQuotaLimit.timeUnit) && + Objects.equals(unitTime, aiAPIQuotaLimit.unitTime) && + Objects.equals(requestCount, aiAPIQuotaLimit.requestCount) && + Objects.equals(totalTokenCount, aiAPIQuotaLimit.totalTokenCount) && + Objects.equals(promptTokenCount, aiAPIQuotaLimit.promptTokenCount) && + Objects.equals(completionTokenCount, aiAPIQuotaLimit.completionTokenCount); } @Override public int hashCode() { - return Objects.hash(timeUnit, unitTime, requestCount, totalTokenCount, requestTokenCount, responseTokenCount); + return Objects.hash(timeUnit, unitTime, requestCount, totalTokenCount, promptTokenCount, completionTokenCount); } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class AIQuotaLimitDTO {\n"); + sb.append("class AIAPIQuotaLimitDTO {\n"); sb.append(" timeUnit: ").append(toIndentedString(timeUnit)).append("\n"); sb.append(" unitTime: ").append(toIndentedString(unitTime)).append("\n"); sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); sb.append(" totalTokenCount: ").append(toIndentedString(totalTokenCount)).append("\n"); - sb.append(" requestTokenCount: ").append(toIndentedString(requestTokenCount)).append("\n"); - sb.append(" responseTokenCount: ").append(toIndentedString(responseTokenCount)).append("\n"); + sb.append(" promptTokenCount: ").append(toIndentedString(promptTokenCount)).append("\n"); + sb.append(" completionTokenCount: ").append(toIndentedString(completionTokenCount)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ThrottleLimitDTO.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ThrottleLimitDTO.java index e6b09c5e0c86..545100c1e9d4 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ThrottleLimitDTO.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/gen/java/org/wso2/carbon/apimgt/rest/api/admin/v1/dto/ThrottleLimitDTO.java @@ -4,7 +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.admin.v1.dto.AIQuotaLimitDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIAPIQuotaLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BandwidthLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EventCountLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RequestCountLimitDTO; @@ -31,7 +31,7 @@ public enum TypeEnum { REQUESTCOUNTLIMIT("REQUESTCOUNTLIMIT"), BANDWIDTHLIMIT("BANDWIDTHLIMIT"), EVENTCOUNTLIMIT("EVENTCOUNTLIMIT"), - AIQUOTALIMIT("AIQUOTALIMIT"); + AIAPIQUOTALIMIT("AIAPIQUOTALIMIT"); private String value; TypeEnum (String v) { @@ -61,10 +61,10 @@ public static TypeEnum fromValue(String v) { private RequestCountLimitDTO requestCount = null; private BandwidthLimitDTO bandwidth = null; private EventCountLimitDTO eventCount = null; - private AIQuotaLimitDTO aiQuota = null; + private AIAPIQuotaLimitDTO aiApiQuota = null; /** - * Type of the throttling limit. Allowed values are \"REQUESTCOUNTLIMIT\" and \"BANDWIDTHLIMIT\". Please see schemas of \"RequestCountLimit\" and \"BandwidthLimit\" throttling limit types in Definitions section. + * Type of the throttling limit. Allowed values are \"REQUESTCOUNTLIMIT\", \"BANDWIDTHLIMIT\", \"EVENTCOUNTLIMIT\" and \"AIAPIQUOTALIMIT\". Please see schemas of \"RequestCountLimit\", \"BandwidthLimit\", \"EventCountLimit\" and \"AIAPIQuotaLimit\" throttling limit types in Definitions section. **/ public ThrottleLimitDTO type(TypeEnum type) { this.type = type; @@ -72,7 +72,7 @@ public ThrottleLimitDTO type(TypeEnum type) { } - @ApiModelProperty(example = "REQUESTCOUNTLIMIT", required = true, value = "Type of the throttling limit. Allowed values are \"REQUESTCOUNTLIMIT\" and \"BANDWIDTHLIMIT\". Please see schemas of \"RequestCountLimit\" and \"BandwidthLimit\" throttling limit types in Definitions section. ") + @ApiModelProperty(example = "REQUESTCOUNTLIMIT", required = true, value = "Type of the throttling limit. Allowed values are \"REQUESTCOUNTLIMIT\", \"BANDWIDTHLIMIT\", \"EVENTCOUNTLIMIT\" and \"AIAPIQUOTALIMIT\". Please see schemas of \"RequestCountLimit\", \"BandwidthLimit\", \"EventCountLimit\" and \"AIAPIQuotaLimit\" throttling limit types in Definitions section. ") @JsonProperty("type") @NotNull public TypeEnum getType() { @@ -138,20 +138,20 @@ public void setEventCount(EventCountLimitDTO eventCount) { /** **/ - public ThrottleLimitDTO aiQuota(AIQuotaLimitDTO aiQuota) { - this.aiQuota = aiQuota; + public ThrottleLimitDTO aiApiQuota(AIAPIQuotaLimitDTO aiApiQuota) { + this.aiApiQuota = aiApiQuota; return this; } @ApiModelProperty(value = "") @Valid - @JsonProperty("aiQuota") - public AIQuotaLimitDTO getAiQuota() { - return aiQuota; + @JsonProperty("aiApiQuota") + public AIAPIQuotaLimitDTO getAiApiQuota() { + return aiApiQuota; } - public void setAiQuota(AIQuotaLimitDTO aiQuota) { - this.aiQuota = aiQuota; + public void setAiApiQuota(AIAPIQuotaLimitDTO aiApiQuota) { + this.aiApiQuota = aiApiQuota; } @@ -168,12 +168,12 @@ public boolean equals(java.lang.Object o) { Objects.equals(requestCount, throttleLimit.requestCount) && Objects.equals(bandwidth, throttleLimit.bandwidth) && Objects.equals(eventCount, throttleLimit.eventCount) && - Objects.equals(aiQuota, throttleLimit.aiQuota); + Objects.equals(aiApiQuota, throttleLimit.aiApiQuota); } @Override public int hashCode() { - return Objects.hash(type, requestCount, bandwidth, eventCount, aiQuota); + return Objects.hash(type, requestCount, bandwidth, eventCount, aiApiQuota); } @Override @@ -185,7 +185,7 @@ public String toString() { sb.append(" requestCount: ").append(toIndentedString(requestCount)).append("\n"); sb.append(" bandwidth: ").append(toIndentedString(bandwidth)).append("\n"); sb.append(" eventCount: ").append(toIndentedString(eventCount)).append("\n"); - sb.append(" aiQuota: ").append(toIndentedString(aiQuota)).append("\n"); + sb.append(" aiApiQuota: ").append(toIndentedString(aiApiQuota)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java index 2361457722e2..4bd439de1360 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/impl/ThrottlingApiServiceImpl.java @@ -801,8 +801,8 @@ public Response throttlingPoliciesSubscriptionPolicyIdPut(String policyId, Strin String existingPolicyQuotaType = existingPolicy.getDefaultQuotaPolicy().getType(); String dtoQuotaType = body.getDefaultLimit().getType().toString(); - if (existingPolicyQuotaType.equals(PolicyConstants.AI_QUOTA_TYPE) - != dtoQuotaType.equals(PolicyConstants.AI_QUOTA_TYPE_ENUM_VALUE)) { + if (existingPolicyQuotaType.equals(PolicyConstants.AI_API_QUOTA_TYPE) + != dtoQuotaType.equals(PolicyConstants.AI_API_QUOTA_TYPE_ENUM_VALUE)) { throw new APIManagementException( "Subscription quota type can not be changed for AI Subscription policies.", ExceptionCodes.from(ExceptionCodes.SUBSCRIPTION_POLICY_UPDATE_TYPE_BAD_REQUEST)); @@ -811,7 +811,7 @@ public Response throttlingPoliciesSubscriptionPolicyIdPut(String policyId, Strin //overridden properties body.setPolicyId(policyId); body.setPolicyName(existingPolicy.getPolicyName()); - if (PolicyConstants.AI_QUOTA_TYPE_ENUM_VALUE.equals(body.getDefaultLimit().getType().toString())) { + if (PolicyConstants.AI_API_QUOTA_TYPE_ENUM_VALUE.equals(body.getDefaultLimit().getType().toString())) { body.setDefaultLimit(RestApiAdminUtils.overrideTokenBasedQuotaLimits(body.getDefaultLimit(), existingPolicy.getDefaultQuotaPolicy())); } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java index fd97522e25ab..5ffbe11eec78 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/RestApiAdminUtils.java @@ -25,13 +25,13 @@ import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.ExceptionCodes; import org.wso2.carbon.apimgt.api.model.BlockConditionsDTO; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.Policy; import org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy; import org.wso2.carbon.apimgt.impl.APIAdminImpl; import org.wso2.carbon.apimgt.impl.APIConstants; import org.wso2.carbon.apimgt.impl.utils.APIUtil; -import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIQuotaLimitDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIAPIQuotaLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomRuleDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleConditionDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ThrottleLimitDTO; @@ -394,19 +394,19 @@ public static void restoreTenantTheme(int tenantId, File tenantThemeDirectory, F public static ThrottleLimitDTO overrideTokenBasedQuotaLimits(ThrottleLimitDTO throttleLimitDTO, QuotaPolicy quotaPolicy) { - AIQuotaLimitDTO aiQuotaLimitDTO = throttleLimitDTO.getAiQuota(); - AIQuotaLimit aiQuotaLimit = (AIQuotaLimit) quotaPolicy.getLimit(); + AIAPIQuotaLimitDTO aiApiQuotaLimitDTO = throttleLimitDTO.getAiApiQuota(); + AIAPIQuotaLimit AIAPIQuotaLimit = (AIAPIQuotaLimit) quotaPolicy.getLimit(); throttleLimitDTO.setType(throttleLimitDTO.getType()); - if (throttleLimitDTO.getAiQuota().getTotalTokenCount() == null) { - aiQuotaLimitDTO.setTotalTokenCount(aiQuotaLimit.getTotalTokenCount()); + if (throttleLimitDTO.getAiApiQuota().getTotalTokenCount() == null) { + aiApiQuotaLimitDTO.setTotalTokenCount(AIAPIQuotaLimit.getTotalTokenCount()); } - if (throttleLimitDTO.getAiQuota().getRequestTokenCount() == null) { - aiQuotaLimitDTO.setRequestTokenCount(aiQuotaLimit.getRequestTokenCount()); + if (throttleLimitDTO.getAiApiQuota().getPromptTokenCount() == null) { + aiApiQuotaLimitDTO.setPromptTokenCount(AIAPIQuotaLimit.getPromptTokenCount()); } - if (throttleLimitDTO.getAiQuota().getResponseTokenCount() == null) { - aiQuotaLimitDTO.setResponseTokenCount(aiQuotaLimit.getResponseTokenCount()); + if (throttleLimitDTO.getAiApiQuota().getCompletionTokenCount() == null) { + aiApiQuotaLimitDTO.setCompletionTokenCount(AIAPIQuotaLimit.getCompletionTokenCount()); } - throttleLimitDTO.setAiQuota(aiQuotaLimitDTO); + throttleLimitDTO.setAiApiQuota(aiApiQuotaLimitDTO); return throttleLimitDTO; } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/CommonThrottleMappingUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/CommonThrottleMappingUtil.java index 3bf5c83597ab..91bd9848110a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/CommonThrottleMappingUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/CommonThrottleMappingUtil.java @@ -21,7 +21,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.api.UnsupportedThrottleConditionTypeException; import org.wso2.carbon.apimgt.api.UnsupportedThrottleLimitTypeException; -import org.wso2.carbon.apimgt.api.model.policy.AIQuotaLimit; +import org.wso2.carbon.apimgt.api.model.policy.AIAPIQuotaLimit; import org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit; import org.wso2.carbon.apimgt.api.model.policy.Condition; import org.wso2.carbon.apimgt.api.model.policy.EventCountLimit; @@ -35,7 +35,7 @@ import org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy; import org.wso2.carbon.apimgt.api.model.policy.RequestCountLimit; import org.wso2.carbon.apimgt.impl.utils.APIUtil; -import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIQuotaLimitDTO; +import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.AIAPIQuotaLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.BandwidthLimitDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.ConditionalGroupDTO; import org.wso2.carbon.apimgt.rest.api.admin.v1.dto.CustomAttributeDTO; @@ -315,13 +315,13 @@ public static QuotaPolicy fromDTOToQuotaPolicy(ThrottleLimitDTO dto) } break; } - case AIQUOTALIMIT: { - if (dto.getAiQuota() != null) { - quotaPolicy.setLimit(fromDTOToAIQuotaLimit(dto.getAiQuota())); + case AIAPIQUOTALIMIT: { + if (dto.getAiApiQuota() != null) { + quotaPolicy.setLimit(fromDTOToAIAPIQuotaLimit(dto.getAiApiQuota())); } else { errorMessage = RestApiAdminUtils.constructMissingThrottleObjectErrorMessage( - ThrottleLimitDTO.TypeEnum.AIQUOTALIMIT) + dto.toString(); + ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT) + dto.toString(); throw new UnsupportedThrottleLimitTypeException(errorMessage); } break; @@ -358,10 +358,10 @@ public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) EventCountLimit eventCountLimit = (EventCountLimit) quotaPolicy.getLimit(); defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.EVENTCOUNTLIMIT); defaultLimitType.setEventCount(fromEventCountLimitToDTO(eventCountLimit)); - } else if (PolicyConstants.AI_QUOTA_TYPE.equals(quotaPolicy.getType())) { - AIQuotaLimit aiQuotaLimit = (AIQuotaLimit) quotaPolicy.getLimit(); - defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.AIQUOTALIMIT); - defaultLimitType.setAiQuota(fromAIQuotaLimitToDTO(aiQuotaLimit)); + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equals(quotaPolicy.getType())) { + AIAPIQuotaLimit AIAPIQuotaLimit = (AIAPIQuotaLimit) quotaPolicy.getLimit(); + defaultLimitType.setType(ThrottleLimitDTO.TypeEnum.AIAPIQUOTALIMIT); + defaultLimitType.setAiApiQuota(fromAIQuotaLimitToDTO(AIAPIQuotaLimit)); } else { String msg = "Throttle limit type " + quotaPolicy.getType() + " is not supported"; throw new UnsupportedThrottleLimitTypeException(msg); @@ -370,19 +370,19 @@ public static ThrottleLimitDTO fromQuotaPolicyToDTO(QuotaPolicy quotaPolicy) } /** - * Converts a AI Quota Limit model object into a AI Quota Limit DTO object + * Converts a AI API Quota Limit model object into a AI API Quota Limit DTO object * - * @param aiQuotaLimit AI Quota Limit model object - * @return AI Quota Limit DTO object derived from model + * @param AIAPIQuotaLimit AI API Quota Limit model object + * @return AI API Quota Limit DTO object derived from model */ - public static AIQuotaLimitDTO fromAIQuotaLimitToDTO(AIQuotaLimit aiQuotaLimit) { - AIQuotaLimitDTO dto = new AIQuotaLimitDTO(); - dto.setTimeUnit(aiQuotaLimit.getTimeUnit()); - dto.setUnitTime(aiQuotaLimit.getUnitTime()); - dto.setRequestCount(aiQuotaLimit.getRequestCount()); - dto.setTotalTokenCount(aiQuotaLimit.getTotalTokenCount()); - dto.setRequestTokenCount(aiQuotaLimit.getRequestTokenCount()); - dto.setResponseTokenCount(aiQuotaLimit.getResponseTokenCount()); + public static AIAPIQuotaLimitDTO fromAIQuotaLimitToDTO(AIAPIQuotaLimit AIAPIQuotaLimit) { + AIAPIQuotaLimitDTO dto = new AIAPIQuotaLimitDTO(); + dto.setTimeUnit(AIAPIQuotaLimit.getTimeUnit()); + dto.setUnitTime(AIAPIQuotaLimit.getUnitTime()); + dto.setRequestCount(AIAPIQuotaLimit.getRequestCount()); + dto.setTotalTokenCount(AIAPIQuotaLimit.getTotalTokenCount()); + dto.setPromptTokenCount(AIAPIQuotaLimit.getPromptTokenCount()); + dto.setCompletionTokenCount(AIAPIQuotaLimit.getCompletionTokenCount()); return dto; } @@ -421,21 +421,21 @@ public static RequestCountLimit fromDTOToRequestCountLimit(RequestCountLimitDTO * @param dto AI Quota Limit DTO object * @return AI Quota Limit model object derived from DTO */ - public static AIQuotaLimit fromDTOToAIQuotaLimit(AIQuotaLimitDTO dto) { - AIQuotaLimit aiQuotaLimit = new AIQuotaLimit(); - aiQuotaLimit.setTimeUnit(dto.getTimeUnit()); - aiQuotaLimit.setUnitTime(dto.getUnitTime()); - aiQuotaLimit.setRequestCount(dto.getRequestCount()); + public static AIAPIQuotaLimit fromDTOToAIAPIQuotaLimit(AIAPIQuotaLimitDTO dto) { + AIAPIQuotaLimit AIAPIQuotaLimit = new AIAPIQuotaLimit(); + AIAPIQuotaLimit.setTimeUnit(dto.getTimeUnit()); + AIAPIQuotaLimit.setUnitTime(dto.getUnitTime()); + AIAPIQuotaLimit.setRequestCount(dto.getRequestCount()); if (dto.getTotalTokenCount() != null) { - aiQuotaLimit.setTotalTokenCount(dto.getTotalTokenCount()); + AIAPIQuotaLimit.setTotalTokenCount(dto.getTotalTokenCount()); } - if (dto.getRequestTokenCount() != null) { - aiQuotaLimit.setRequestTokenCount(dto.getRequestTokenCount()); + if (dto.getPromptTokenCount() != null) { + AIAPIQuotaLimit.setPromptTokenCount(dto.getPromptTokenCount()); } - if (dto.getResponseTokenCount() != null) { - aiQuotaLimit.setResponseTokenCount(dto.getResponseTokenCount()); + if (dto.getCompletionTokenCount() != null) { + AIAPIQuotaLimit.setCompletionTokenCount(dto.getCompletionTokenCount()); } - return aiQuotaLimit; + return AIAPIQuotaLimit; } private static EventCountLimit fromDTOToEventCountLimit(EventCountLimitDTO dto) { @@ -694,8 +694,8 @@ private static String mapQuotaPolicyTypeFromDTOToModel(ThrottleLimitDTO.TypeEnum return PolicyConstants.REQUEST_COUNT_TYPE; case EVENTCOUNTLIMIT: return PolicyConstants.EVENT_COUNT_TYPE; - case AIQUOTALIMIT: - return PolicyConstants.AI_QUOTA_TYPE; + case AIAPIQUOTALIMIT: + return PolicyConstants.AI_API_QUOTA_TYPE; default: return null; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/SubscriptionThrottlePolicyMappingUtil.java b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/SubscriptionThrottlePolicyMappingUtil.java index a78c66fff071..f7ef5fc03953 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/SubscriptionThrottlePolicyMappingUtil.java +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/java/org/wso2/carbon/apimgt/rest/api/admin/v1/utils/mappings/throttling/SubscriptionThrottlePolicyMappingUtil.java @@ -139,15 +139,21 @@ public static SubscriptionPolicy fromSubscriptionThrottlePolicyDTOToModel(Subscr SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy(dto.getPolicyName()); subscriptionPolicy = CommonThrottleMappingUtil.updateFieldsFromDTOToPolicy(dto, subscriptionPolicy); subscriptionPolicy.setBillingPlan(dto.getBillingPlan()); - subscriptionPolicy.setRateLimitTimeUnit(dto.getRateLimitTimeUnit()); - subscriptionPolicy.setRateLimitCount(dto.getRateLimitCount()); - subscriptionPolicy.setSubscriberCount(dto.getSubscriberCount()); subscriptionPolicy.setStopOnQuotaReach(dto.isStopOnQuotaReach()); - if (dto.getGraphQLMaxComplexity() != null && !(PolicyConstants.AI_QUOTA_TYPE_ENUM_VALUE).equals(quotaType)) { - subscriptionPolicy.setGraphQLMaxComplexity(dto.getGraphQLMaxComplexity()); - } - if (dto.getGraphQLMaxDepth() != null && !(PolicyConstants.AI_QUOTA_TYPE_ENUM_VALUE).equals(quotaType)) { - subscriptionPolicy.setGraphQLMaxDepth(dto.getGraphQLMaxDepth()); + if (!PolicyConstants.AI_API_QUOTA_TYPE_ENUM_VALUE.equals(quotaType)) { + subscriptionPolicy.setRateLimitTimeUnit(dto.getRateLimitTimeUnit()); + if (dto.getRateLimitCount() != null) { + subscriptionPolicy.setRateLimitCount(dto.getRateLimitCount()); + } + if (dto.getSubscriberCount() != null) { + subscriptionPolicy.setSubscriberCount(dto.getSubscriberCount()); + } + if (dto.getGraphQLMaxComplexity() != null) { + subscriptionPolicy.setGraphQLMaxComplexity(dto.getGraphQLMaxComplexity()); + } + if (dto.getGraphQLMaxDepth() != null) { + subscriptionPolicy.setGraphQLMaxDepth(dto.getGraphQLMaxDepth()); + } } List customAttributes = dto.getCustomAttributes(); if (customAttributes != null && customAttributes.size() > 0) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml index b2d105ef9b09..04b4265adf61 100755 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml @@ -4111,23 +4111,24 @@ components: type: type: string description: | - Type of the throttling limit. Allowed values are "REQUESTCOUNTLIMIT" and "BANDWIDTHLIMIT". - Please see schemas of "RequestCountLimit" and "BandwidthLimit" throttling limit types in - Definitions section. + Type of the throttling limit. Allowed values are "REQUESTCOUNTLIMIT", "BANDWIDTHLIMIT", "EVENTCOUNTLIMIT" + and "AIAPIQUOTALIMIT". + Please see schemas of "RequestCountLimit", "BandwidthLimit", "EventCountLimit" and "AIAPIQuotaLimit" + throttling limit types in Definitions section. example: REQUESTCOUNTLIMIT enum: - REQUESTCOUNTLIMIT - BANDWIDTHLIMIT - EVENTCOUNTLIMIT - - AIQUOTALIMIT + - AIAPIQUOTALIMIT requestCount: $ref: '#/components/schemas/RequestCountLimit' bandwidth: $ref: '#/components/schemas/BandwidthLimit' eventCount: $ref: '#/components/schemas/EventCountLimit' - aiQuota: - $ref: '#/components/schemas/AIQuotaLimit' + aiApiQuota: + $ref: '#/components/schemas/AIAPIQuotaLimit' BurstLimit: title: Burst Limit object type: object @@ -4190,8 +4191,8 @@ components: description: Maximum number of requests allowed format: int64 example: 30 - AIQuotaLimit: - title: AI Quota Limit object + AIAPIQuotaLimit: + title: AI API Quota Limit object allOf: - $ref: '#/components/schemas/ThrottleLimitBase' - required: @@ -4202,22 +4203,22 @@ components: type: integer description: Maximum number of requests allowed format: int64 - example: 30 + example: 300 totalTokenCount: type: integer description: Maximum number of total tokens allowed format: int64 - example: 1000 - requestTokenCount: + example: 800 + promptTokenCount: type: integer - description: Maximum number of request tokens allowed + description: Maximum number of prompt tokens allowed format: int64 - example: 300 - responseTokenCount: + example: 400 + completionTokenCount: type: integer - description: Maximum number of response tokens allowed + description: Maximum number of completion tokens allowed format: int64 - example: 300 + example: 500 EventCountLimit: title: Event Count Limit object allOf: diff --git a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml index ed168152ac21..e606a422639a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml +++ b/components/apimgt/org.wso2.carbon.apimgt.rest.api.common/src/main/resources/admin-api.yaml @@ -4099,23 +4099,24 @@ components: type: type: string description: | - Type of the throttling limit. Allowed values are "REQUESTCOUNTLIMIT" and "BANDWIDTHLIMIT". - Please see schemas of "RequestCountLimit" and "BandwidthLimit" throttling limit types in - Definitions section. + Type of the throttling limit. Allowed values are "REQUESTCOUNTLIMIT", "BANDWIDTHLIMIT", "EVENTCOUNTLIMIT" + and "AIAPIQUOTALIMIT". + Please see schemas of "RequestCountLimit", "BandwidthLimit", "EventCountLimit" and "AIAPIQuotaLimit" + throttling limit types in Definitions section. example: REQUESTCOUNTLIMIT enum: - REQUESTCOUNTLIMIT - BANDWIDTHLIMIT - EVENTCOUNTLIMIT - - AIQUOTALIMIT + - AIAPIQUOTALIMIT requestCount: $ref: '#/components/schemas/RequestCountLimit' bandwidth: $ref: '#/components/schemas/BandwidthLimit' eventCount: $ref: '#/components/schemas/EventCountLimit' - aiQuota: - $ref: '#/components/schemas/AIQuotaLimit' + aiApiQuota: + $ref: '#/components/schemas/AIAPIQuotaLimit' BurstLimit: title: Burst Limit object type: object @@ -4178,8 +4179,8 @@ components: description: Maximum number of requests allowed format: int64 example: 30 - AIQuotaLimit: - title: AI Quota Limit object + AIAPIQuotaLimit: + title: AI API Quota Limit object allOf: - $ref: '#/components/schemas/ThrottleLimitBase' - required: @@ -4190,22 +4191,22 @@ components: type: integer description: Maximum number of requests allowed format: int64 - example: 30 + example: 300 totalTokenCount: type: integer description: Maximum number of total tokens allowed format: int64 - example: 1000 - requestTokenCount: + example: 800 + promptTokenCount: type: integer - description: Maximum number of request tokens allowed + description: Maximum number of prompt tokens allowed format: int64 - example: 300 - responseTokenCount: + example: 400 + completionTokenCount: type: integer - description: Maximum number of response tokens allowed + description: Maximum number of completion tokens allowed format: int64 - example: 300 + example: 500 EventCountLimit: title: Event Count Limit object allOf: diff --git a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIQuotaLimit.java b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIAPIQuotaLimit.java similarity index 71% rename from components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIQuotaLimit.java rename to components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIAPIQuotaLimit.java index 01ff4f1cbb5d..fbc628d3473a 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIQuotaLimit.java +++ b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/AIAPIQuotaLimit.java @@ -21,12 +21,12 @@ /** * Entity for keeping details of a AI Quota Limit */ -public class AIQuotaLimit extends Limit { +public class AIAPIQuotaLimit extends Limit { private long requestCount; private long totalTokenCount; - private long requestTokenCount; - private long responseTokenCount; + private long promptTokenCount; + private long completionTokenCount; public long getRequestCount() { return requestCount; @@ -44,19 +44,19 @@ public void setTotalTokenCount(long totalTokenCount) { this.totalTokenCount = totalTokenCount; } - public long getRequestTokenCount() { - return requestTokenCount; + public long getPromptTokenCount() { + return promptTokenCount; } - public void setRequestTokenCount(long requestTokenCount) { - this.requestTokenCount = requestTokenCount; + public void setPromptTokenCount(long promptTokenCount) { + this.promptTokenCount = promptTokenCount; } - public long getResponseTokenCount() { - return responseTokenCount; + public long getCompletionTokenCount() { + return completionTokenCount; } - public void setResponseTokenCount(long responseTokenCount) { - this.responseTokenCount = responseTokenCount; + public void setCompletionTokenCount(long completionTokenCount) { + this.completionTokenCount = completionTokenCount; } } diff --git a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/QuotaPolicy.java b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/QuotaPolicy.java index fd4d06366f5b..8974ce7b5304 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/QuotaPolicy.java +++ b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/dto/QuotaPolicy.java @@ -26,7 +26,7 @@ public class QuotaPolicy { private RequestCountLimit requestCount; private BandwidthLimit bandwidth; private EventCountLimit eventCount; - private AIQuotaLimit aiQuota; + private AIAPIQuotaLimit aiApiQuota; public String getQuotaType() { return quotaType; @@ -60,12 +60,12 @@ public void setEventCount(EventCountLimit eventCount) { this.eventCount = eventCount; } - public AIQuotaLimit getAIQuota() { - return aiQuota; + public AIAPIQuotaLimit getAiApiQuota() { + return aiApiQuota; } - public void setAIQuota(AIQuotaLimit aiQuota) { - this.aiQuota = aiQuota; + public void setAiApiQuota(AIAPIQuotaLimit aiApiQuota) { + this.aiApiQuota = aiApiQuota; } public Limit getLimit() { @@ -73,8 +73,8 @@ public Limit getLimit() { return this.requestCount; } else if (this.eventCount != null) { return this.eventCount; - } else if (this.aiQuota != null) { - return this.aiQuota; + } else if (this.aiApiQuota != null) { + return this.aiApiQuota; } return this.bandwidth; } diff --git a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlePolicyTemplateBuilder.java b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlePolicyTemplateBuilder.java index 1dcebd680d1c..501946e7b49f 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlePolicyTemplateBuilder.java +++ b/components/apimgt/org.wso2.carbon.apimgt.throttle.policy.deployer/src/main/java/org/wso2/carbon/apimgt/throttle/policy/deployer/utils/ThrottlePolicyTemplateBuilder.java @@ -463,7 +463,7 @@ public String getThrottlePolicyForSubscriptionLevel(SubscriptionPolicy policy) t Template template; if (PolicyConstants.EVENT_COUNT_TYPE.equals(policy.getDefaultLimit().getQuotaType())) { template = velocityengine.getTemplate(getTemplatePathForAsyncSubscription()); - } else if (PolicyConstants.AI_QUOTA_TYPE.equals(policy.getDefaultLimit().getQuotaType())) { + } else if (PolicyConstants.AI_API_QUOTA_TYPE.equals(policy.getDefaultLimit().getQuotaType())) { template = velocityengine.getTemplate(getTemplatePathForAISubscription()); } else { template = velocityengine.getTemplate(getTemplatePathForSubscription()); diff --git a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/policy_templates/throttle_policy_template_ai_sub.xml b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/policy_templates/throttle_policy_template_ai_sub.xml index c5c268064821..7bf0b3a9d9e1 100644 --- a/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/policy_templates/throttle_policy_template_ai_sub.xml +++ b/features/apimgt/org.wso2.carbon.apimgt.core.feature/src/main/resources/policy_templates/throttle_policy_template_ai_sub.xml @@ -1,4 +1,4 @@ - @Plan:name('${policy.getTenantDomain()}sub${policy.getName()}') + @Plan:name('${policy.getTenantDomain()}_sub_${policy.getName()}') @Plan:description('ExecutionPlan for sub_${policy.getName()}') @Import('org.wso2.throttle.processed.request.stream:1.0.0') define stream RequestStream (messageID string, appKey string, appTier string, subscriptionKey string, apiKey string, apiTier string, subscriptionTier string, resourceKey string, resourceTier string, userId string, apiContext string, apiVersion string, appTenant string, apiTenant string, appId string, apiName string, propertiesMap string); @@ -16,19 +16,19 @@ #if($quotaPolicy.getLimit().getRequestCount() != "") ifThenElse((count(messageID) >= 1000), true, #end - #if($quotaPolicy.getLimit().getRequestTokenCount() != "") - ifThenElse((sum(cast(map:get(propertiesMap,'requestTokenCount'),'long')) >= 30000L), true, + #if($quotaPolicy.getLimit().getPromptTokenCount() != "") + ifThenElse((sum(cast(map:get(propertiesMap,'promptTokenCount'),'long')) >= 30000L), true, #end - #if($quotaPolicy.getLimit().getResponseTokenCount() != "") - ifThenElse((sum(cast(map:get(propertiesMap,'responseTokenCount'),'long')) >= 30000L), true, + #if($quotaPolicy.getLimit().getCompletionTokenCount() != "") + ifThenElse((sum(cast(map:get(propertiesMap,'completionTokenCount'),'long')) >= 30000L), true, #end #if($quotaPolicy.getLimit().getTotalTokenCount() != "") ifThenElse((sum(cast(map:get(propertiesMap,'totalTokenCount'),'long')) >= 30000L), true, false) #end - #if($quotaPolicy.getLimit().getRequestTokenCount() != "") + #if($quotaPolicy.getLimit().getPromptTokenCount() != "") ) #end - #if($quotaPolicy.getLimit().getResponseTokenCount() != "") + #if($quotaPolicy.getLimit().getCompletionTokenCount() != "") ) #end #if($quotaPolicy.getRequestCountLimit().getRequestCount() != "")