hengyuss commented on code in PR #7580:
URL: https://github.com/apache/shenyu/pull/7580#discussion_r4267048412


##########
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-proxy/src/main/java/org/apache/shenyu/plugin/ai/proxy/enhanced/provider/AiProviderCapabilities.java:
##########
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.ai.proxy.enhanced.provider;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.shenyu.plugin.ai.proxy.enhanced.model.AiProxyException;
+import org.apache.shenyu.plugin.ai.proxy.enhanced.model.ShenyuAiRequest;
+import org.apache.shenyu.plugin.ai.proxy.enhanced.protocol.OpenAiChat;
+import org.apache.shenyu.plugin.ai.proxy.enhanced.protocol.OpenAiResponses;
+
+import java.util.EnumSet;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Declared provider capabilities, independent of HTTP execution and model 
discovery.
+ *
+ * @param protocols supported client protocols
+ * @param operations supported AI operations
+ * @param features supported request features
+ */
+public record AiProviderCapabilities(Set<String> protocols, 
Set<ShenyuAiRequest.Operation> operations, Set<Feature> features) {
+
+    /**
+     * Copy declarations so request handling never mutates provider 
configuration.
+     */
+    public AiProviderCapabilities {
+        protocols = Set.copyOf(protocols);
+        operations = Set.copyOf(operations);
+        features = Set.copyOf(features);
+    }
+
+    /**
+     * General Chat upstream capabilities, including conversion from Responses 
clients.
+     *
+     * @return general capabilities
+     */
+    public static AiProviderCapabilities chat() {
+        return new AiProviderCapabilities(Set.of(OpenAiChat.NAME, 
OpenAiResponses.NAME),
+                EnumSet.allOf(ShenyuAiRequest.Operation.class), 
EnumSet.allOf(Feature.class));

Review Comment:
    Capability declarations should probably be fail-closed. EnumSet.allOf() 
means every future operation or feature is automatically advertised by all 
generic profiles, and by DeepSeek unless it is explicitly added to the removal 
list. A newly added operation could therefore pass validation and be sent to 
/chat/completions before the provider has been reviewed. Please enumerate the 
currently supported operations/features explicitly.



##########
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-proxy/src/main/java/org/apache/shenyu/plugin/ai/proxy/enhanced/provider/AiProxyProvider.java:
##########


Review Comment:
   capabilities() and supports() currently form two independent contracts. The 
engine only consults supports(), whose default still returns true, so a custom 
provider can declare restricted protocols/operations without those
   restrictions ever being enforced. Could we derive the default supports() 
from capabilities().protocols() and centralize decoded request capability 
validation before buildRequest()? Final-payload feature validation can 
remainprovider-specific.



-- 
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]

Reply via email to