Copilot commented on code in PR #5986:
URL: https://github.com/apache/shenyu/pull/5986#discussion_r2020405935
##########
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-proxy/src/main/java/org/apache/shenyu/plugin/ai/proxy/AiProxyPlugin.java:
##########
@@ -89,21 +89,25 @@ protected Mono<Void> doExecute(final ServerWebExchange
exchange, final ShenyuPlu
exchange.getAttributes().put(Constants.CONTEXT, shenyuContext);
// set domain
- exchange.getAttributes().put(Constants.HTTP_DOMAIN,
aiProxyConfig.getBaseUrl());
+ exchange.getAttributes().put(Constants.HTTP_DOMAIN,
aiCommonConfig.getBaseUrl());
// set the http timeout
exchange.getAttributes().put(Constants.HTTP_TIME_OUT, 60 * 3000L);
exchange.getAttributes().put(Constants.HTTP_RETRY, 0);
- String provider = aiProxyConfig.getProvider();
+ String provider = aiCommonConfig.getProvider();
AiModelProviderEnum providerEnum =
AiModelProviderEnum.getByName(provider);
if (Objects.isNull(providerEnum)) {
return Mono.error(new IllegalArgumentException("Invalid AI model
provider"));
}
+ // Create AI model instance
AiModel aiModel = AiModelFactory.createAiModel(providerEnum);
if (Objects.isNull(aiModel)) {
return Mono.error(new IllegalStateException("Failed to create AI
model"));
}
- return aiModel.invoke(aiProxyConfig, exchange, chain, messageReaders);
+
+ exchange.getAttributes().put(Constants.AI_MODEL, providerEnum);
+
Review Comment:
The attribute 'Constants.AI_MODEL' is set to a providerEnum instead of the
AiModel instance, which can lead to runtime errors in components that expect an
AiModel. Set the attribute to 'aiModel' instead.
```suggestion
exchange.getAttributes().put(Constants.AI_MODEL, aiModel);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]