From c753d51e6b8af31b906abf64a1cff4d933fe7762 Mon Sep 17 00:00:00 2001 From: ddaodan <731882332@qq.com> Date: Fri, 16 Aug 2024 00:08:39 +0800 Subject: [PATCH] =?UTF-8?q?2.5=EF=BC=9AFolia=E6=94=AF=E6=8C=81=EF=BC=8Cfix?= =?UTF-8?q?=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- changelog.md | 3 ++ readme.md | 39 ++++++++++--------- .../ddaodan/MineChatGPT/CommandHandler.java | 3 +- .../MineChatGPT/ConversationContext.java | 4 +- src/main/resources/plugin.yml | 2 +- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index f6bb2ba..ceb29c6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'com' -version = '2.4' +version = '2.5' repositories { mavenCentral() diff --git a/changelog.md b/changelog.md index 8f1a61f..cfc0952 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # 更新日志 +## 2.5 +- 允许插件在Folia加载 +- 修复 #4:[BUG]部分情况下回复乱码 ## 2.4 - 添加自定义prompt - 移除了没有任何效果的配置文件自动更新功能 diff --git a/readme.md b/readme.md index 3f146e6..5b69a4a 100644 --- a/readme.md +++ b/readme.md @@ -5,17 +5,18 @@ 所有的代码都是ChatGPT写的哦 ## 功能 -- [x] OpenAPI格式 -- [x] 自定义模型 -- [x] ChatGPT反代 -- [x] 指令补全 -- [ ] 上下文对话 -- [ ] 自定义prompt +- OpenAPI格式 +- 自定义模型 +- ChatGPT反代 +- 指令补全 +- 上下文对话 +- 自定义prompt +- Folia支持 ## 安装 1. 下载插件,放在plugins文件夹中 2. 重启服务器 -> 为兼容更多版本,插件使用1.13版本进行构建,因此在较高版本加载插件时,控制台会出现以下错误信息,这属于正常现象。 +> 为兼容更多版本,插件没有规定Bukkit API version,因此在较高版本加载插件时,控制台可能会出现以下错误信息,这属于正常现象。 > ``` > [Server thread/WARN]: Initializing Legacy Material Support. Unless you have legacy plugins and/or data this is a bug! > [Server thread/WARN]: Legacy plugin MineChatGPT v1.0 does not specify an api-version. @@ -30,7 +31,7 @@ api: # OpenAI API 的基础 URL,用于构建请求 base_url: "https://api.openai.com/v1" ``` -4. 输入`/chatgpt reload`重新加载配置文件 +4. 在控制台中输入`/chatgpt reload`重新加载配置文件 ## 截图 - 服务端截图(Spigot 1.20.1) @@ -101,11 +102,13 @@ debug: false ## 指令与权限 |指令|权限|描述| |-|-|-| -|`/chatgpt`|chatgpt.use|查看插件帮助| -|`/chatgpt `|chatgpt.use|向ChatGPT提问| -|`/chatgpt reload`|chatgpt.reload|重新加载配置文件| -|`/chatgpt model `|chatgpt.model|切换至其他模型| -|`/chatgpt modellist`|chatgpt.modellist|查看可用的模型列表| +|`/chatgpt`|minechatgpt.use|查看插件帮助| +|`/chatgpt `|minechatgpt.use|向ChatGPT提问| +|`/chatgpt reload`|minechatgpt.reload|重新加载配置文件| +|`/chatgpt model `|minechatgpt.model|切换至其他模型| +|`/chatgpt modellist`|minechatgpt.modellist|查看可用的模型列表| +|`/chatgpt context`|minechatgpt.context|切换连续对话模式| +|`/chatgpt clear`|minechatgpt.clear|清空对话历史| ## 兼容的版本 只列出经过测试的版本 @@ -119,17 +122,17 @@ debug: false |KCauldron 1.7.10|× 不支持| ## 常见问题 -### `Failed to contact ChatGPT.` `无法联系ChatGPT。` +### 提问后显示`Failed to contact ChatGPT.` `无法联系ChatGPT。` 检查控制台输出的错误内容。 -### `connect timeout` `connect reset` +### 提问后后台有`connect timeout` `connect reset`等类似的提示 检查`config.yml`中的`base_url`能否正常访问。如果你无法连接到OpenAI官方的API地址,可以考虑使用其他反代。 ### 我可以添加其他模型吗? 可以,只要模型支持OpenAI的API,就可以使用。 -## 我没有ChatGPT的账号,可以用吗? +### 我没有ChatGPT的账号,可以用吗? 可以,目前有很多代理网站,可以很轻松地使用,而且还支持其他模型,费用通常来说也会比官方便宜。如果你愿意,也可以使用我的代理,目前仅在我的QQ群:226385797中提供。 ### 是否会支持Folia 理论上插件可以在Folia上运行,但插件的代码并没有针对Folia进行过优化,因此可能会有一些问题。如果你愿意,可以尝试使用Folia运行插件,但不保证插件可以正常运行。 ## 赞助 -![afdian-ddaodan.jpeg](https://i.ddaodan.cn/images/afdian-ddaodan.jpeg) +[![](https://i.ddaodan.cn/images/afdian-ddaodan.jpeg)](https://afdian.com/a/ddaodan) ## 统计 -![](https://bstats.org/signatures/bukkit/MineChatGPT.svg) \ No newline at end of file +[![](https://bstats.org/signatures/bukkit/MineChatGPT.svg)](https://bstats.org/plugin/bukkit/MineChatGPT/22635) \ No newline at end of file diff --git a/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java b/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java index f7feb18..23f0843 100644 --- a/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java +++ b/src/main/java/com/ddaodan/MineChatGPT/CommandHandler.java @@ -166,7 +166,8 @@ private void askChatGPT(CommandSender sender, String question, ConversationConte } if (response.statusCode() == 200) { String responseBody = response.bodyText(); - JSONObject jsonResponse = new JSONObject(responseBody); + String utf8ResponseBody = new String(responseBody.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8); + JSONObject jsonResponse = new JSONObject(utf8ResponseBody); String answer = jsonResponse.getJSONArray("choices").getJSONObject(0).getJSONObject("message").getString("content"); sender.sendMessage(configManager.getChatGPTResponseMessage().replace("%s", answer)); if (contextEnabled) { diff --git a/src/main/java/com/ddaodan/MineChatGPT/ConversationContext.java b/src/main/java/com/ddaodan/MineChatGPT/ConversationContext.java index 7eea1ad..1cdb283 100644 --- a/src/main/java/com/ddaodan/MineChatGPT/ConversationContext.java +++ b/src/main/java/com/ddaodan/MineChatGPT/ConversationContext.java @@ -14,9 +14,9 @@ public ConversationContext(int maxHistorySize) { public void addMessage(String message) { if (conversationHistory.size() >= maxHistorySize) { - conversationHistory.poll(); // Remove the oldest message + conversationHistory.poll(); } - conversationHistory.offer(message); // Add the new message + conversationHistory.offer(message); } public String getConversationHistory() { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 38427b2..db5fc22 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -25,6 +25,6 @@ permissions: minechatgpt.context: description: Allows toggling context mode default: true - chatgpt.clear: + minechatgpt.clear: description: Allows clearing conversation history default: true \ No newline at end of file