【优化】模型enum统一交 model

This commit is contained in:
cherishsince 2024-04-28 14:37:31 +08:00
parent a34d925973
commit ca0024988c
7 changed files with 68 additions and 12 deletions

View File

@ -100,7 +100,7 @@ public class QianWenChatClient implements ChatClient, StreamingChatClient {
messageList.add(message); messageList.add(message);
}); });
return QwenParam.builder() return QwenParam.builder()
.model(qianWenApi.getQianWenChatModal().getValue()) .model(qianWenApi.getQianWenChatModal().getModel())
.prompt(prompt.getContents()) .prompt(prompt.getContents())
.messages(messageList) .messages(messageList)
.maxTokens(chatOptions.getMaxTokens()) .maxTokens(chatOptions.getMaxTokens())

View File

@ -34,5 +34,14 @@ public enum QianWenChatModal {
private String name; 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);
}
} }

View File

@ -114,7 +114,7 @@ public class XingHuoChatClient implements ChatClient, StreamingChatClient {
// 创建 params // 创建 params
XingHuoChatCompletionRequest.Parameter.Chat chatParameter = new XingHuoChatCompletionRequest.Parameter.Chat(); XingHuoChatCompletionRequest.Parameter.Chat chatParameter = new XingHuoChatCompletionRequest.Parameter.Chat();
BeanUtil.copyProperties(xingHuoOptions, chatParameter); BeanUtil.copyProperties(xingHuoOptions, chatParameter);
chatParameter.setDomain(xingHuoOptions.getChatModel().getValue()); chatParameter.setDomain(xingHuoOptions.getChatModel().getModel());
XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter); XingHuoChatCompletionRequest.Parameter parameter = new XingHuoChatCompletionRequest.Parameter().setChat(chatParameter);
// 创建 payload text 信息 // 创建 payload text 信息
List<XingHuoChatCompletionRequest.Payload.Message.Text> texts = prompt.getInstructions().stream().map(message -> { List<XingHuoChatCompletionRequest.Payload.Message.Text> texts = prompt.getInstructions().stream().map(message -> {

View File

@ -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.name = name;
this.value = value; this.model = model;
this.uri = uri; this.uri = uri;
} }
private String name; private String name;
private String value; private String model;
private String uri; 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);
}
} }

View File

@ -25,8 +25,16 @@ public enum YiYanChatModel {
; ;
private String value; private String model;
private String uri; 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);
}
} }

View File

@ -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.YiYanChatClient;
import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanOptions; import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanOptions;
import cn.iocoder.yudao.framework.ai.chatyiyan.api.YiYanApi; 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.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
@ -32,7 +35,7 @@ public class YudaoAiAutoConfiguration {
YudaoAiProperties.XingHuoProperties xingHuoProperties = yudaoAiProperties.getXinghuo(); YudaoAiProperties.XingHuoProperties xingHuoProperties = yudaoAiProperties.getXinghuo();
// 转换配置 // 转换配置
XingHuoOptions xingHuoOptions = new XingHuoOptions(); XingHuoOptions xingHuoOptions = new XingHuoOptions();
xingHuoOptions.setChatModel(xingHuoProperties.getChatModel()); xingHuoOptions.setChatModel(xingHuoProperties.getModel());
xingHuoOptions.setTopK(xingHuoProperties.getTopK()); xingHuoOptions.setTopK(xingHuoProperties.getTopK());
xingHuoOptions.setTemperature(xingHuoProperties.getTemperature()); xingHuoOptions.setTemperature(xingHuoProperties.getTemperature());
xingHuoOptions.setMaxTokens(xingHuoProperties.getMaxTokens()); xingHuoOptions.setMaxTokens(xingHuoProperties.getMaxTokens());
@ -79,10 +82,24 @@ public class YudaoAiAutoConfiguration {
new YiYanApi( new YiYanApi(
yiYanProperties.getAppKey(), yiYanProperties.getAppKey(),
yiYanProperties.getSecretKey(), yiYanProperties.getSecretKey(),
yiYanProperties.getChatModel(), yiYanProperties.getModel(),
yiYanProperties.getRefreshTokenSecondTime() yiYanProperties.getRefreshTokenSecondTime()
), ),
yiYanOptions 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())
);
}
} }

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.ai.config;
import cn.iocoder.yudao.framework.ai.AiPlatformEnum; import cn.iocoder.yudao.framework.ai.AiPlatformEnum;
import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel; import cn.iocoder.yudao.framework.ai.chatxinghuo.XingHuoChatModel;
import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatModel; import cn.iocoder.yudao.framework.ai.chatyiyan.YiYanChatModel;
import cn.iocoder.yudao.framework.ai.imageopenai.OpenAiImageModelEnum;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -23,6 +24,7 @@ public class YudaoAiProperties {
private QianWenProperties qianwen; private QianWenProperties qianwen;
private XingHuoProperties xinghuo; private XingHuoProperties xinghuo;
private YiYanProperties yiyan; private YiYanProperties yiyan;
private OpenAiImageProperties openAiImage;
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
@ -64,7 +66,7 @@ public class YudaoAiProperties {
private String appId; private String appId;
private String appKey; private String appKey;
private String secretKey; private String secretKey;
private XingHuoChatModel chatModel; private XingHuoChatModel model;
} }
@Data @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小时) * token 刷新时间(默认 86400 = 24小时)
*/ */
private int refreshTokenSecondTime = 86400; 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;
} }
} }