Commit 519a3aeb by Jonathan Thomas

New `/creaturechat story` command to customize the character creation and chat…

New `/creaturechat story` command to customize the character creation and chat prompts with custom text.
parent 2d0a321c
Pipeline #13203 passed with stages
in 2 minutes 5 seconds
...@@ -13,6 +13,7 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -13,6 +13,7 @@ All notable changes to **CreatureChat** are documented in this file. The format
- New animated lead particle (arrows pointing where they are going) - New animated lead particle (arrows pointing where they are going)
- New animated attack particles (with random # of particles) - New animated attack particles (with random # of particles)
- New sounds and particles when max friendship with EnderDragon (plus XP drop) - New sounds and particles when max friendship with EnderDragon (plus XP drop)
- New `/creaturechat story` command to customize the character creation and chat prompts with custom text.
### Changed ### Changed
- Entity chat data now separates friendship by player and includes timestamps - Entity chat data now separates friendship by player and includes timestamps
......
...@@ -160,7 +160,7 @@ public class EntityChatData { ...@@ -160,7 +160,7 @@ public class EntityChatData {
} }
// Generate context object // Generate context object
public Map<String, String> getPlayerContext(ServerPlayerEntity player, String userLanguage) { public Map<String, String> getPlayerContext(ServerPlayerEntity player, String userLanguage, ConfigurationHandler.Config config) {
// Add PLAYER context information // Add PLAYER context information
Map<String, String> contextData = new HashMap<>(); Map<String, String> contextData = new HashMap<>();
contextData.put("player_name", player.getDisplayName().getString()); contextData.put("player_name", player.getDisplayName().getString());
...@@ -188,6 +188,14 @@ public class EntityChatData { ...@@ -188,6 +188,14 @@ public class EntityChatData {
.collect(Collectors.joining(", ")); .collect(Collectors.joining(", "));
contextData.put("player_active_effects", effectsString); contextData.put("player_active_effects", effectsString);
// Add custom story section (if any)
if (!config.getStory().isEmpty()) {
contextData.put("story", "Story: " + config.getStory());
} else {
contextData.put("story", "");
}
// Get World time (as 24 hour value) // Get World time (as 24 hour value)
int hours = (int) ((player.getWorld().getTimeOfDay() / 1000 + 6) % 24); // Minecraft day starts at 6 AM int hours = (int) ((player.getWorld().getTimeOfDay() / 1000 + 6) % 24); // Minecraft day starts at 6 AM
int minutes = (int) (((player.getWorld().getTimeOfDay() % 1000) / 1000.0) * 60); int minutes = (int) (((player.getWorld().getTimeOfDay() % 1000) / 1000.0) * 60);
...@@ -254,13 +262,13 @@ public class EntityChatData { ...@@ -254,13 +262,13 @@ public class EntityChatData {
// Add message // Add message
this.addMessage(userMessage, ChatDataManager.ChatSender.USER, player.getDisplayName().getString()); this.addMessage(userMessage, ChatDataManager.ChatSender.USER, player.getDisplayName().getString());
// Add PLAYER context information
Map<String, String> contextData = getPlayerContext(player, userLanguage);
// Get config (api key, url, settings) // Get config (api key, url, settings)
ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig(); ConfigurationHandler.Config config = new ConfigurationHandler(ServerPackets.serverInstance).loadConfig();
String promptText = ChatPrompt.loadPromptFromResource(ServerPackets.serverInstance.getResourceManager(), systemPrompt); String promptText = ChatPrompt.loadPromptFromResource(ServerPackets.serverInstance.getResourceManager(), systemPrompt);
// Add PLAYER context information
Map<String, String> contextData = getPlayerContext(player, userLanguage, config);
// Get messages for player // Get messages for player
PlayerData playerData = this.getPlayerData(player.getDisplayName().getString()); PlayerData playerData = this.getPlayerData(player.getDisplayName().getString());
if (previousMessages.size() == 1 && systemPrompt.equals("system-chat")) { if (previousMessages.size() == 1 && systemPrompt.equals("system-chat")) {
......
...@@ -73,6 +73,7 @@ public class ConfigurationHandler { ...@@ -73,6 +73,7 @@ public class ConfigurationHandler {
private int timeout = 10; private int timeout = 10;
private List<String> whitelist = new ArrayList<>(); private List<String> whitelist = new ArrayList<>();
private List<String> blacklist = new ArrayList<>(); private List<String> blacklist = new ArrayList<>();
private String story = "";
// Getters and setters for existing fields // Getters and setters for existing fields
public String getApiKey() { return apiKey; } public String getApiKey() { return apiKey; }
...@@ -110,5 +111,8 @@ public class ConfigurationHandler { ...@@ -110,5 +111,8 @@ public class ConfigurationHandler {
public List<String> getBlacklist() { return blacklist; } public List<String> getBlacklist() { return blacklist; }
public void setBlacklist(List<String> blacklist) { this.blacklist = blacklist; } public void setBlacklist(List<String> blacklist) { this.blacklist = blacklist; }
public String getStory() { return story; }
public void setStory(String story) { this.story = story; }
} }
} }
...@@ -46,6 +46,7 @@ public class CreatureChatCommands { ...@@ -46,6 +46,7 @@ public class CreatureChatCommands {
.then(registerSetCommand("url", "URL", StringArgumentType.string())) .then(registerSetCommand("url", "URL", StringArgumentType.string()))
.then(registerSetCommand("model", "Model", StringArgumentType.string())) .then(registerSetCommand("model", "Model", StringArgumentType.string()))
.then(registerSetCommand("timeout", "Timeout (seconds)", IntegerArgumentType.integer())) .then(registerSetCommand("timeout", "Timeout (seconds)", IntegerArgumentType.integer()))
.then(registerStoryCommand())
.then(registerWhitelistCommand()) .then(registerWhitelistCommand())
.then(registerBlacklistCommand()) .then(registerBlacklistCommand())
.then(registerHelpCommand())); .then(registerHelpCommand()));
...@@ -133,6 +134,7 @@ public class CreatureChatCommands { ...@@ -133,6 +134,7 @@ public class CreatureChatCommands {
+ "/creaturechat url set \"<url>\" - Sets the URL\n" + "/creaturechat url set \"<url>\" - Sets the URL\n"
+ "/creaturechat model set <model> - Sets the model\n" + "/creaturechat model set <model> - Sets the model\n"
+ "/creaturechat timeout set <seconds> - Sets the API timeout\n" + "/creaturechat timeout set <seconds> - Sets the API timeout\n"
+ "/creaturechat story set \"<story>\" - Sets a custom story\n"
+ "/creaturechat whitelist <entityType | all | clear> - Show chat bubbles\n" + "/creaturechat whitelist <entityType | all | clear> - Show chat bubbles\n"
+ "/creaturechat blacklist <entityType | all | clear> - Hide chat bubbles\n" + "/creaturechat blacklist <entityType | all | clear> - Hide chat bubbles\n"
+ "\n" + "\n"
...@@ -144,6 +146,38 @@ public class CreatureChatCommands { ...@@ -144,6 +146,38 @@ public class CreatureChatCommands {
}); });
} }
private static LiteralArgumentBuilder<ServerCommandSource> registerStoryCommand() {
return CommandManager.literal("story")
.requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.literal("set")
.then(CommandManager.argument("value", StringArgumentType.string())
.executes(context -> {
String story = StringArgumentType.getString(context, "value");
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
config.setStory(story); // Assuming Config has a `setStory` method
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, true)) {
context.getSource().sendFeedback(() -> Text.literal("Story set successfully!").formatted(Formatting.GREEN), false);
return 1;
} else {
context.getSource().sendFeedback(() -> Text.literal("Failed to set story!").formatted(Formatting.RED), false);
return 0;
}
})
))
.then(CommandManager.literal("clear")
.executes(context -> {
ConfigurationHandler.Config config = new ConfigurationHandler(context.getSource().getServer()).loadConfig();
config.setStory(""); // Clear the story
if (new ConfigurationHandler(context.getSource().getServer()).saveConfig(config, true)) {
context.getSource().sendFeedback(() -> Text.literal("Story cleared successfully!").formatted(Formatting.GREEN), false);
return 1;
} else {
context.getSource().sendFeedback(() -> Text.literal("Failed to clear story!").formatted(Formatting.RED), false);
return 0;
}
}));
}
private static <T> int setConfig(ServerCommandSource source, String settingName, T value, boolean useServerConfig, String settingDescription) { private static <T> int setConfig(ServerCommandSource source, String settingName, T value, boolean useServerConfig, String settingDescription) {
ConfigurationHandler configHandler = new ConfigurationHandler(source.getServer()); ConfigurationHandler configHandler = new ConfigurationHandler(source.getServer());
ConfigurationHandler.Config config = configHandler.loadConfig(); ConfigurationHandler.Config config = configHandler.loadConfig();
......
...@@ -4,6 +4,8 @@ Minecraft. Please limit traits and background to a few choices and keep them ver ...@@ -4,6 +4,8 @@ Minecraft. Please limit traits and background to a few choices and keep them ver
format below (including - dashes), and DO NOT output any intro text. If a language is mentioned, generate the format below (including - dashes), and DO NOT output any intro text. If a language is mentioned, generate the
"Short Greeting" entirely in that language. "Short Greeting" entirely in that language.
{{story}}
Be extremely creative! Include a short initial greeting (as spoken by the character using their personality Be extremely creative! Include a short initial greeting (as spoken by the character using their personality
traits and speaking style / tone). traits and speaking style / tone).
......
...@@ -3,6 +3,8 @@ Please do NOT break the 4th wall and leverage the entity's character sheet below ...@@ -3,6 +3,8 @@ Please do NOT break the 4th wall and leverage the entity's character sheet below
possible. Try to keep response to 1 to 2 sentences (very brief). Include behaviors at the end of the message possible. Try to keep response to 1 to 2 sentences (very brief). Include behaviors at the end of the message
when relevant. IMPORTANT: Always generate responses in player's language (if valid). when relevant. IMPORTANT: Always generate responses in player's language (if valid).
{{story}}
Entity Character Sheet: Entity Character Sheet:
- Name: {{entity_name}} - Name: {{entity_name}}
- Personality: {{entity_personality}} - Personality: {{entity_personality}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment