Skip to content

Commit

Permalink
7.5.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke100000 committed Feb 12, 2024
1 parent a6c7030 commit e031063
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# 7.5.13

* Updated chatAI to v2
* See https://github.com/Luke100000/minecraft-comes-alive/wiki/GPT3-based-conversations
* Older versions will no longer work, technical reasons
* Added TTS v2
* See https://github.com/Luke100000/minecraft-comes-alive/wiki/TTS

# 7.5.12

* Fixed various smaller issues
Expand Down
11 changes: 7 additions & 4 deletions common/src/main/java/net/mca/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,17 @@ public static Config getInstance() {
public int trackVillagerPositionEveryNTicks = 200;

//AI
public String _read_this_before_using_villager_ai = "https://github.com/Luke100000/minecraft-comes-alive/wiki/GPT3-based-conversations";
public boolean enableVillagerChatAI = false;
public int villagerChatAIIntelligence = 4;
public boolean enableOnlineTTS = false;
public String onlineTTSLanguage = "en";
public String villagerChatAIEndpoint = "https://chat.conczin.net/v1/mca/chat";
public String villagerChatAIEndpoint = "https://api.conczin.net/v1/mca/chat";
public String villagerChatAIToken = "";
public String villagerChatAIModel = "mistral-small";
public String villagerTTSServer = "https://api.rk.conczin.net/";
public String villagerTTSServer = "http://api.rk.conczin.net/";

// TTS
public boolean enableOnlineTTS = false;
public String onlineTTSLanguage = "en";

//village behavior
public float guardSpawnFraction = 0.175f;
Expand Down
12 changes: 8 additions & 4 deletions common/src/main/java/net/mca/entity/ai/GPT3.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Answer post(String url, String requestBody, String token) {

// Write the request body to the connection
try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
wr.writeBytes(requestBody);
wr.write(requestBody.getBytes(StandardCharsets.UTF_8));
wr.flush();
}

Expand Down Expand Up @@ -168,8 +168,10 @@ public static Optional<String> answer(ServerPlayerEntity player, VillagerEntityM

if (message.error == null) {
// remember
pastDialogue.add(new Pair<>("user", msg));
pastDialogue.add(new Pair<>("assistant", message.answer));
if (message.answer != null) {
pastDialogue.add(new Pair<>("user", msg));
pastDialogue.add(new Pair<>("assistant", message.answer));
}
return Optional.ofNullable(message.answer);
} else if (message.error.equals("invalid_model")) {
player.sendMessage(Text.literal("Invalid model!").formatted(Formatting.RED), false);
Expand Down Expand Up @@ -210,8 +212,10 @@ static String jsonStringQuote(String string) {
}

static String cleanupAnswer(String answer) {
answer = answer.replace("\"", "");
answer = answer.replace("\n", " ");
String[] parts = answer.split(":", 2);
return parts[parts.length - 1];
return parts[parts.length - 1].strip();
}

public static boolean inConversationWith(VillagerEntityMCA villager, ServerPlayerEntity player) {
Expand Down
10 changes: 6 additions & 4 deletions common/src/main/java/net/mca/server/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
.then(register("mail", Command::mail))
.then(register("verify").then(CommandManager.argument("email", StringArgumentType.greedyString()).executes(Command::verify)))
.then(register("chatAI")
.requires(p -> p.hasPermissionLevel(2) || p.getServer().isSingleplayer())
.executes(Command::chatAIHelp)
.then(CommandManager.argument("model", StringArgumentType.greedyString())
.then(CommandManager.argument("model", StringArgumentType.string())
.executes(c -> Command.chatAI(c.getArgument("model", String.class), (new Config()).villagerChatAIEndpoint, ""))
.then(CommandManager.argument("endpoint", StringArgumentType.greedyString())
.then(CommandManager.argument("endpoint", StringArgumentType.string())
.executes(c -> Command.chatAI(c.getArgument("model", String.class), c.getArgument("endpoint", String.class), ""))
.then(CommandManager.argument("token", StringArgumentType.greedyString())
.then(CommandManager.argument("token", StringArgumentType.string())
.executes(c -> Command.chatAI(c.getArgument("model", String.class), c.getArgument("endpoint", String.class), c.getArgument("token", String.class)))))))
.then(register("tts")
.requires(p -> p.getServer().isSingleplayer())
.then(CommandManager.literal("enable").then(CommandManager.argument("enabled", BoolArgumentType.bool()).executes(Command::ttsEnable)))
.then(CommandManager.literal("language").then(CommandManager.argument("language", StringArgumentType.string()).executes(Command::ttsLanguage)))
.then(CommandManager.literal("scan").requires(p -> p.getPlayer() != null && p.getPlayer().getEntityName().contains("Player")).executes(Command::ttsScan))
Expand All @@ -69,7 +71,7 @@ private static int chatAIHelp(CommandContext<ServerCommandSource> context) {
.withColor(Formatting.GOLD)
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://github.com/Luke100000/minecraft-comes-alive/wiki/GPT3-based-conversations")));
sendMessage(context, styled);
return 0;
return chatAI((new Config()).villagerChatAIModel, (new Config()).villagerChatAIEndpoint, (new Config()).villagerChatAIToken);
}

private static int chatAI(String model, String endpoint, String token) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/resources/assets/mca/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@
"subtitle.mca.villager.celebrate": "Villager Celebrating",

"mca.ai_broken": "AI broke, please send latest.log to dev!",
"mca.ai_help": "Click here to open the help page!",
"mca.ai_help": "AI enabled and reset to default. Click here to open the help page!",
"mca.limit.patreon": "You reached your hourly AI limit. Click here to open the tutorial on how to increase that limit!",
"mca.limit.premium": "You reached your hourly AI limit, even with your patreon subscription enabled! Please take a break.",
"mca.limit.patreon.hover": "Click me!",
Expand Down

0 comments on commit e031063

Please sign in to comment.