feat:增加æ千帆支持文心一言
This commit is contained in:
parent
ae26772ef5
commit
0ec252123d
|
@ -67,6 +67,7 @@ public class AdiConstant {
|
|||
public static class SysConfigKey {
|
||||
public static final String OPENAI_SETTING = "openai_setting";
|
||||
public static final String DASHSCOPE_SETTING = "dashscope_setting";
|
||||
public static final String QIANFAN_SETTING = "qianfan_setting";
|
||||
public static final String REQUEST_TEXT_RATE_LIMIT = "request_text_rate_limit";
|
||||
public static final String REQUEST_IMAGE_RATE_LIMIT = "request_image_rate_limit";
|
||||
public static final String CONVERSATION_MAX_NUM = "conversation_max_num";
|
||||
|
|
|
@ -201,7 +201,7 @@ public class ConversationMessageService extends ServiceImpl<ConversationMessageM
|
|||
if (Boolean.TRUE.equals(conversation.getUnderstandContextEnable()) && user.getUnderstandContextMsgPairNum() > 0) {
|
||||
List<ConversationMessage> historyMsgList = this.lambdaQuery()
|
||||
.eq(ConversationMessage::getUserId, user.getId())
|
||||
.eq(ConversationMessage::getConversationId, askReq.getConversationUuid())
|
||||
.eq(ConversationMessage::getConversationUuid, askReq.getConversationUuid())
|
||||
.orderByDesc(ConversationMessage::getConversationId)
|
||||
.last("limit " + user.getUnderstandContextMsgPairNum() * 2)
|
||||
.list();
|
||||
|
|
|
@ -21,8 +21,8 @@ import static com.moyz.adi.common.enums.ErrorEnum.B_LLM_SECRET_KEY_NOT_SET;
|
|||
@Slf4j
|
||||
public class DashScopeLLMService extends AbstractLLMService<DashScopeSetting> {
|
||||
|
||||
public DashScopeLLMService(String modelName, Proxy proxy) {
|
||||
super(modelName, AdiConstant.SysConfigKey.DASHSCOPE_SETTING, DashScopeSetting.class, proxy);
|
||||
public DashScopeLLMService(String modelName) {
|
||||
super(modelName, AdiConstant.SysConfigKey.DASHSCOPE_SETTING, DashScopeSetting.class, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,8 @@ public class Initializer {
|
|||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyHttpPort));
|
||||
}
|
||||
LLMContext.addLLMService(OpenAiModelName.GPT_3_5_TURBO, new OpenAiLLMService(OpenAiModelName.GPT_3_5_TURBO, proxy));
|
||||
LLMContext.addLLMService(QwenModelName.QWEN_MAX, new DashScopeLLMService(QwenModelName.QWEN_MAX, proxy));
|
||||
LLMContext.addLLMService(QwenModelName.QWEN_MAX, new DashScopeLLMService(QwenModelName.QWEN_MAX));
|
||||
LLMContext.addLLMService("ERNIE-Bot", new QianFanLLMService("ERNIE-Bot"));
|
||||
ImageModelContext.addImageModelService(OpenAiModelName.DALL_E_2, new OpenAiImageModelService(OpenAiModelName.DALL_E_2, proxy));
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.moyz.adi.common.service;
|
||||
|
||||
import com.moyz.adi.common.cosntant.AdiConstant;
|
||||
import com.moyz.adi.common.interfaces.AbstractLLMService;
|
||||
import com.moyz.adi.common.vo.QianFanSetting;
|
||||
import dev.langchain4j.model.chat.ChatLanguageModel;
|
||||
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
|
||||
import dev.langchain4j.model.qianfan.QianfanChatModel;
|
||||
import dev.langchain4j.model.qianfan.QianfanStreamingChatModel;
|
||||
import lombok.experimental.Accessors;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* QianFan LLM service
|
||||
*/
|
||||
@Slf4j
|
||||
@Accessors(chain = true)
|
||||
public class QianFanLLMService extends AbstractLLMService<QianFanSetting> {
|
||||
|
||||
public QianFanLLMService(String modelName) {
|
||||
super(modelName, AdiConstant.SysConfigKey.QIANFAN_SETTING, QianFanSetting.class, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return StringUtils.isNoneBlank(setting.getApiKey(), setting.getSecretKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChatLanguageModel buildChatLLM() {
|
||||
return QianfanChatModel.builder()
|
||||
.modelName(modelName)
|
||||
.temperature(0.7)
|
||||
.topP(1.0)
|
||||
.maxRetries(1)
|
||||
.apiKey(setting.getApiKey())
|
||||
.secretKey(setting.getSecretKey())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected StreamingChatLanguageModel buildStreamingChatLLM() {
|
||||
return QianfanStreamingChatModel.builder()
|
||||
.modelName(modelName)
|
||||
.temperature(0.7)
|
||||
.topP(1.0)
|
||||
.apiKey(setting.getApiKey())
|
||||
.secretKey(setting.getSecretKey())
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.moyz.adi.common.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QianFanSetting {
|
||||
|
||||
@JsonProperty("api_key")
|
||||
private String apiKey;
|
||||
|
||||
@JsonProperty("secret_key")
|
||||
private String secretKey;
|
||||
}
|
|
@ -386,6 +386,8 @@ VALUES ('openai_setting', '{"secret_key":""}');
|
|||
INSERT INTO adi_sys_config (name, value)
|
||||
VALUES ('dashscope_setting', '{"api_key":""}');
|
||||
INSERT INTO adi_sys_config (name, value)
|
||||
VALUES ('qianfan_setting', '{"api_key":"","secret_key":""}');
|
||||
INSERT INTO adi_sys_config (name, value)
|
||||
VALUES ('request_text_rate_limit', '{"times":24,"minutes":3}');
|
||||
INSERT INTO adi_sys_config (name, value)
|
||||
VALUES ('request_image_rate_limit', '{"times":6,"minutes":3}');
|
||||
|
|
5
pom.xml
5
pom.xml
|
@ -165,6 +165,11 @@
|
|||
<artifactId>langchain4j-dashscope</artifactId>
|
||||
<version>${langchain4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-qianfan</artifactId>
|
||||
<version>${langchain4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
Loading…
Reference in New Issue