From f99f81723461ccc684c3316ee7075c3767d14aa9 Mon Sep 17 00:00:00 2001
From: weizhiqiang <598748873@qq.com>
Date: Sun, 6 Oct 2024 15:29:35 +0800
Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20AI=E4=BB=A3=E7=A0=81=E5=9B=9E?=
=?UTF-8?q?=E6=BB=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
skyeye-ai/.gitignore | 17 ++
skyeye-ai/ai-common/.gitignore | 17 ++
skyeye-ai/ai-common/pom.xml | 29 ++++
skyeye-ai/ai-pro/.gitignore | 17 ++
skyeye-ai/ai-pro/pom.xml | 62 +++++++
.../ai/core/config/AiConfiguration.java | 30 ++++
.../ai/core/config/SkyeyeAiProperties.java | 29 ++++
.../skyeye/ai/core/enums/AiPlatformEnum.java | 48 ++++++
.../com/skyeye/ai/core/factory/AiFactory.java | 63 +++++++
.../skyeye/ai/core/factory/AiFactoryImpl.java | 82 +++++++++
.../message/controller/MessageController.java | 41 +++++
.../message/service/MessageService.java | 22 +++
.../service/impl/MessageServiceImpl.java | 50 ++++++
skyeye-ai/ai-web/.gitignore | 17 ++
skyeye-ai/ai-web/pom.xml | 91 ++++++++++
.../java/com/skyeye/SkyAiApplication.java | 29 ++++
.../db/config/BaseDataSourceConfig.java | 163 ++++++++++++++++++
.../ai-web/src/main/resources/banner.txt | 34 ++++
.../ai-web/src/main/resources/bootstrap.yml | 47 +++++
.../ai-web/src/main/resources/jvm调优参数配置 | 22 +++
.../src/main/resources/log4j.properties | 70 ++++++++
skyeye-ai/pom.xml | 38 ++++
22 files changed, 1018 insertions(+)
create mode 100644 skyeye-ai/.gitignore
create mode 100644 skyeye-ai/ai-common/.gitignore
create mode 100644 skyeye-ai/ai-common/pom.xml
create mode 100644 skyeye-ai/ai-pro/.gitignore
create mode 100644 skyeye-ai/ai-pro/pom.xml
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/AiConfiguration.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/SkyeyeAiProperties.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/enums/AiPlatformEnum.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactory.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactoryImpl.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/message/controller/MessageController.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/message/service/MessageService.java
create mode 100644 skyeye-ai/ai-pro/src/main/java/com/skyeye/message/service/impl/MessageServiceImpl.java
create mode 100644 skyeye-ai/ai-web/.gitignore
create mode 100644 skyeye-ai/ai-web/pom.xml
create mode 100644 skyeye-ai/ai-web/src/main/java/com/skyeye/SkyAiApplication.java
create mode 100644 skyeye-ai/ai-web/src/main/java/com/skyeye/db/config/BaseDataSourceConfig.java
create mode 100644 skyeye-ai/ai-web/src/main/resources/banner.txt
create mode 100644 skyeye-ai/ai-web/src/main/resources/bootstrap.yml
create mode 100644 skyeye-ai/ai-web/src/main/resources/jvm调优参数配置
create mode 100644 skyeye-ai/ai-web/src/main/resources/log4j.properties
create mode 100644 skyeye-ai/pom.xml
diff --git a/skyeye-ai/.gitignore b/skyeye-ai/.gitignore
new file mode 100644
index 00000000..bdd1e1a8
--- /dev/null
+++ b/skyeye-ai/.gitignore
@@ -0,0 +1,17 @@
+*.class
+
+# Package Files #
+*.war
+*.ear
+
+class
+.idea
+*.iml
+.settings
+*.classpath
+/bin
+classes
+/target/
+/.project/
+/.metadata/
+/logs/
\ No newline at end of file
diff --git a/skyeye-ai/ai-common/.gitignore b/skyeye-ai/ai-common/.gitignore
new file mode 100644
index 00000000..bdd1e1a8
--- /dev/null
+++ b/skyeye-ai/ai-common/.gitignore
@@ -0,0 +1,17 @@
+*.class
+
+# Package Files #
+*.war
+*.ear
+
+class
+.idea
+*.iml
+.settings
+*.classpath
+/bin
+classes
+/target/
+/.project/
+/.metadata/
+/logs/
\ No newline at end of file
diff --git a/skyeye-ai/ai-common/pom.xml b/skyeye-ai/ai-common/pom.xml
new file mode 100644
index 00000000..41dc20e6
--- /dev/null
+++ b/skyeye-ai/ai-common/pom.xml
@@ -0,0 +1,29 @@
+
+
+
+ skyeye-ai
+ com.skyeye
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ ai-common
+
+
+ UTF-8
+
+
+
+
+
+
+ com.skyeye
+ skyeye-common-rest
+ 1.0-SNAPSHOT
+
+
+
+
+
\ No newline at end of file
diff --git a/skyeye-ai/ai-pro/.gitignore b/skyeye-ai/ai-pro/.gitignore
new file mode 100644
index 00000000..bdd1e1a8
--- /dev/null
+++ b/skyeye-ai/ai-pro/.gitignore
@@ -0,0 +1,17 @@
+*.class
+
+# Package Files #
+*.war
+*.ear
+
+class
+.idea
+*.iml
+.settings
+*.classpath
+/bin
+classes
+/target/
+/.project/
+/.metadata/
+/logs/
\ No newline at end of file
diff --git a/skyeye-ai/ai-pro/pom.xml b/skyeye-ai/ai-pro/pom.xml
new file mode 100644
index 00000000..73564168
--- /dev/null
+++ b/skyeye-ai/ai-pro/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+ skyeye-ai
+ com.skyeye
+ 1.0-SNAPSHOT
+
+ 4.0.0
+
+ ai-pro
+
+
+ UTF-8
+
+ 0.9.5.2
+ 1.0.25
+
+
+
+
+
+
+ com.skyeye
+ ai-common
+ 1.0-SNAPSHOT
+
+
+
+ org.apache.commons
+ commons-dbcp2
+ 2.1.1
+
+
+
+ com.jayway.jsonpath
+ json-path
+ 2.8.0
+
+
+
+
+ com.mchange
+ c3p0
+ ${c3p0.version}
+
+
+ com.alibaba
+ druid
+ ${druid.version}
+
+
+
+ com.baidubce
+ qianfan
+ 0.1.1
+
+
+
+
+
\ No newline at end of file
diff --git a/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/AiConfiguration.java b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/AiConfiguration.java
new file mode 100644
index 00000000..cffcd691
--- /dev/null
+++ b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/AiConfiguration.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
+ ******************************************************************************/
+
+package com.skyeye.ai.core.config;
+
+import com.skyeye.ai.core.factory.AiFactory;
+import com.skyeye.ai.core.factory.AiFactoryImpl;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @ClassName: AiConfiguration
+ * @Description: AI配置类
+ * @author: skyeye云系列--卫志强
+ * @date: 2024/8/18 22:10
+ * @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
+ * 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
+ */
+@Configuration
+@EnableConfigurationProperties(SkyeyeAiProperties.class)
+public class AiConfiguration {
+
+ @Bean
+ public AiFactory aiClientFactory() {
+ return new AiFactoryImpl();
+ }
+
+}
diff --git a/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/SkyeyeAiProperties.java b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/SkyeyeAiProperties.java
new file mode 100644
index 00000000..bb17a871
--- /dev/null
+++ b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/config/SkyeyeAiProperties.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
+ ******************************************************************************/
+
+package com.skyeye.ai.core.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @ClassName: SkyeyeAiProperties
+ * @Description: Skyeye AI 配置类
+ * @author: skyeye云系列--卫志强
+ * @date: 2024/10/5 18:03
+ * @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
+ * 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
+ */
+@Data
+@ConfigurationProperties(prefix = "spring.ai")
+public class SkyeyeAiProperties {
+
+ private QianfanProperties qianfan;
+
+ @Data
+ public static class QianfanProperties {
+ private String apiKey;
+ private String secretKey;
+ }
+}
diff --git a/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/enums/AiPlatformEnum.java b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/enums/AiPlatformEnum.java
new file mode 100644
index 00000000..198fa15a
--- /dev/null
+++ b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/enums/AiPlatformEnum.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
+ ******************************************************************************/
+
+package com.skyeye.ai.core.enums;
+
+import cn.hutool.core.util.StrUtil;
+import com.skyeye.common.base.classenum.SkyeyeEnumClass;
+import com.skyeye.exception.CustomException;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+
+/**
+ * @ClassName: AiPlatformEnum
+ * @Description: AI 模型平台
+ * @author: skyeye云系列--卫志强
+ * @date: 2024/10/5 11:33
+ * @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
+ * 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
+ */
+@Getter
+@NoArgsConstructor
+@AllArgsConstructor
+public enum AiPlatformEnum implements SkyeyeEnumClass {
+
+ YI_YAN("YiYan", "文心一言", "百度", true, false);
+
+ private String key;
+
+ private String value;
+
+ private String remark;
+
+ private Boolean show;
+
+ private Boolean isDefault;
+
+ public static AiPlatformEnum getName(String key) {
+ for (AiPlatformEnum bean : AiPlatformEnum.values()) {
+ if (StrUtil.equals(key, bean.getKey())) {
+ return bean;
+ }
+ }
+ throw new CustomException("非法的AI平台状态");
+ }
+
+}
diff --git a/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactory.java b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactory.java
new file mode 100644
index 00000000..44f16d62
--- /dev/null
+++ b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactory.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
+ ******************************************************************************/
+
+package com.skyeye.ai.core.factory;
+
+import com.skyeye.ai.core.enums.AiPlatformEnum;
+
+/**
+ * @ClassName: AiFactory
+ * @Description: AI Model 模型工厂的接口类
+ * @author: skyeye云系列--卫志强
+ * @date: 2024/10/5 11:33
+ * @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
+ * 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
+ */
+public interface AiFactory {
+
+ /**
+ * 基于指定配置,获得 ChatModel 对象
+ *
+ * 如果不存在,则进行创建
+ *
+ * @param platform 平台
+ * @param apiKey API KEY
+ * @param url API URL
+ * @return ChatModel 对象
+ */
+ Object getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String secretKey, String url);
+
+ /**
+ * 基于默认配置,获得 ChatModel 对象
+ *
+ * 默认配置,指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
+ *
+ * @param platform 平台
+ * @return ChatModel 对象
+ */
+ Object getDefaultChatModel(AiPlatformEnum platform);
+
+ /**
+ * 基于默认配置,获得 ImageModel 对象
+ *
+ * 默认配置,指的是在 application.yaml 配置文件中的 spring.ai 相关的配置
+ *
+ * @param platform 平台
+ * @return ImageModel 对象
+ */
+ Object getDefaultImageModel(AiPlatformEnum platform);
+
+ /**
+ * 基于指定配置,获得 ImageModel 对象
+ *
+ * 如果不存在,则进行创建
+ *
+ * @param platform 平台
+ * @param apiKey API KEY
+ * @param url API URL
+ * @return ImageModel 对象
+ */
+ Object getOrCreateImageModel(AiPlatformEnum platform, String apiKey, String url);
+
+}
diff --git a/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactoryImpl.java b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactoryImpl.java
new file mode 100644
index 00000000..4288ba1f
--- /dev/null
+++ b/skyeye-ai/ai-pro/src/main/java/com/skyeye/ai/core/factory/AiFactoryImpl.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright 卫志强 QQ:598748873@qq.com Inc. All rights reserved. 开源地址:https://gitee.com/doc_wei01/skyeye
+ ******************************************************************************/
+
+package com.skyeye.ai.core.factory;
+
+import cn.hutool.core.lang.Singleton;
+import cn.hutool.core.lang.func.Func0;
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baidubce.qianfan.Qianfan;
+import com.baidubce.qianfan.core.auth.Auth;
+import com.skyeye.ai.core.config.SkyeyeAiProperties;
+import com.skyeye.ai.core.enums.AiPlatformEnum;
+import com.skyeye.exception.CustomException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * @ClassName: AiFactoryImpl
+ * @Description: AI Model 模型工厂的实现类
+ * @author: skyeye云系列--卫志强
+ * @date: 2024/10/5 14:09
+ * @Copyright: 2024 https://gitee.com/doc_wei01/skyeye Inc. All rights reserved.
+ * 注意:本内容仅限购买后使用.禁止私自外泄以及用于其他的商业目的
+ */
+public class AiFactoryImpl implements AiFactory {
+
+ @Autowired
+ private SkyeyeAiProperties skyeyeAiProperties;
+
+ @Override
+ public Object getOrCreateChatModel(AiPlatformEnum platform, String apiKey, String secretKey, String url) {
+ String cacheKey = buildClientCacheKey(platform, apiKey, url);
+ return Singleton.get(cacheKey, (Func0