增加自动配置

This commit is contained in:
cherishsince 2024-04-13 16:08:47 +08:00
parent ec6ad9da74
commit 17f7970259
4 changed files with 146 additions and 9 deletions

View File

@ -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())
);
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1 @@
cn.iocoder.yudao.framework.ai.config.YudaoAiAutoConfiguration

View File

@ -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: