From c2ee6e62d1272323ab58aa013e8f0ae70b74e427 Mon Sep 17 00:00:00 2001 From: kelvin124124 Date: Mon, 16 Dec 2024 18:43:11 +0800 Subject: [PATCH 1/4] fix url error for openai api --- ChatGPTTranslator.cs | 2 +- Config.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ChatGPTTranslator.cs b/ChatGPTTranslator.cs index c3eae3c..1b6f5cc 100644 --- a/ChatGPTTranslator.cs +++ b/ChatGPTTranslator.cs @@ -22,7 +22,7 @@ public class ChatGPTTranslator : ITranslator private float temperature; private Dictionary translationCache = new Dictionary(); - public ChatGPTTranslator(IPluginLog pluginLog, string baseUrl = "https://api.openai.com/v1/chat/completions", string apiKey = "", string model = "gpt-4o-mini", float temperature = 0.1f) + public ChatGPTTranslator(IPluginLog pluginLog, string baseUrl = "https://api.openai.com/v1", string apiKey = "", string model = "gpt-4o-mini", float temperature = 0.1f) { this.pluginLog = pluginLog; this.model = model; diff --git a/Config.cs b/Config.cs index 9abfb73..b54daa7 100644 --- a/Config.cs +++ b/Config.cs @@ -122,7 +122,7 @@ public class Config : IPluginConfiguration public string ChatGptApiKey = string.Empty; - public string ChatGPTBaseUrl = "https://api.openai.com/v1/chat/completions"; + public string ChatGPTBaseUrl = "https://api.openai.com/v1"; public string LlmModel = "gpt-4o-mini"; From a3e8eca99af0b71365ac314e0d68b6c987badb81 Mon Sep 17 00:00:00 2001 From: kelvin124124 Date: Thu, 19 Dec 2024 21:21:58 +0800 Subject: [PATCH 2/4] fix debug messages --- ChatGPTTranslator.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ChatGPTTranslator.cs b/ChatGPTTranslator.cs index 1b6f5cc..e7d3ed4 100644 --- a/ChatGPTTranslator.cs +++ b/ChatGPTTranslator.cs @@ -6,6 +6,7 @@ using System; using System.ClientModel; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Dalamud.Plugin.Services; @@ -28,7 +29,7 @@ public ChatGPTTranslator(IPluginLog pluginLog, string baseUrl = "https://api.ope this.model = model; this.temperature = temperature; - pluginLog.Debug($"ChatGPTTranslator: {baseUrl}, {apiKey}, {model}, {temperature}"); + pluginLog.Debug($"ChatGPTTranslator: {baseUrl}, {apiKey[..20]}***{apiKey[^5..]}, {temperature}"); if (string.IsNullOrWhiteSpace(apiKey)) { @@ -44,7 +45,7 @@ public ChatGPTTranslator(IPluginLog pluginLog, string baseUrl = "https://api.ope Endpoint = new Uri(baseUrl), }; - pluginLog.Debug($"ChatGPTTranslator: {clientOptions}"); + pluginLog.Debug($"ChatGPTTranslator: {string.Join(", ", clientOptions.GetType().GetProperties().Select(p => $"{p.Name}={p.GetValue(clientOptions)}"))}"); this.chatClient = new ChatClient(model, new ApiKeyCredential(apiKey), clientOptions); } From 8041b3302d764b46e3b0bb65672e021f6b35ff72 Mon Sep 17 00:00:00 2001 From: kelvin124124 Date: Thu, 19 Dec 2024 21:22:28 +0800 Subject: [PATCH 3/4] fix engine list indexing --- PluginUI.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PluginUI.cs b/PluginUI.cs index 11d4347..e6ef148 100644 --- a/PluginUI.cs +++ b/PluginUI.cs @@ -561,9 +561,11 @@ private void EchoglossianConfigUi() ImGui.Checkbox(Resources.TranslateTextsAgain, ref this.configuration.TranslateAlreadyTranslatedTexts); var engines = this.enginesList.Where((_, i) => langDict[languageInt].SupportedEngines.Contains(i)).ToArray(); + chosenTransEngine = Array.IndexOf(langDict[languageInt].SupportedEngines, this.configuration.ChosenTransEngine); if (ImGui.Combo(Resources.TranslationEngineChoose, ref chosenTransEngine, engines, engines.Length)) { - this.configuration.ChosenTransEngine = chosenTransEngine; + this.configuration.ChosenTransEngine = langDict[languageInt].SupportedEngines[chosenTransEngine]; + PluginLog.Debug("Chosen translation engine: " + this.configuration.ChosenTransEngine); this.translationService = new TranslationService(this.configuration, PluginLog, sanitizer); } From a2a08b4d8472f9b2e70937854eee6a21e45d2e78 Mon Sep 17 00:00:00 2001 From: kelvin124124 Date: Thu, 19 Dec 2024 21:24:56 +0800 Subject: [PATCH 4/4] fix wrong url in existing config --- Echoglossian.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Echoglossian.cs b/Echoglossian.cs index 889a9e5..7f9f99a 100644 --- a/Echoglossian.cs +++ b/Echoglossian.cs @@ -287,6 +287,14 @@ public Echoglossian() // Disabling BattleTalk translation by default if the language is not supported by the game font while we fix the overlays this.configuration.TranslateBattleTalk = this.configuration.OverlayOnlyLanguage ? false : true; this.configuration.UseImGuiForBattleTalk = false; + + // Fix wrong chatgpt base url in v3.17 + // TODO: remove it in later versions + if (this.configuration.ChatGPTBaseUrl == "https://api.openai.com/v1/chat/completions") + { + this.configuration.ChatGPTBaseUrl = "https://api.openai.com/v1/chat"; + PluginInterface.SavePluginConfig(this.configuration); + } } ///