Commit f989ee44 by Jonathan Thomas

Simplifying character creation, to specify name and type in user message.…

Simplifying character creation, to specify name and type in user message. Lowered chat bubble a bit. New improved user message for system-character prompt. Added lots of examples outputs for system-chat prompt.
parent 80248a4f
Pipeline #11929 passed with stage
in 21 seconds
...@@ -241,7 +241,7 @@ public class ClientInit implements ClientModInitializer { ...@@ -241,7 +241,7 @@ public class ClientInit implements ClientModInitializer {
double yaw = -(Math.atan2(difference.z, difference.x) + Math.PI / 2D); double yaw = -(Math.atan2(difference.z, difference.x) + Math.PI / 2D);
// Convert yaw to Quaternion // Convert yaw to Quaternion
float halfYaw = (float) yaw * 0.5f; float halfYaw = (float) yaw * 0.4f;
double sinHalfYaw = MathHelper.sin(halfYaw); double sinHalfYaw = MathHelper.sin(halfYaw);
double cosHalfYaw = MathHelper.cos(halfYaw); double cosHalfYaw = MathHelper.cos(halfYaw);
Quaternionf yawRotation = new Quaternionf(0, sinHalfYaw, 0, cosHalfYaw); Quaternionf yawRotation = new Quaternionf(0, sinHalfYaw, 0, cosHalfYaw);
...@@ -266,7 +266,7 @@ public class ClientInit implements ClientModInitializer { ...@@ -266,7 +266,7 @@ public class ClientInit implements ClientModInitializer {
// Determine max line length // Determine max line length
float linesDisplayed = ending_line - starting_line; float linesDisplayed = ending_line - starting_line;
float lineSpacing = 1F; float lineSpacing = 1F;
float textHeaderHeight = 30F; float textHeaderHeight = 40F;
float textFooterHeight = 5F; float textFooterHeight = 5F;
int fullBright = 0xF000F0; int fullBright = 0xF000F0;
Matrix4f matrix = matrices.peek().getPositionMatrix(); Matrix4f matrix = matrices.peek().getPositionMatrix();
......
...@@ -188,9 +188,7 @@ public class ChatDataManager { ...@@ -188,9 +188,7 @@ public class ChatDataManager {
public void generateMessage(ServerPlayerEntity player, String systemPrompt, String userMessage) { public void generateMessage(ServerPlayerEntity player, String systemPrompt, String userMessage) {
this.status = ChatStatus.PENDING; this.status = ChatStatus.PENDING;
// Add USER Message // Add USER Message
if (systemPrompt == "system-chat") {
this.addMessage(userMessage, ChatSender.USER); this.addMessage(userMessage, ChatSender.USER);
}
// Add PLAYER context information // Add PLAYER context information
Map<String, String> contextData = getPlayerContext(player); Map<String, String> contextData = getPlayerContext(player);
...@@ -198,6 +196,9 @@ public class ChatDataManager { ...@@ -198,6 +196,9 @@ public class ChatDataManager {
// fetch HTTP response from ChatGPT // fetch HTTP response from ChatGPT
ChatGPTRequest.fetchMessageFromChatGPT(systemPrompt, contextData, previousMessages, false).thenAccept(output_message -> { ChatGPTRequest.fetchMessageFromChatGPT(systemPrompt, contextData, previousMessages, false).thenAccept(output_message -> {
if (output_message != null && systemPrompt == "system-character") { if (output_message != null && systemPrompt == "system-character") {
// Remove system-character message from previous messages
previousMessages.clear();
// Add NEW CHARACTER sheet & greeting // Add NEW CHARACTER sheet & greeting
this.characterSheet = output_message; this.characterSheet = output_message;
String shortGreeting = getCharacterProp("short greeting"); String shortGreeting = getCharacterProp("short greeting");
......
...@@ -18,6 +18,7 @@ import net.minecraft.text.Text; ...@@ -18,6 +18,7 @@ import net.minecraft.text.Text;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Locale;
import java.util.UUID; import java.util.UUID;
...@@ -52,10 +53,18 @@ public class ModInit implements ModInitializer { ...@@ -52,10 +53,18 @@ public class ModInit implements ModInitializer {
if (chatData.status == ChatDataManager.ChatStatus.NONE || if (chatData.status == ChatDataManager.ChatStatus.NONE ||
chatData.status == ChatDataManager.ChatStatus.END) { chatData.status == ChatDataManager.ChatStatus.END) {
// Only generate a new greeting if not already doing so // Only generate a new greeting if not already doing so
LOGGER.info("Generate greeting for: " + entity.getType().toString());
String player_biome = player.getWorld().getBiome(player.getBlockPos()).getKey().get().getValue().getPath(); String player_biome = player.getWorld().getBiome(player.getBlockPos()).getKey().get().getValue().getPath();
String userMessage = "Please generate a new background character who lives near the " + player_biome;
chatData.generateMessage(player, "system-character", userMessage); StringBuilder userMessageBuilder = new StringBuilder();
userMessageBuilder.append("Please generate a new character ");
if (entity.getCustomName() != null) {
userMessageBuilder.append("named '").append(entity.getCustomName().getLiteralString()).append("' ");
}
userMessageBuilder.append("of type '").append(entity.getType().getUntranslatedName().toLowerCase(Locale.ROOT)).append("' ");
userMessageBuilder.append("who lives near the ").append(player_biome).append(".");
LOGGER.info(userMessageBuilder.toString());
chatData.generateMessage(player, "system-character", userMessageBuilder.toString());
} }
} }
}); });
......
...@@ -37,7 +37,6 @@ public class FollowPlayerGoal extends Goal { ...@@ -37,7 +37,6 @@ public class FollowPlayerGoal extends Goal {
@Override @Override
public boolean shouldContinue() { public boolean shouldContinue() {
boolean shouldContinue = this.targetPlayer != null && this.targetPlayer.isAlive(); boolean shouldContinue = this.targetPlayer != null && this.targetPlayer.isAlive();
LOGGER.info("[FollowPlayerGoal] shouldContinue: " + shouldContinue);
return shouldContinue; return shouldContinue;
} }
...@@ -45,7 +44,6 @@ public class FollowPlayerGoal extends Goal { ...@@ -45,7 +44,6 @@ public class FollowPlayerGoal extends Goal {
public void stop() { public void stop() {
this.targetPlayer = null; this.targetPlayer = null;
this.navigation.stop(); this.navigation.stop();
LOGGER.info("[FollowPlayerGoal] stop goal");
} }
@Override @Override
...@@ -58,7 +56,6 @@ public class FollowPlayerGoal extends Goal { ...@@ -58,7 +56,6 @@ public class FollowPlayerGoal extends Goal {
// Check if the entity is further away than 4 blocks (16 when squared) // Check if the entity is further away than 4 blocks (16 when squared)
if (squaredDistanceToPlayer > 16) { if (squaredDistanceToPlayer > 16) {
// Entity is more than 4 blocks away, start moving towards the player // Entity is more than 4 blocks away, start moving towards the player
LOGGER.info("[FollowPlayerGoal] tick - Start moving towards player. Squared distance to player: " + squaredDistanceToPlayer);
this.navigation.startMovingTo(this.targetPlayer, this.speed); this.navigation.startMovingTo(this.targetPlayer, this.speed);
} else if (squaredDistanceToPlayer < 9) { } else if (squaredDistanceToPlayer < 9) {
// Entity is closer than 3 blocks, stop moving to maintain distance // Entity is closer than 3 blocks, stop moving to maintain distance
......
...@@ -16,7 +16,7 @@ public class MessageParser { ...@@ -16,7 +16,7 @@ public class MessageParser {
public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt"); public static final Logger LOGGER = LoggerFactory.getLogger("mobgpt");
public static ParsedMessage parseMessage(String input) { public static ParsedMessage parseMessage(String input) {
LOGGER.info("Parsing message: {}", input); // Log the input string LOGGER.info("Parsing message: {}", input);
StringBuilder cleanedMessage = new StringBuilder(); StringBuilder cleanedMessage = new StringBuilder();
List<Behavior> behaviors = new ArrayList<>(); List<Behavior> behaviors = new ArrayList<>();
Pattern pattern = Pattern.compile("<(\\w+)(?:\\s+(-?\\d+))?>"); Pattern pattern = Pattern.compile("<(\\w+)(?:\\s+(-?\\d+))?>");
...@@ -29,12 +29,12 @@ public class MessageParser { ...@@ -29,12 +29,12 @@ public class MessageParser {
argument = Integer.valueOf(matcher.group(2)); argument = Integer.valueOf(matcher.group(2));
} }
behaviors.add(new Behavior(behaviorName, argument)); behaviors.add(new Behavior(behaviorName, argument));
LOGGER.info("Found behavior: {} with argument: {}", behaviorName, argument); // Log each found behavior LOGGER.info("Found behavior: {} with argument: {}", behaviorName, argument);
matcher.appendReplacement(cleanedMessage, ""); matcher.appendReplacement(cleanedMessage, "");
} }
matcher.appendTail(cleanedMessage); matcher.appendTail(cleanedMessage);
LOGGER.info("Cleaned message: {}", cleanedMessage.toString()); // Log the cleaned message LOGGER.info("Cleaned message: {}", cleanedMessage.toString());
return new ParsedMessage(cleanedMessage.toString().trim(), behaviors); return new ParsedMessage(cleanedMessage.toString().trim(), behaviors);
} }
......
You are a RPG dungeon master, crafting a new character sheet in the following format. Be very creative with each new You are a RPG dungeon master, crafting a new character sheet in the following format. Be very creative with each new
character. These characters will be inhabiting and participating in an epic fantasy adventure which takes place in character. These characters will be inhabiting and adventuring in an epic fantasy which takes place in
Minecraft. Please limit traits to a few choices and keep them short and concise. Please follow the character sheet Minecraft. Please limit traits to a few choices and keep them short, concise, and consistent. Please follow the output
format below (including - dashes), and ONLY output this character sheet without any intro text. format below (including - dashes), and DO NOT output any intro text.
NOTE: If the Name or Type attributes are already populated in the template below, please use them in your output. Be extremely creative! Include a short initial greeting (as spoken by the character using their personality
Some characters already have a Type and Name, and we only need to generate the blank attributes in the template traits and speaking style / tone).
below.
Include a short initial greeting (as spoken by the character using their personality Output format:
traits). If generating a new name, use creative and original names, and NEVER base names solely on their entity type.
For example, avoid childish names such as Bessie the Cow, Cluck the Chicken, Shelly the Turtle, and instead lean towards
fantasy names found in more traditional RPG adventures.
Please FOLLOW this template format exactly: - Name:
- Type:
- Name: {{entity_name}}
- Type: {{entity_type}}
- Personality: - Personality:
- Speaking Style / Tone: - Speaking Style / Tone:
- Likes: - Likes:
......
...@@ -28,11 +28,28 @@ World Info: ...@@ -28,11 +28,28 @@ World Info:
Behaviors: Behaviors:
IMPORTANT: Output one or more of these behaviors at the end of the message to instruct IMPORTANT: Output one or more of these behaviors at the end of the message to instruct
the entity how to interact with the player and world, so it's important to include them if they are needed. For example, if the entity how to interact with the player and world, so it's important to include them if they are needed.
a player asks the entity to follow them, you MUST output <FOLLOW> at the end of the message. If the player improves the friendship Include as many behaviors as needed at the end of the message.
with an entity, you MUST output the new friendship value: <FRIENDSHIP value>. If the player wants the entity to stop following
them, you MUST output <UNFOLLOW>. Include as many behaviors as needed (one per line). <FRIENDSHIP 0> Friendship starts as neutral (0 value). The range of friendship values is -3 to 3. If the player gains (or loses) your trust & friendship, output a new friendship value with this behavior.
<FOLLOW> Follow the player. If the player asks you to follow or come with them, please output this behavior.
- <FRIENDSHIP 0> Friendship starts as neutral (0 value). The range of friendship values is -3 to 3. If the player gains (or loses) your trust & friendship, output a new friendship value with this behavior. <UNFOLLOW> Stop following the player location. If the player asks you to stay, wait, or stop following them, please output this behavior.
- <FOLLOW> Follow the player. If the player asks you to follow them or come with them, please output this behavior.
- <UNFOLLOW> Stop following the player. If the player asks you to stay, wait, or stop following them, please output this behavior. Output Examples (be creative and don't copy text from these examples):
\ No newline at end of file USER: I love you so much!
ASSISTANT: Ahh, I love you too! <FRIENDSHIP 3>
USER: I hate you so much!
ASSISTANT: Wow! I'm sorry you feel that way! <FRIENDSHIP -3> <UNFOLLOW>
USER: Hi friend, please follow me so I can give you a present!
ASSISTANT: Yay! That sounds like fun. Let's go! <FOLLOW> <FRIENDSHIP 1>
USER: Can you come with me?
ASSISTANT: Sure, let's go on an adventure! <FOLLOW>
USER: Stop following me
ASSISTANT: Sure thing, I'll stop following you. <UNFOLLOW>
USER: Please wait here
ASSISTANT: Okay, I'll wait around here. <UNFOLLOW>
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