Skip to content

Commit

Permalink
可以自定义 chat 和 tts 的语言类型了
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Feb 14, 2025
1 parent 0960bbb commit cef398a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ public class AIConfig {
public static ForgeConfigSpec.BooleanValue CHAT_ENABLED;
public static ForgeConfigSpec.ConfigValue<String> CHAT_BASE_URL;
public static ForgeConfigSpec.ConfigValue<String> CHAT_MODEL;
public static ForgeConfigSpec.ConfigValue<String> CHAT_LANGUAGE;

public static ForgeConfigSpec.BooleanValue TTS_ENABLED;
public static ForgeConfigSpec.ConfigValue<String> TTS_BASE_URL;
public static ForgeConfigSpec.ConfigValue<String> TTS_MODEL;
public static ForgeConfigSpec.ConfigValue<String> TTS_LANGUAGE;

public static ForgeConfigSpec.IntValue MAID_MAX_HISTORY_CHAT_SIZE;

Expand All @@ -29,6 +31,9 @@ public static void init(ForgeConfigSpec.Builder builder) {
builder.comment("The chat AI model you intend to use");
CHAT_MODEL = builder.define("ChatModel", "deepseek-chat");

builder.comment("The chat language you intend to use");
CHAT_LANGUAGE = builder.define("ChatLanguage", "中文");

builder.comment("Whether or not to enable the TTS feature");
TTS_ENABLED = builder.define("TTSEnabled", true);

Expand All @@ -38,6 +43,9 @@ public static void init(ForgeConfigSpec.Builder builder) {
builder.comment("The TTS model you intend to use");
TTS_MODEL = builder.define("TTSModel", "4858e0be678c4449bf3a7646186edd42");

builder.comment("The TTS language you intend to use");
TTS_LANGUAGE = builder.define("TTSLanguage", "英文");

builder.comment("The maximum historical conversation length cached by the maid");
MAID_MAX_HISTORY_CHAT_SIZE = builder.defineInRange("MaidMaxHistoryChatSize", 16, 1, Integer.MAX_VALUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ static String replace(String input, EntityMaid maid) {
.replace("${mainhand_item}", getSlotItemName(EquipmentSlot.MAINHAND, maid))
.replace("${offhand_item}", getSlotItemName(EquipmentSlot.OFFHAND, maid))
.replace("${inventory_items}", getInventoryItems(maid))
.replace("${output_json_format}", getOutputJsonFormat());
.replace("${output_json_format}", getOutputJsonFormat())
.replace("${chat_language}", AIConfig.CHAT_LANGUAGE.get())
.replace("${tts_language}", AIConfig.TTS_LANGUAGE.get());
}

private static String getWeather(Level level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public AIChatConfigScreen(AIChatScreen parent) {
@Override
protected void init() {
int posX = this.width / 2;
int posY = this.height / 2;
int posY = this.height / 2 - 5;

this.configEditBoxes.clear();
this.configOnSave.clear();
Expand All @@ -49,13 +49,17 @@ private void createConfigBox(int posX, int posY) {
Component.translatable("ai.touhou_little_maid.chat.config.base_url"), v -> AIConfig.CHAT_BASE_URL.set(v));
createInputEditBox(posX - 203, posY + 20, AIConfig.CHAT_MODEL.get(),
Component.translatable("ai.touhou_little_maid.chat.config.model"), v -> AIConfig.CHAT_MODEL.set(v));
createInputEditBox(posX - 203, posY + 60, AIConfig.CHAT_LANGUAGE.get(),
Component.translatable("ai.touhou_little_maid.chat.config.language"), v -> AIConfig.CHAT_LANGUAGE.set(v));

createInputEditBox(posX + 3, posY - 60, ApiKeyManager.getTtsApiKey(), true,
Component.translatable("ai.touhou_little_maid.tts.config.api_key"), ApiKeyManager::setTtsApiKey);
createInputEditBox(posX + 3, posY - 20, AIConfig.TTS_BASE_URL.get(),
Component.translatable("ai.touhou_little_maid.tts.config.base_url"), v -> AIConfig.TTS_BASE_URL.set(v));
createInputEditBox(posX + 3, posY + 20, AIConfig.TTS_MODEL.get(),
Component.translatable("ai.touhou_little_maid.tts.config.model"), v -> AIConfig.TTS_MODEL.set(v));
createInputEditBox(posX + 3, posY + 60, AIConfig.TTS_LANGUAGE.get(),
Component.translatable("ai.touhou_little_maid.tts.config.language"), v -> AIConfig.TTS_LANGUAGE.set(v));
}

private void createCheckbox(int posX, int posY) {
Expand All @@ -80,14 +84,14 @@ public void onPress() {

private void createSaveExitButton(int posX, int posY) {
this.addRenderableWidget(Button.builder(Component.translatable("button.touhou_little_maid.maid.return"), b -> this.getMinecraft().setScreen(parent))
.pos(posX - 205, posY + 50).size(204, 20).build());
.pos(posX - 205, posY + 90).size(204, 20).build());
this.addRenderableWidget(Button.builder(Component.translatable("selectWorld.edit.save"), b -> {
for (int i = 0; i < this.configOnSave.size(); i++) {
EditBox editBox = this.configEditBoxes.get(i);
this.configOnSave.get(i).accept(editBox.getValue());
}
this.getMinecraft().setScreen(parent);
}).pos(posX + 1, posY + 50).size(204, 20).build());
}).pos(posX + 1, posY + 90).size(204, 20).build());
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"ai.touhou_little_maid.chat.config.api_key": "Chat API Key",
"ai.touhou_little_maid.chat.config.base_url": "Chat Base URL",
"ai.touhou_little_maid.chat.config.model": "Chat Model",
"ai.touhou_little_maid.chat.config.language": "Chat Language",
"ai.touhou_little_maid.tts.config.enable": "Whether or not to enable TTS",
"ai.touhou_little_maid.tts.config.api_key": "TTS API Key",
"ai.touhou_little_maid.tts.config.base_url": "TTS Base URL",
"ai.touhou_little_maid.tts.config.model": "TTS Model",
"ai.touhou_little_maid.tts.config.language": "TTS Language",
"advancements.touhou_little_maid.base.craft_gohei.description": "Craft a gohei",
"advancements.touhou_little_maid.base.craft_gohei.title": "The Key to Gensou?",
"advancements.touhou_little_maid.base.build_altar.description": "Build an altar, and let the fun begin",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/touhou_little_maid/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"ai.touhou_little_maid.chat.config.api_key": "对话 AI API Key",
"ai.touhou_little_maid.chat.config.base_url": "对话 AI Base URL",
"ai.touhou_little_maid.chat.config.model": "对话模型",
"ai.touhou_little_maid.chat.config.language": "对话语言",
"ai.touhou_little_maid.tts.config.enable": "是否启用 TTS",
"ai.touhou_little_maid.tts.config.api_key": "TTS API Key",
"ai.touhou_little_maid.tts.config.base_url": "TTS Base URL",
"ai.touhou_little_maid.tts.config.model": "TTS 模型",
"ai.touhou_little_maid.tts.config.language": "TTS 语言",
"advancements.touhou_little_maid.base.craft_gohei.description": "合成御币",
"advancements.touhou_little_maid.base.craft_gohei.title": "赤色幻想",
"advancements.touhou_little_maid.base.build_altar.description": "修建女仆模组的祭坛",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ format = """

# 回复语言类型
language = """
文字(chat_text)字段为中文回复,语音(tss_text)字段为中文回复翻译过来的英文回复
文字(chat_text)字段为${chat_language}回复,语音(tts_text)字段为${chat_language}回复翻译过来的${tts_language}回复
"""

0 comments on commit cef398a

Please sign in to comment.