不存在重大问题,但温度采样相关逻辑需要后需添加

This commit is contained in:
2024-12-21 20:52:39 +08:00
parent dba16e99c2
commit 4b41c6470c
11 changed files with 36 additions and 20 deletions

View File

@@ -18,7 +18,7 @@ dependencies{
implementation ("junit:junit:4.13.2")
implementation ("org.apache.logging.log4j:log4j-core:2.23.1")
implementation ("org.apache.logging.log4j:log4j-api:2.23.1")
implementation("top.mrxiaom.mirai:overflow-core-api:1.0.0.519-0d68f08-SNAPSHOT")
implementation("top.mrxiaom.mirai:overflow-core-all:1.0.0")
implementation ("com.alibaba:fastjson:1.2.73")
implementation ("org.projectlombok:lombok:1.18.36")

View File

@@ -9,6 +9,7 @@ import net.mamoe.mirai.event.events.MessageEvent;
import plugin.chat.constant.Constant;
import plugin.config.Config;
import plugin.config.CustomCommandTemplate;
import plugin.config.ModelConfigTemplate;
import plugin.listener.FriendMessageListener;
import plugin.listener.GroupMessageListener;
import plugin.listener.OwnerMessageListener;
@@ -117,7 +118,10 @@ public final class App extends JavaPlugin {
helpMsg[0] += "\r\n";
helpMsg[0] += "————<模型列表>————";
for (int i = 0; i < Config.ConfigLoader.getConfig().getModelConfigTemplates().size(); i++) {
helpMsg[0] += "\r\n\r\n"+"TemplateIndex: "+i+"\r\n"+Config.ConfigLoader.getConfig().getModelConfigTemplates().get(i).toString();
ModelConfigTemplate modelConfigTemplate = Config.ConfigLoader.getConfig().getModelConfigTemplates().get(i);
helpMsg[0] += "\r\n\r\n"+"TemplateIndex: "+i+"\r\n" +
"name: "+modelConfigTemplate.getTemplate_name() +
"base_url: "+modelConfigTemplate.getBase_url()+"\r\n";
}
event.getSubject().sendMessage(helpMsg[0]);
}

View File

@@ -55,12 +55,14 @@ public class ChatClient {
}
public void setPromotion(String promotion){
if (!promotion.equals("null")) {
Message message = Message.builder()
.role(Constant.Character.SYSTEM)
.content(promotion)
.build();
messages.add(0, message);
}
}
public ChatResponse runChat(String content){
HttpRequest request = HttpRequest.post(url+"/chat/completions");

View File

@@ -23,7 +23,7 @@ public class Constant {
public static final String MATCH_IMAGE = "\\[mirai:image:(.*?)]";
public static final String MATCH_MESSAGE = ".*[mirai:image:(https?://[\\w./?&amp;=]+)].*";
public static final String CUSTOM_SPLIT = "\\|";
public static final String ADD_CUSTOM = "/[a-zA-Z]+\\|.*\\|.*";
public static final String ADD_CUSTOM = "/[a-zA-Z]+\\|[0-9]+\\|.*\\|.*";
public static final String MODEL_CHANGE = ".*\\|.*";
}

View File

@@ -5,7 +5,9 @@ import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.inspector.TagInspector;
import plugin.chat.constant.Constant;
import java.io.File;
@@ -76,10 +78,10 @@ public class Config {
}
public static Config load() throws IOException {
Config config;
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Yaml yaml = new Yaml(dumperOptions);
LoaderOptions loaderOptions = new LoaderOptions();
TagInspector tagInspector = tag -> true;
loaderOptions.setTagInspector(tagInspector);
Yaml yaml = new Yaml(loaderOptions);
File file = new File(Constant.Path.CONFIG_PATH);
if (file.exists()) {
FileInputStream fileInputStream = new FileInputStream(Constant.Path.CONFIG_PATH);

View File

@@ -20,6 +20,6 @@ public class CustomCommandTemplate {
return "command: " + command + "\r\n" +
"modelTemplateIndex: " + modelTemplateIndex + "\r\n" +
"customModel: " + customModel + "\r\n" +
"customPromotion: " + customPromotion + "\r\n";
"customPromotion: " + customPromotion;
}
}

View File

@@ -36,7 +36,8 @@ public class FriendMessageListener extends SimpleListenerHost {
}
}
if (OCRUtil.isSupported && url != null) {
content = content + "```content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```";
content = content.replace("[图片]","```recognized_image_content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```");
// content = content + "```image content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```";
}
//处理消息头

View File

@@ -44,7 +44,7 @@ public class GroupMessageListener extends SimpleListenerHost {
}
}
if (OCRUtil.isSupported && url != null) {
content = content + "```content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```";
content = content.replace("[图片]","```recognized_image_content\r\n" + OCRUtil.getContentOfImage(url) + "\r\n```");
}
//消息头处理

View File

@@ -46,7 +46,7 @@ public class OwnerMessageListener extends SimpleListenerHost {
}
String instruction = primaryContent.split(Constant.Order.SPLIT_CUSTOM)[0];
String arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_GUN) + 1);
String arguments = primaryContent.substring(instruction.length() + 1);
long id = event.getSender().getId();
String response;
try {
@@ -64,7 +64,7 @@ public class OwnerMessageListener extends SimpleListenerHost {
String arguments;
try {
instruction = primaryContent.split(Constant.Order.SPLIT_CUSTOM)[0];
arguments = primaryContent.substring(primaryContent.indexOf(Constant.Order.SPLIT_CUSTOM) + 1);
arguments = primaryContent.substring(instruction.length()+1);
} catch (ArrayIndexOutOfBoundsException e) {
event.getFriend().sendMessage("操作失败,缺少参数");
return;

View File

@@ -27,8 +27,8 @@ public class ChatUtil {
private static void launchCleanerThread() {
Config config = Config.ConfigLoader.getConfig();
long timeout = Long.parseLong(config.getTimeout());
long timeCheck = Long.parseLong(config.getTimeCheck());
long timeout = Long.parseLong(config.getTimeout().substring(1));
long timeCheck = Long.parseLong(config.getTimeCheck().substring(1));
Thread thread = new Thread(() -> {
long currentTime = System.currentTimeMillis();
while (true) {
@@ -77,6 +77,7 @@ public class ChatUtil {
ChatClient chatClient = new ChatClient(chatId, url, apikey, customModel);
chatClient.setPromotion(customPromotion);
chatClients.put(chatId, chatClient);
log.info("final content: {}",content);
chatResponse = chatClient.runChat(content);
}
}

View File

@@ -126,6 +126,12 @@ public class MyTest {
MiraiConsoleTerminalLoader.INSTANCE.startAsDaemon(terminal);
PluginManager.INSTANCE.loadPlugin(App.INSTANCE);
PluginManager.INSTANCE.enablePlugin(App.INSTANCE);
new Scanner(System.in).nextLine();
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
while (true) {
if (input.equals("exit")) {
return;
}
}
}
}