You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "478320 (via GitHub)" <gi...@apache.org> on 2025/06/03 17:48:28 UTC

[PR] fea plugin ai-request-transformer : first add plugin [shenyu]

478320 opened a new pull request, #6033:
URL: https://github.com/apache/shenyu/pull/6033

   <!-- Describe your PR here; e.g. Fixes #issueNo -->
   
   <!--
   Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
   -->
   Make sure that:
   
   - [ ] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [ ] You submit test cases (unit or integration tests) that back your changes.
   - [ ] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
   


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fea plugin ai-request-transformer : first add plugin [shenyu]

Posted by "478320 (via GitHub)" <gi...@apache.org>.
478320 commented on PR #6033:
URL: https://github.com/apache/shenyu/pull/6033#issuecomment-2936497440

   #5973


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: ai-request-transformer plugin [shenyu]

Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 commented on code in PR #6033:
URL: https://github.com/apache/shenyu/pull/6033#discussion_r2126338881


##########
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/cache/ChatClientCache.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.transformer.request.cache;
+
+import org.apache.shenyu.common.dto.convert.plugin.AiRequestTransformerConfig;
+import org.apache.shenyu.common.enums.AiModelProviderEnum;
+import org.springframework.ai.chat.client.ChatClient;
+import org.springframework.ai.chat.model.ChatModel;
+import org.springframework.ai.deepseek.DeepSeekChatModel;
+import org.springframework.ai.deepseek.DeepSeekChatOptions;
+import org.springframework.ai.deepseek.api.DeepSeekApi;
+import org.springframework.ai.openai.OpenAiChatModel;
+import org.springframework.ai.openai.OpenAiChatOptions;
+import org.springframework.ai.openai.api.OpenAiApi;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * this is chatClient cache.
+ */
+public class ChatClientCache {
+
+    private static final Map<String, ChatClient> CHAT_CLIENT_MAP = new HashMap<>();
+
+    public ChatClientCache() {
+    }
+
+    /**
+     * Init.
+     *gi
+     * @param aiRequestTransformerConfig the aiRequestTransformerConfig
+     */
+    public ChatClient init(final String ruleId, final AiRequestTransformerConfig aiRequestTransformerConfig) {
+        ChatModel chatModel = initAiModel(aiRequestTransformerConfig);
+        ChatClient chatClient = ChatClient.builder(chatModel).build();
+        CHAT_CLIENT_MAP.put(ruleId + aiRequestTransformerConfig.getProvider(), chatClient);
+        return chatClient;
+    }
+
+
+    /**
+     * Init chatModel.
+     *
+     * @param aiRequestTransformerConfig the aiRequestTransformerConfig.
+     * @return chatModel.
+     */
+    public ChatModel initAiModel(final AiRequestTransformerConfig aiRequestTransformerConfig) {
+        switch (Objects.requireNonNull(AiModelProviderEnum.getByName(aiRequestTransformerConfig.getProvider()))) {
+            case DEEP_SEEK :

Review Comment:
   use Factory Design Model, not switch case



##########
shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/template/AiRequestTransformerTemplate.java:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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.transformer.request.template;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.core.io.buffer.DataBufferUtils;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+
+
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * this is the aiRequestTransformerTemplate.
+ */
+public class AiRequestTransformerTemplate {
+
+    /**
+     * sysContent.
+     */
+    public static final String SYS_CONTENT = "你是HTTP/1.1协议专家,回答只包含标准HTTP/1.1报文内容。  \n"

Review Comment:
   english pls



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: ai-request-transformer plugin [shenyu]

Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 commented on PR #6033:
URL: https://github.com/apache/shenyu/pull/6033#issuecomment-2939624703

   1. fix ci
   2. add other sql type 
   3. add upgrade sql


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat: ai-request-transformer plugin [shenyu]

Posted by "Aias00 (via GitHub)" <gi...@apache.org>.
Aias00 merged PR #6033:
URL: https://github.com/apache/shenyu/pull/6033


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org