From 17f7970259d3e3456fce1235fbdfaebf64268403 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Sat, 13 Apr 2024 16:08:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/config/YudaoAiAutoConfiguration.java | 32 +++++++ .../ai/config/YudaoAiProperties.java | 85 +++++++++++++++++++ ...ot.autoconfigure.AutoConfiguration.imports | 1 + .../src/main/resources/application-local.yaml | 37 ++++++-- 4 files changed, 146 insertions(+), 9 deletions(-) create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiAutoConfiguration.java create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiProperties.java create mode 100644 yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiAutoConfiguration.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiAutoConfiguration.java new file mode 100644 index 000000000..2725c9a33 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiAutoConfiguration.java @@ -0,0 +1,32 @@ +package cn.iocoder.yudao.framework.ai.config; + +import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatClient; +import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoOptions; +import cn.iocoder.yudao.framework.ai.chatxinghuo.api.XingHuoApi; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +/** + * ai 自动配置 + * + * @author fansili + * @time 2024/4/12 16:29 + * @since 1.0 + */ +@AutoConfiguration +@EnableConfigurationProperties(YudaoAiProperties.class) +public class YudaoAiAutoConfiguration { + + @Bean + public XingHuoChatClient xingHuoChatClient(YudaoAiProperties yudaoAiProperties) { + return new XingHuoChatClient( + new XingHuoApi( + yudaoAiProperties.getXingHuo().getAppId(), + yudaoAiProperties.getXingHuo().getAppKey(), + yudaoAiProperties.getXingHuo().getSecretKey() + ), + new XingHuoOptions().setChatModel(yudaoAiProperties.getXingHuo().getChatModel()) + ); + } +} diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiProperties.java b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiProperties.java new file mode 100644 index 000000000..2e7bff5c5 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/java/cn/iocoder/yudao/framework/ai/config/YudaoAiProperties.java @@ -0,0 +1,85 @@ +package cn.iocoder.yudao.framework.ai.config; + +import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; +import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatModel; +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * ai 自动配置 + * + * @author fansili + * @time 2024/4/12 16:29 + * @since 1.0 + */ +@Data +@ConfigurationProperties(prefix = "yudao.ai") +public class YudaoAiProperties { + + private QianWenProperties qianWen; + private XingHuoProperties xingHuo; + private YiYanProperties yiYan; + + @Data + @Accessors(chain = true) + public static class ChatProperties { + + private Float temperature; + + private Float topP; + + private Integer topK; + } + + @Data + @Accessors(chain = true) + public static class QianWenProperties extends ChatProperties { + /** + * 阿里云:服务器接入点 + */ + private String endpoint = "bailian.cn-beijing.aliyuncs.com"; + /** + * 阿里云:权限 accessKeyId + */ + private String accessKeyId; + /** + * 阿里云:权限 accessKeySecret + */ + private String accessKeySecret; + /** + * 阿里云:agentKey(相当于应用id) + */ + private String agentKey; + } + + @Data + @Accessors(chain = true) + public static class XingHuoProperties extends ChatProperties { + private String appId; + private String appKey; + private String secretKey; + private XingHuoChatModel chatModel; + } + + @Data + @Accessors(chain = true) + public static class YiYanProperties extends ChatProperties { + /** + * appKey + */ + private String appKey; + /** + * secretKey + */ + private String secretKey; + /** + * 模型 + */ + private YiYanChatModel chatModel = YiYanChatModel.ERNIE4_3_5_8K; + /** + * token 刷新时间(默认 86400 = 24小时) + */ + private int refreshTokenSecondTime = 86400; + } +} diff --git a/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 000000000..6eedc9cc8 --- /dev/null +++ b/yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +cn.iocoder.yudao.framework.ai.config.YudaoAiAutoConfiguration diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index cddf42014..59f1d0098 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -54,7 +54,7 @@ spring: # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.master.name} # SQLServer 连接的示例 # url: jdbc:dm://10.211.55.4:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 username: root - password: 123456 + password: root # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # username: SYSDBA # DM 连接的示例 @@ -68,7 +68,7 @@ spring: # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=${spring.datasource.dynamic.datasource.slave.name} # SQLServer 连接的示例 username: root - password: 123456 + password: root # username: sa # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W @@ -196,12 +196,12 @@ debug: false --- #################### 微信公众号、小程序相关配置 #################### wx: mp: # 公众号配置(必填),参见 https://github.com/Wechat-Group/WxJava/blob/develop/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md 文档 -# app-id: wx041349c6f39b268b # 测试号(牛希尧提供的) -# secret: 5abee519483bc9f8cb37ce280e814bd0 + # app-id: wx041349c6f39b268b # 测试号(牛希尧提供的) + # secret: 5abee519483bc9f8cb37ce280e814bd0 app-id: wx5b23ba7a5589ecbb # 测试号(自己的) secret: 2a7b3b20c537e52e74afd395eb85f61f -# app-id: wxa69ab825b163be19 # 测试号(Kongdy 提供的) -# secret: bd4f9fab889591b62aeac0d7b8d8b4a0 + # app-id: wxa69ab825b163be19 # 测试号(Kongdy 提供的) + # secret: bd4f9fab889591b62aeac0d7b8d8b4a0 # 存储配置,解决 AccessToken 的跨节点的共享 config-storage: type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 @@ -212,8 +212,8 @@ wx: # secret: 333ae72f41552af1e998fe1f54e1584a appid: wx63c280fe3248a3e7 # wenhualian的接口测试号 secret: 6f270509224a7ae1296bbf1c8cb97aed -# appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的) -# secret: 4a1a04e07f6a4a0751b39c3064a92c8b + # appid: wxc4598c446f8a9cb3 # 测试号(Kongdy 提供的) + # secret: 4a1a04e07f6a4a0751b39c3064a92c8b config-storage: type: RedisTemplate # 采用 RedisTemplate 操作 Redis,会自动从 Spring 中获取 key-prefix: wa # Redis Key 的前缀 @@ -223,6 +223,25 @@ wx: # 芋道配置项,设置当前项目所有自定义的配置 yudao: + ai: + temperature: 1 + topP: 1 + topK: 1 + qianWen: + endpoint: bailian.cn-beijing.aliyuncs.com + accessKeyId: LTAI5tNTVhXW4fLKUjMrr98z + accessKeySecret: ZJ0JQeyjzxxm5CfeTV6k1wNE9UsvZP + agentKey: f0c1088824594f589c8f10567ccd929f_p_efm + xingHuo: + appId: 13c8cca6 + appKey: cb6415c19d6162cda07b47316fcb0416 + secretKey: Y2JiYTIxZjA3MDMxMjNjZjQzYzVmNzdh + chatModel: XING_HUO_3_5 + yiYan: + appKey: x0cuLZ7XsaTCU08vuJWO87Lg + secretKey: R9mYF9dl9KASgi5RUq0FQt3wRisSnOcK + refreshTokenSecondTime: 86400 + chatModel: ERNIE4_3_5_8K captcha: enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试; security: @@ -235,6 +254,7 @@ yudao: pay: order-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址 refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 + access-log: # 访问日志的配置项 enable: false error-code: # 错误码相关配置项 @@ -267,7 +287,6 @@ justauth: type: REDIS prefix: 'social_auth_state:' # 缓存前缀,目前只对 Redis 缓存生效,默认 JUSTAUTH::STATE:: timeout: 24h # 超时时长,目前只对 Redis 缓存生效,默认 3 分钟 - # TODO 赤焰:这个配置的目的是? #ureport配置 #ureport: