Skip to content

Commit feee201

Browse files
committed
Introduce generic property name to enforce the target endpoint
1 parent a16b47c commit feee201

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

  • components/apimgt
    • org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api
    • org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/mediators

components/apimgt/org.wso2.carbon.apimgt.api/src/main/java/org/wso2/carbon/apimgt/api/APIConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ public static class AIAPIConstants {
182182
public static final String TRAFFIC_FLOW_DIRECTION_IN = "IN";
183183
public static final String TRAFFIC_FLOW_DIRECTION_OUT = "OUT";
184184
public static final String API_LLM_ENDPOINT = "_API_LLMEndpoint_";
185+
// New generic property name for passing target model configurations between mediators.
186+
public static final String TARGET_MODEL_CONFIGS = "TARGET_MODEL_CONFIGS";
187+
// Backward compatible constant name. New code should use TARGET_MODEL_CONFIGS.
185188
public static final String ROUND_ROBIN_CONFIGS = "ROUND_ROBIN_CONFIGS";
186189
public static final String FAILOVER_CONFIGS = "FAILOVER_CONFIGS";
187190
public static final String TARGET_MODEL_ENDPOINT = "TARGET_MODEL_ENDPOINT";

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/mediators/AIAPIMediator.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ private void processInboundRequest(MessageContext messageContext,
175175
return;
176176
}
177177

178-
Map<String, Object> roundRobinConfigs;
179-
if (messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS) != null) {
180-
roundRobinConfigs =
181-
(Map<String, Object>) messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS);
182-
handleLoadBalancing(messageContext, providerConfiguration, roundRobinConfigs, provider);
178+
// Prefer the new generic TARGET_MODEL_CONFIGS; fall back to ROUND_ROBIN_CONFIGS for compatibility
179+
Map<String, Object> targetModelConfigs = null;
180+
if (messageContext.getProperty(APIConstants.AIAPIConstants.TARGET_MODEL_CONFIGS) != null) {
181+
targetModelConfigs = (Map<String, Object>) messageContext
182+
.getProperty(APIConstants.AIAPIConstants.TARGET_MODEL_CONFIGS);
183+
} else if (messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS) != null) {
184+
targetModelConfigs = (Map<String, Object>) messageContext
185+
.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS);
186+
}
187+
if (targetModelConfigs != null) {
188+
handleLoadBalancing(messageContext, providerConfiguration, targetModelConfigs, provider);
183189
if (log.isDebugEnabled()) {
184190
log.debug("Load balancing configured, processing with round-robin configurations");
185191
}
@@ -649,10 +655,14 @@ private void processOutboundResponse(MessageContext messageContext,
649655
llmProviderService.getResponseMetadata(llmResponseMetaData, providerConfigs.getMetadata(), metadataMap);
650656
messageContext.setProperty(APIConstants.AIAPIConstants.AI_API_RESPONSE_METADATA, metadataMap);
651657

658+
// Read target model configs from the new generic property first, then fall back for compatibility
652659
Map<String, Object> roundRobinConfigs = null;
653-
if (messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS) != null) {
654-
roundRobinConfigs =
655-
(Map<String, Object>) messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS);
660+
if (messageContext.getProperty(APIConstants.AIAPIConstants.TARGET_MODEL_CONFIGS) != null) {
661+
roundRobinConfigs = (Map<String, Object>) messageContext
662+
.getProperty(APIConstants.AIAPIConstants.TARGET_MODEL_CONFIGS);
663+
} else if (messageContext.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS) != null) {
664+
roundRobinConfigs = (Map<String, Object>) messageContext
665+
.getProperty(APIConstants.AIAPIConstants.ROUND_ROBIN_CONFIGS);
656666
}
657667

658668
Map<String, Object> failoverConfigs = null;

0 commit comments

Comments
 (0)