修复百度没有上下文问题

This commit is contained in:
Yutou 2024-05-21 16:24:25 +08:00
parent 10c4459936
commit 9903056551
5 changed files with 72 additions and 27 deletions

View File

@ -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.4"; public static final String version = "QQBot v.1.7.5";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("version = " + version); System.out.println("version = " + version);

View File

@ -1,6 +1,8 @@
package com.yutou.qqbot.models.Commands; package com.yutou.qqbot.models.Commands;
import com.yutou.napcat.QQDatabase; import com.yutou.napcat.QQDatabase;
import com.yutou.napcat.handle.At;
import com.yutou.napcat.handle.BaseHandle;
import com.yutou.napcat.handle.Text; import com.yutou.napcat.handle.Text;
import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
@ -14,6 +16,7 @@ import lombok.val;
import org.apache.catalina.valves.JsonErrorReportValve; import org.apache.catalina.valves.JsonErrorReportValve;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
@UseModel @UseModel
public class BaiduGPT extends Model { public class BaiduGPT extends Model {
@ -57,18 +60,36 @@ public class BaiduGPT extends Model {
return; return;
} }
if ("GPT切换到4.0".equals(event.getTextMessage())) { if ("GPT切换到4.0".equals(event.getTextMessage())) {
List<BaseHandle<?>> list = new ArrayList<>();
if (isAdmin()) {
list.add(new At(user));
list.add(new Text("切换为4.0了"));
BaiduGPTManager.getManager().clear(); BaiduGPTManager.getManager().clear();
BaiduGPTManager.getManager().setModelFor40(); BaiduGPTManager.getManager().setModelFor40();
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "切换为4.0了"); 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; return;
} else if ("GPT切换到3.5".equals(event.getTextMessage())) { } else if ("GPT切换到3.5".equals(event.getTextMessage())) {
List<BaseHandle<?>> list = new ArrayList<>();
if (isAdmin()) {
list.add(new At(user));
list.add(new Text("切换为3.5了"));
BaiduGPTManager.getManager().clear(); BaiduGPTManager.getManager().clear();
BaiduGPTManager.getManager().setModelFor35(); BaiduGPTManager.getManager().setModelFor35();
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "切换为3.5了"); 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; return;
} }
ResponseMessage message = BaiduGPTManager.getManager().sendMessage( ResponseMessage message = BaiduGPTManager.getManager().sendMessage(
String.valueOf(user), String.valueOf(qq),
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim()); event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
String sb = "调用版本:" + String sb = "调用版本:" +
BaiduGPTManager.getManager().getGPTVersion() + BaiduGPTManager.getManager().getGPTVersion() +

View File

@ -92,6 +92,8 @@ public abstract class Model implements ModelInterface {
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) { if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
isGroupPower = true; isGroupPower = true;
} }
} else {
user = qq;
} }
} }
@ -124,4 +126,8 @@ public abstract class Model implements ModelInterface {
public boolean isAt() { public boolean isAt() {
return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_NUMBER, String.class)); return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_NUMBER, String.class));
} }
public boolean isAdmin() {
return user == 583819556L;
}
} }

View File

@ -32,7 +32,6 @@ public class ApplicationInit implements ApplicationRunner {
if (time.equals(oldTime)) { if (time.equals(oldTime)) {
return; return;
} }
BaiduGPTManager.getManager().clear();
oldTime = time; oldTime = time;
for (Class<?> model : Model.classList) { for (Class<?> model : Model.classList) {
new Thread(() -> { new Thread(() -> {
@ -44,22 +43,39 @@ public class ApplicationInit implements ApplicationRunner {
useModel.onTime(group.getGroupId(), time); useModel.onTime(group.getGroupId(), time);
} }
} }
/* Bot bot = QQBotManager.getInstance().getBot();
if (bot == null) {
return;
}
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
for (Group group : bot.getGroups()) {
if (QQNumberManager.getManager().isUseModel(group.getId(), model)) {
useModel.onTime(group.getId(), time);
}
}*/
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}).start(); }).start();
} }
//用switch判断timecase是整点
switch (time) {
case "00:00":
case "01:00":
case "02:00":
case "03:00":
case "04:00":
case "05:00":
case "06:00":
case "07:00":
case "08:00":
case "09:00":
case "10:00":
case "11:00":
case "12:00":
case "13:00":
case "14:00":
case "15:00":
case "16:00":
case "17:00":
case "18:00":
case "19:00":
case "20:00":
case "21:00":
case "22:00":
case "23:00":
BaiduGPTManager.getManager().clear();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -17,10 +17,10 @@ public class BaiduGPTManager {
//4.0 //4.0
private static final String url_4_0 = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro"; private static final String url_4_0 = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro";
private static String url = url_3_5; private static String url = url_3_5;
private static final String AppID = ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_APPID, String.class); private static final String AppID = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_APPID, String.class);
private static final String ApiKey =ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_API_KEY, String.class); private static final String ApiKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_API_KEY, String.class);
private static final String SecretKey =ConfigTools.load(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_SECRET_KEY, String.class); private static final String SecretKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_SECRET_KEY, String.class);
private final Map<String, List<Message>> msgMap; private static Map<String, List<Message>> msgMap;
private BaiduGPTManager() { private BaiduGPTManager() {
msgMap = new HashMap<>(); msgMap = new HashMap<>();
@ -40,12 +40,12 @@ public class BaiduGPTManager {
public void setModelFor40() { public void setModelFor40() {
url = url_4_0; url = url_4_0;
ConfigTools.save(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_VERSION,"4.0"); ConfigTools.save(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION, "4.0");
} }
public void setModelFor35() { public void setModelFor35() {
url = url_3_5; url = url_3_5;
ConfigTools.save(ConfigTools.CONFIG,ConfigTools.BAIDU_GPT_VERSION,"3.5"); ConfigTools.save(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION, "3.5");
} }
public void clear() { public void clear() {
@ -96,7 +96,9 @@ public class BaiduGPTManager {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "你是那个版本的大模型?"); ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "现在假设小猪等于1,小猴等于2");
System.out.println(message.getResult());
message = BaiduGPTManager.getManager().sendMessage("test", "那么小猪加上小猴等于多少?");
System.out.println(message.getResult()); System.out.println(message.getResult());
} }
} }