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-unsubscr...@shenyu.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org