支持 自定义prompt

This commit is contained in:
ddaodan 2024-08-07 17:55:29 +08:00
parent aa8aadac49
commit acdfcda8db
4 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,6 @@
# 更新日志 # 更新日志
## 2.4
- 添加自定义prompt
## 2.3 ## 2.3
- 修复 #3[BUG]提问乱码/答非所问 - 修复 #3[BUG]提问乱码/答非所问
## 2.2 ## 2.2

View File

@ -128,10 +128,17 @@ public class CommandHandler implements CommandExecutor {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("model", configManager.getDefaultModel()); json.put("model", configManager.getDefaultModel());
JSONArray messages = new JSONArray(); JSONArray messages = new JSONArray();
// 添加自定义 prompt
String customPrompt = configManager.getCustomPrompt();
if (!customPrompt.isEmpty()) {
JSONObject promptMessage = new JSONObject();
promptMessage.put("role", "system");
promptMessage.put("content", customPrompt);
messages.put(promptMessage);
}
JSONObject message = new JSONObject(); JSONObject message = new JSONObject();
message.put("role", "user"); message.put("role", "user");
message.put("content", utf8Question); message.put("content", utf8Question);
//message.put("content", question);
messages.put(message); messages.put(message);
if (contextEnabled) { if (contextEnabled) {
String history = conversationContext.getConversationHistory(); String history = conversationContext.getConversationHistory();

View File

@ -56,6 +56,10 @@ public class ConfigManager {
return config.getStringList("models"); return config.getStringList("models");
} }
public String getCustomPrompt() {
return config.getString("prompt", "You are a helpful assistant.");
}
public String getHelpMessage() { public String getHelpMessage() {
return translateColorCodes(config.getString("messages.help")); return translateColorCodes(config.getString("messages.help"));
} }

View File

@ -28,6 +28,7 @@ conversation:
# Continuous conversation switch # Continuous conversation switch
context_enabled: false context_enabled: false
max_history_size: 10 max_history_size: 10
prompt: "You are a helpful assistant."
# Message settings # Message settings
messages: messages:
reload: "&aConfiguration reloaded successfully!" reload: "&aConfiguration reloaded successfully!"
@ -53,4 +54,4 @@ messages:
# If you don't know what this is, don't change it # If you don't know what this is, don't change it
debug: false debug: false
# DO NOT EDIT!!!!! # DO NOT EDIT!!!!!
version: 2.3 version: 2.4