feat(gpt): 支持切换 GPT 模型
- 新增配置项 GPT 用于选择 GPT 模型类型 - 实现 BaiduGPT 和 SiliconGPT 两种模型的切换逻辑 - 优化 SiliconGPTManager 初始化,支持自定义模型配置 - 更新 QQBot 版本号至 1.7.12
This commit is contained in:
parent
7637aa2fec
commit
9e062976ac
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version = "QQBot v.1.7.11.5";
|
||||
public static final String version = "QQBot v.1.7.12";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("version = " + version);
|
||||
|
@ -5,6 +5,8 @@ import com.yutou.qqbot.data.baidu.Message;
|
||||
import com.yutou.qqbot.data.gpt.OpenAiBean;
|
||||
import com.yutou.qqbot.http.GPTApi;
|
||||
import com.yutou.qqbot.http.GPTBuilder;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.File;
|
||||
@ -19,7 +21,12 @@ public class SiliconGPTManager extends AbsGPTManager {
|
||||
private volatile static SiliconGPTManager instance = new SiliconGPTManager();
|
||||
|
||||
private SiliconGPTManager() {
|
||||
setModel("deepseek-ai/DeepSeek-R1-Distill-Qwen-7B");
|
||||
val load = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.GPT_SILICON, String.class);
|
||||
String defModel = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B";
|
||||
if (!StringUtils.isEmpty(load)) {
|
||||
defModel = load;
|
||||
}
|
||||
setModel(defModel);
|
||||
}
|
||||
|
||||
public static SiliconGPTManager getInstance() {
|
||||
@ -44,10 +51,10 @@ public class SiliconGPTManager extends AbsGPTManager {
|
||||
}
|
||||
|
||||
val builder = GPTBuilder.create(model);
|
||||
List<Message> list=getMessageList(user);
|
||||
List<Message> list = getMessageList(user);
|
||||
list.add(Message.create(message));
|
||||
for (Message msg : list) {
|
||||
builder.addMessage(msg.getRole(),msg.getContent());
|
||||
builder.addMessage(msg.getRole(), msg.getContent());
|
||||
}
|
||||
val response = GPTApi.getApi().completions(builder.build()).execute();
|
||||
|
||||
@ -70,7 +77,7 @@ public class SiliconGPTManager extends AbsGPTManager {
|
||||
val choice = choices.get(choices.size() - 1);
|
||||
val bot = Message.create(choice.getMessage().getContent(), true);
|
||||
|
||||
list.add(bot);
|
||||
list.add(bot);
|
||||
return bot;
|
||||
|
||||
} catch (IOException e) {
|
||||
@ -104,7 +111,7 @@ public class SiliconGPTManager extends AbsGPTManager {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String model="THUDM/glm-4-9b-chat";
|
||||
String model = "THUDM/glm-4-9b-chat";
|
||||
val message = AbsGPTManager.getManager(SiliconGPTManager.class)
|
||||
.setModel(model)
|
||||
.sendMessage("user", "宫廷玉液酒的下一句是什么?");
|
||||
|
@ -13,6 +13,7 @@ import com.yutou.qqbot.gpt.BaiduGPTManager;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.File;
|
||||
@ -36,6 +37,22 @@ public class BaiduGPT extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
public BaiduGPT() {
|
||||
val load = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.GPT, String.class);
|
||||
if(!StringUtils.isEmpty(load)){
|
||||
switch (load){
|
||||
case "baidu":
|
||||
gptManager = BaiduGPTManager.class;
|
||||
break;
|
||||
case "silicon":
|
||||
gptManager = SiliconGPTManager.class;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
gptManager = BaiduGPTManager.class;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "百度文言一心GPT";
|
||||
|
@ -34,6 +34,8 @@ public class ConfigTools {
|
||||
public static final String BAIDU_GPT_SECRET_KEY = "baidu.gpt.SecretKey";
|
||||
public static final String TURNIP_PROPHET_SERVER = "turnip.server";
|
||||
public static final String TURNIP_PROPHET_SEND_TMP_GROUP = "turnip.send.tmp.group";
|
||||
public static final String GPT = "gpt.model";
|
||||
public static final String GPT_SILICON = "silicon.gpt.version";
|
||||
|
||||
|
||||
static {
|
||||
|
Loading…
x
Reference in New Issue
Block a user