【优化】模型enum统一交 model
This commit is contained in:
parent
a34d925973
commit
ca0024988c
|
@ -100,7 +100,7 @@ public class QianWenChatClient implements ChatClient, StreamingChatClient {
|
|||
messageList.add(message);
|
||||
});
|
||||
return QwenParam.builder()
|
||||
.model(qianWenApi.getQianWenChatModal().getValue())
|
||||
.model(qianWenApi.getQianWenChatModal().getModel())
|
||||
.prompt(prompt.getContents())
|
||||
.messages(messageList)
|
||||
.maxTokens(chatOptions.getMaxTokens())
|
||||
|
|
|
@ -34,5 +34,14 @@ public enum QianWenChatModal {
|
|||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
private String model;
|
||||
|
||||
public static QianWenChatModal valueOfModel(String model) {
|
||||
for (QianWenChatModal itemEnum : QianWenChatModal.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class XingHuoChatClient implements ChatClient, StreamingChatClient {
|
|||
// 创建 params
|
||||
XingHuoChatCompletionRequest.Parameter.Chat chatParameter = new XingHuoChatCompletionRequest.Parameter.Chat();
|
||||
BeanUtil.copyProperties(xingHuoOptions, chatParameter);
|
||||
chatParameter.setDomain(xingHuoOptions.getChatModel().getValue());
|
||||
chatParameter.setDomain(xingHuoOptions.getChatModel().getModel());
|
||||
XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter);
|
||||
// 创建 payload text 信息
|
||||
List<XingHuoChatCompletionRequest.Payload.Message.Text> texts = prompt.getInstructions().stream().map(message -> {
|
||||
|
|
|
@ -30,15 +30,24 @@ public enum XingHuoChatModel {
|
|||
|
||||
;
|
||||
|
||||
XingHuoChatModel(String name, String value, String uri) {
|
||||
XingHuoChatModel(String name, String model, String uri) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.model = model;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
private String value;
|
||||
private String model;
|
||||
|
||||
private String uri;
|
||||
|
||||
public static XingHuoChatModel valueOfModel(String model) {
|
||||
for (XingHuoChatModel itemEnum : XingHuoChatModel.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,8 +25,16 @@ public enum YiYanChatModel {
|
|||
|
||||
;
|
||||
|
||||
private String value;
|
||||
private String model;
|
||||
|
||||
private String uri;
|
||||
|
||||
public static YiYanChatModel valueOfModel(String model) {
|
||||
for (YiYanChatModel itemEnum : YiYanChatModel.values()) {
|
||||
if (itemEnum.getModel().equals(model)) {
|
||||
return itemEnum;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid MessageType value: " + model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,9 @@ import cn.iocoder.yudao.framework.ai.chatxinghuo.api.XingHuoApi;
|
|||
import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatClient;
|
||||
import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanOptions;
|
||||
import cn.iocoder.yudao.framework.ai.chatyiyan.api.YiYanApi;
|
||||
import cn.iocoder.yudao.framework.ai.imageopenai.OpenAiImageApi;
|
||||
import cn.iocoder.yudao.framework.ai.imageopenai.OpenAiImageClient;
|
||||
import cn.iocoder.yudao.framework.ai.imageopenai.OpenAiImageOptions;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
@ -32,7 +35,7 @@ public class YudaoAiAutoConfiguration {
|
|||
YudaoAiProperties.XingHuoProperties xingHuoProperties = yudaoAiProperties.getXinghuo();
|
||||
// 转换配置
|
||||
XingHuoOptions xingHuoOptions = new XingHuoOptions();
|
||||
xingHuoOptions.setChatModel(xingHuoProperties.getChatModel());
|
||||
xingHuoOptions.setChatModel(xingHuoProperties.getModel());
|
||||
xingHuoOptions.setTopK(xingHuoProperties.getTopK());
|
||||
xingHuoOptions.setTemperature(xingHuoProperties.getTemperature());
|
||||
xingHuoOptions.setMaxTokens(xingHuoProperties.getMaxTokens());
|
||||
|
@ -79,10 +82,24 @@ public class YudaoAiAutoConfiguration {
|
|||
new YiYanApi(
|
||||
yiYanProperties.getAppKey(),
|
||||
yiYanProperties.getSecretKey(),
|
||||
yiYanProperties.getChatModel(),
|
||||
yiYanProperties.getModel(),
|
||||
yiYanProperties.getRefreshTokenSecondTime()
|
||||
),
|
||||
yiYanOptions
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "yudao.ai.openAiImage.enable", havingValue = "true")
|
||||
public OpenAiImageClient openAiImageClient(YudaoAiProperties yudaoAiProperties) {
|
||||
YudaoAiProperties.OpenAiImageProperties openAiImageProperties = yudaoAiProperties.getOpenAiImage();
|
||||
// 创建 client
|
||||
return new OpenAiImageClient(
|
||||
new OpenAiImageApi(openAiImageProperties.getApiKey()),
|
||||
new OpenAiImageOptions()
|
||||
.setModel(openAiImageProperties.getModel())
|
||||
.setResponseFormat(OpenAiImageOptions.ResponseFormatEnum.URL.getValue())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.config;
|
|||
import cn.iocoder.yudao.framework.ai.AiPlatformEnum;
|
||||
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatModel;
|
||||
import cn.iocoder.yudao.framework.ai.imageopenai.OpenAiImageModelEnum;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
@ -23,6 +24,7 @@ public class YudaoAiProperties {
|
|||
private QianWenProperties qianwen;
|
||||
private XingHuoProperties xinghuo;
|
||||
private YiYanProperties yiyan;
|
||||
private OpenAiImageProperties openAiImage;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
|
@ -64,7 +66,7 @@ public class YudaoAiProperties {
|
|||
private String appId;
|
||||
private String appKey;
|
||||
private String secretKey;
|
||||
private XingHuoChatModel chatModel;
|
||||
private XingHuoChatModel model;
|
||||
}
|
||||
|
||||
@Data
|
||||
|
@ -81,12 +83,23 @@ public class YudaoAiProperties {
|
|||
/**
|
||||
* 模型
|
||||
*/
|
||||
private YiYanChatModel chatModel = YiYanChatModel.ERNIE4_3_5_8K;
|
||||
private YiYanChatModel model = YiYanChatModel.ERNIE4_3_5_8K;
|
||||
/**
|
||||
* token 刷新时间(默认 86400 = 24小时)
|
||||
*/
|
||||
private int refreshTokenSecondTime = 86400;
|
||||
}
|
||||
|
||||
private YiYanChatModel model;
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public static class OpenAiImageProperties {
|
||||
/**
|
||||
* api key
|
||||
*/
|
||||
private String apiKey;
|
||||
/**
|
||||
* 模型
|
||||
*/
|
||||
private OpenAiImageModelEnum model = OpenAiImageModelEnum.DALL_E_2;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue