Browse Source

FeignClientBuilder bugfix

wangqi49 2 weeks ago
parent
commit
3be912f74f

+ 13 - 0
webchat-aigc/src/main/java/com/webchat/aigc/config/properties/AliBabaEmbeddingPropertiesConfig.java

@@ -0,0 +1,13 @@
+package com.webchat.aigc.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "llm.config.embedding.alibaba")
+public class AliBabaEmbeddingPropertiesConfig {
+
+    private String apiKey;
+}

+ 2 - 0
webchat-aigc/src/main/java/com/webchat/aigc/controller/BasicModelServiceController.java

@@ -0,0 +1,2 @@
+package com.webchat.aigc.controller;public class BasicModelServiceController {
+}

+ 2 - 0
webchat-aigc/src/main/java/com/webchat/aigc/llm/AbstractEmbeddingModel.java

@@ -0,0 +1,2 @@
+package com.webchat.aigc.llm;public class AbstractEmbeddingModel {
+}

+ 2 - 0
webchat-aigc/src/main/java/com/webchat/aigc/llm/AlibabaEmbeddingModel.java

@@ -0,0 +1,2 @@
+package com.webchat.aigc.llm;public class AlibabaEmbeddingModel {
+}

+ 2 - 0
webchat-aigc/src/main/java/com/webchat/aigc/llm/BasicEmbeddingModel.java

@@ -0,0 +1,2 @@
+package com.webchat.aigc.llm;public class BasicEmbeddingModel {
+}

+ 2 - 0
webchat-aigc/src/main/java/com/webchat/aigc/llm/BasicModelService.java

@@ -0,0 +1,2 @@
+package com.webchat.aigc.llm;public class BasicModelService {
+}

+ 63 - 0
webchat-aigc/src/main/java/com/webchat/aigc/llm/EmbeddingModelFactory.java

@@ -0,0 +1,63 @@
+package com.webchat.aigc.llm;
+
+import com.webchat.common.enums.LlmModelEnum;
+import com.webchat.common.exception.BusinessException;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author 程序员王七七 https://www.coderutil.com 网站作者
+ * @date 2024/10/29 22:47
+ *
+ * 抽象大模型对话工厂服务
+ */
+@Component
+public class LLMServiceFactory implements InitializingBean, ApplicationContextAware {
+
+    private ApplicationContext applicationContext;
+
+    private static final Map<String, AbstractLLMChatService> serviceMap = new HashMap<>();
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.applicationContext = applicationContext;
+    }
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        this.initServiceMap();
+    }
+
+    /**
+     * 初始化模型服务
+     */
+    private void initServiceMap() {
+        /**
+         * kimi
+         */
+        serviceMap.put(LlmModelEnum.KIMI.getModel(), applicationContext.getBean(KimiAIService.class));
+        /**
+         * deepseek
+         */
+        serviceMap.put(LlmModelEnum.DEEPSEEK.getModel(), applicationContext.getBean(DeepSeekAIService.class));
+
+        /**
+         * ollama
+         */
+        serviceMap.put(LlmModelEnum.OLLAMA.getModel(), applicationContext.getBean(OllamaService.class));
+    }
+
+    public static AbstractLLMChatService getLLMService(String model) {
+        AbstractLLMChatService llmChatService = serviceMap.get(model);
+        if (llmChatService == null) {
+            throw new BusinessException("不支持的模型");
+        }
+        return llmChatService;
+    }
+}

+ 19 - 0
webchat-common/src/main/java/com/webchat/common/enums/EmbeddingModelEnum.java

@@ -0,0 +1,19 @@
+package com.webchat.common.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum LlmModelEnum {
+
+    KIMI("kimi"),
+
+    DEEPSEEK("deepseek"),
+
+    OLLAMA("ollama");
+
+    private String model;
+
+    LlmModelEnum(String model) {
+        this.model = model;
+    }
+}

+ 8 - 0
webchat-common/src/main/java/com/webchat/common/enums/search/DataSourceTypeEnum.java

@@ -0,0 +1,8 @@
+package com.webchat.common.enums.search;
+
+
+import lombok.Getter;
+
+@Getter
+public enum DataSourceTypeEnum {
+}

+ 34 - 0
webchat-common/src/main/java/com/webchat/common/exception/AiCallException.java

@@ -0,0 +1,34 @@
+package com.webchat.common.exception;
+
+import com.webchat.common.enums.APIErrorCommonEnum;
+
+public class BusinessException extends RuntimeException {
+
+    private Integer code = 500;
+
+    public BusinessException() {
+        super();
+    }
+
+    public BusinessException(String msg) {
+        super(msg);
+    }
+
+    public BusinessException(APIErrorCommonEnum apiErrorCommonEnum) {
+        super(apiErrorCommonEnum.getMessage());
+        this.code = apiErrorCommonEnum.getCode();
+    }
+
+    public BusinessException(Integer code, String msg) {
+        super(msg);
+        this.code = code;
+    }
+
+    public BusinessException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+}

+ 4 - 0
webchat-domain/src/main/java/com/webchat/domain/dto/search/SyncSearchEngineDTO.java

@@ -0,0 +1,4 @@
+package com.webchat.domain.dto.search;
+
+public class SyncSearchEngineDTO {
+}

+ 35 - 0
webchat-domain/src/main/java/com/webchat/domain/dto/search/SyncSearchEngineListDTO.java

@@ -0,0 +1,35 @@
+package com.webchat.domain.dto.search;
+
+
+import com.webchat.domain.dto.queue.BaseQueueDTO;
+import lombok.Builder;
+import lombok.Data;
+
+@Data
+@Builder
+public class SyncSearchEngineDTO extends BaseQueueDTO {
+
+    /**
+     * 业务数据主键
+     */
+    private String pk;
+
+
+    /**
+     * 业务数据类型
+     * com.webchat.common.enums.search.DataSourceTypeEnum
+     */
+    private String sourceType;
+
+    /**
+     * 内容总结,如文章标题
+     */
+    private String summary;
+
+    /**
+     * 内容,主要对content做embedding
+     */
+    private String content;
+
+
+}

+ 2 - 0
webchat-remote/src/main/java/com/webchat/rmi/aigc/BasicModelServiceClient.java

@@ -0,0 +1,2 @@
+package com.webchat.rmi.aigc;public class BasicModelServiceClient {
+}

+ 7 - 8
webchat-remote/src/main/java/com/webchat/rmi/builder/FeignClientBuilder.java

@@ -31,16 +31,15 @@ public class FeignClientBuilder<T> {
                 .decoder(decoder)
                 .requestInterceptor(template -> template.header("Content-Type", "application/json"))
                 .contract(new SpringMvcContract());
-        return builder.target(targetClass, instanceHost);
 
         // 显式指定 name 和 URL
-//        Target<T> target = new Target.HardCodedTarget<>(
-//                targetClass,
-//                instanceHost,  // 自定义唯一标识
-//                instanceHost
-//        );
-//
-//        return builder.target(target);
+        Target<T> target = new Target.HardCodedTarget<>(
+                targetClass,
+                instanceHost,  // 自定义唯一标识
+                instanceHost
+        );
+
+        return builder.target(target);
     }
 
 }

+ 4 - 0
webchat-search/src/main/java/com/webchat/search/messagequeue/consumer/SyncDataRedisQueueConsumer.java

@@ -0,0 +1,4 @@
+package com.webchat.search.messagequeue.consumer;
+
+public class SyncDataRedisQueueConsumer {
+}