feat(gpt): 支持硅基大模型并优化 GPT功能
- 新增对硅基大模型的支持,可通过指令切换使用 - 优化 GPT 模型切换逻辑,支持更多自定义选项 - 优化日志级别和网络请求超时设置
This commit is contained in:
parent
864d5960a7
commit
068964145f
@ -18,6 +18,7 @@ import retrofit2.Retrofit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class BaseApi {
|
public class BaseApi {
|
||||||
@ -97,6 +98,10 @@ public class BaseApi {
|
|||||||
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
|
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
|
||||||
OkHttpClient.Builder builder = new OkHttpClient()
|
OkHttpClient.Builder builder = new OkHttpClient()
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
|
.callTimeout(2, TimeUnit.MINUTES)
|
||||||
|
.readTimeout(2, TimeUnit.MINUTES)
|
||||||
|
.connectTimeout(2, TimeUnit.MINUTES)
|
||||||
|
.writeTimeout(2, TimeUnit.MINUTES)
|
||||||
.addInterceptor(initQuery())
|
.addInterceptor(initQuery())
|
||||||
.addInterceptor(loggingInterceptor);
|
.addInterceptor(loggingInterceptor);
|
||||||
return create(builder.build(),
|
return create(builder.build(),
|
||||||
|
@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class QQBotApplication {
|
public class QQBotApplication {
|
||||||
public static final String version = "QQBot v.1.7.10";
|
public static final String version = "QQBot v.1.7.11.4";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("version = " + version);
|
System.out.println("version = " + version);
|
||||||
|
@ -92,7 +92,7 @@ public abstract class AbsGPTManager {
|
|||||||
* @param tClass GPT管理器的具体实现类。
|
* @param tClass GPT管理器的具体实现类。
|
||||||
* @return GPT管理器实例。
|
* @return GPT管理器实例。
|
||||||
*/
|
*/
|
||||||
public static <T extends AbsGPTManager> AbsGPTManager getManager(Class<T> tClass) {
|
public static <T extends AbsGPTManager> AbsGPTManager getManager(Class<?> tClass) {
|
||||||
if (tClass == BaiduGPTManager.class) {
|
if (tClass == BaiduGPTManager.class) {
|
||||||
return BaiduGPTManager.getManager();
|
return BaiduGPTManager.getManager();
|
||||||
}else if(tClass== SiliconGPTManager.class){
|
}else if(tClass== SiliconGPTManager.class){
|
||||||
@ -131,7 +131,7 @@ public abstract class AbsGPTManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbsGPTManager setModel(String model) {
|
public AbsGPTManager setModel(String model) {
|
||||||
this.model=model;
|
this.model=model;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ public class SiliconGPTManager extends AbsGPTManager {
|
|||||||
private volatile static SiliconGPTManager instance = new SiliconGPTManager();
|
private volatile static SiliconGPTManager instance = new SiliconGPTManager();
|
||||||
|
|
||||||
private SiliconGPTManager() {
|
private SiliconGPTManager() {
|
||||||
|
setModel("deepseek-ai/DeepSeek-R1-Distill-Qwen-7B");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SiliconGPTManager getInstance() {
|
public static SiliconGPTManager getInstance() {
|
||||||
@ -37,7 +38,6 @@ public class SiliconGPTManager extends AbsGPTManager {
|
|||||||
// 获取或创建用户锁
|
// 获取或创建用户锁
|
||||||
AtomicBoolean lock = userLocks.computeIfAbsent(user, k -> new AtomicBoolean(false));
|
AtomicBoolean lock = userLocks.computeIfAbsent(user, k -> new AtomicBoolean(false));
|
||||||
try {
|
try {
|
||||||
GPTApi.setLog(false);
|
|
||||||
// 尝试加锁(如果已被锁定则立即返回提示)
|
// 尝试加锁(如果已被锁定则立即返回提示)
|
||||||
if (!lock.compareAndSet(false, true)) {
|
if (!lock.compareAndSet(false, true)) {
|
||||||
return Message.create("您有请求正在处理中,请稍后再试", true);
|
return Message.create("您有请求正在处理中,请稍后再试", true);
|
||||||
|
@ -6,6 +6,7 @@ import com.yutou.qqbot.Annotations.UseModel;
|
|||||||
import com.yutou.qqbot.QQBotManager;
|
import com.yutou.qqbot.QQBotManager;
|
||||||
import com.yutou.qqbot.data.baidu.Message;
|
import com.yutou.qqbot.data.baidu.Message;
|
||||||
import com.yutou.qqbot.gpt.AbsGPTManager;
|
import com.yutou.qqbot.gpt.AbsGPTManager;
|
||||||
|
import com.yutou.qqbot.gpt.SiliconGPTManager;
|
||||||
import com.yutou.qqbot.interfaces.DownloadInterface;
|
import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
import com.yutou.qqbot.gpt.BaiduGPTManager;
|
import com.yutou.qqbot.gpt.BaiduGPTManager;
|
||||||
@ -20,6 +21,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@UseModel
|
@UseModel
|
||||||
public class BaiduGPT extends Model {
|
public class BaiduGPT extends Model {
|
||||||
|
private Class<?> gptManager = SiliconGPTManager.class;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUserPublic() {
|
public boolean isUserPublic() {
|
||||||
@ -43,19 +45,28 @@ public class BaiduGPT extends Model {
|
|||||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||||
super.onMessage(qq, event, isGroup);
|
super.onMessage(qq, event, isGroup);
|
||||||
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
|
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
|
||||||
BaiduGPTManager.getManager().clear();
|
AbsGPTManager.getManager(gptManager).clear();
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
|
||||||
} else if (event.isAtMe()) {
|
} else if (event.isAtMe()) {
|
||||||
if (event.getTextMessage().contains("省流") || event.getTextMessage().contains("总结")) {
|
if (event.getTextMessage().contains("省流") || event.getTextMessage().contains("总结")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("GPT切换到4.0".equals(event.getTextMessage())) {
|
if (event.getTextMessage().contains("画画")) {
|
||||||
|
val file = BaiduGPTManager.getManager().textToImage(String.valueOf(qq), event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").replace("画画", "").trim());
|
||||||
|
if (file == null) {
|
||||||
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("画不出"));
|
||||||
|
} else {
|
||||||
|
QQBotManager.getInstance().sendMessage(file, qq, event.getMessageId().toString(), "好嘞");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else if (event.getTextMessage().contains("GPT切换到")) {
|
||||||
|
val text = event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").replace("切换到", "").trim();
|
||||||
List<BaseHandle<?>> list = new ArrayList<>();
|
List<BaseHandle<?>> list = new ArrayList<>();
|
||||||
if (isAdmin()) {
|
if (isAdmin()) {
|
||||||
list.add(new At(user));
|
list.add(new At(user));
|
||||||
list.add(new Text("切换为4.0了"));
|
list.add(new Text("切换为" + text));
|
||||||
BaiduGPTManager.getManager().clear();
|
AbsGPTManager.getManager(gptManager).clear();
|
||||||
BaiduGPTManager.getManager().setModelFor40();
|
AbsGPTManager.getManager(gptManager).setModel(text);
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||||
} else {
|
} else {
|
||||||
list.add(new At(user));
|
list.add(new At(user));
|
||||||
@ -63,62 +74,57 @@ public class BaiduGPT extends Model {
|
|||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if ("GPT切换到3.5".equals(event.getTextMessage())) {
|
}else if(event.getTextMessage().contains("大模型切换到")){
|
||||||
List<BaseHandle<?>> list = new ArrayList<>();
|
List<BaseHandle<?>> list = new ArrayList<>();
|
||||||
if (isAdmin()) {
|
val text = event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").replace("大模型切换到", "").trim();
|
||||||
list.add(new At(user));
|
if(text.contains("baidu")|| text.contains("百度")){
|
||||||
list.add(new Text("切换为3.5了"));
|
gptManager= BaiduGPTManager.class;
|
||||||
BaiduGPTManager.getManager().clear();
|
}else if(text.contains("silicon")||text.contains("硅基")){
|
||||||
BaiduGPTManager.getManager().setModelFor35();
|
gptManager= SiliconGPTManager.class;
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
|
||||||
}else {
|
|
||||||
list.add(new At(user));
|
|
||||||
list.add(new Text("你没有权限"));
|
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
|
||||||
}
|
}
|
||||||
return;
|
list.add(new At(user));
|
||||||
}else if(event.getTextMessage().contains("画画")){
|
list.add(new Text("切换为" + text));
|
||||||
val file = BaiduGPTManager.getManager().textToImage(String.valueOf(qq), event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").replace("画画", "").trim());
|
AbsGPTManager.getManager(gptManager).clear();
|
||||||
if(file==null){
|
AbsGPTManager.getManager(gptManager).setModel(text);
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("画不出"));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||||
}else{
|
|
||||||
QQBotManager.getInstance().sendMessage(file,qq, event.getMessageId().toString(), "好嘞");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if(checkImage()) {
|
if (checkImage()) {
|
||||||
parseImage(event, qq);
|
parseImage(event, qq);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
Message message = BaiduGPTManager.getManager().sendMessage(
|
Message message = AbsGPTManager.getManager(gptManager).sendMessage(
|
||||||
String.valueOf(qq),
|
String.valueOf(qq),
|
||||||
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
|
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
|
||||||
String sb = "调用版本:" +
|
String sb = "调用版本:" +
|
||||||
BaiduGPTManager.getManager().getGPTVersion() +
|
gptManager.getSimpleName()+
|
||||||
"\n" +
|
"\n" +
|
||||||
|
"使用模型:"+
|
||||||
|
AbsGPTManager.getManager(gptManager).getGPTVersion() +
|
||||||
|
"\n"+
|
||||||
message.getContent();
|
message.getContent();
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text(sb));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text(sb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseImage(MessageEvent event, Long qq) {
|
private void parseImage(MessageEvent event, Long qq) {
|
||||||
Image imageHandle = event.findType(Image.class);
|
Image imageHandle = event.findType(Image.class);
|
||||||
val replyHandle = event.findType(Reply.class);
|
val replyHandle = event.findType(Reply.class);
|
||||||
if (replyHandle != null &&imageHandle==null) {
|
if (replyHandle != null && imageHandle == null) {
|
||||||
imageHandle = getReply(replyHandle.getData().getId()).findType(Image.class);
|
imageHandle = getReply(replyHandle.getData().getId()).findType(Image.class);
|
||||||
|
}
|
||||||
|
if (imageHandle == null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(imageHandle==null){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HttpTools.download(imageHandle.getData().getUrl(), "gpt_parse_image.png", new DownloadInterface() {
|
HttpTools.download(imageHandle.getData().getUrl(), "gpt_parse_image.png", new DownloadInterface() {
|
||||||
@Override
|
@Override
|
||||||
public void onDownload(File file) {
|
public void onDownload(File file) {
|
||||||
super.onDownload(file);
|
super.onDownload(file);
|
||||||
if(file==null){
|
if (file == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
val text = BaiduGPTManager.getManager().imageToText(String.valueOf(qq), file);
|
val text = BaiduGPTManager.getManager().imageToText(String.valueOf(qq), file);
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(),qq,new Reply(event.getMessageId()),new Text(text));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Reply(event.getMessageId()), new Text(text));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<!-- 屏蔽 org.apache.hc.client5 包下的所有日志 -->
|
<!-- 屏蔽 org.apache.hc.client5 包下的所有日志 -->
|
||||||
<Logger name="org.apache.hc.client5" level="OFF"/>
|
<Logger name="org.apache.hc.client5" level="OFF"/>
|
||||||
<!-- 根日志记录器 -->
|
<!-- 根日志记录器 -->
|
||||||
<Root level="debug">
|
<Root level="info">
|
||||||
<AppenderRef ref="ConsoleAppender"/>
|
<AppenderRef ref="ConsoleAppender"/>
|
||||||
<AppenderRef ref="RoutingAppender"/>
|
<AppenderRef ref="RoutingAppender"/>
|
||||||
</Root>
|
</Root>
|
||||||
|
Loading…
Reference in New Issue
Block a user