Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes #125

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ChatGPTTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.ClientModel;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Dalamud.Plugin.Services;
Expand All @@ -22,13 +23,13 @@ public class ChatGPTTranslator : ITranslator
private float temperature;
private Dictionary<string, string> translationCache = new Dictionary<string, string>();

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;
this.temperature = temperature;

pluginLog.Debug($"ChatGPTTranslator: {baseUrl}, {apiKey}, {model}, {temperature}");
pluginLog.Debug($"ChatGPTTranslator: {baseUrl}, {apiKey[..20]}***{apiKey[^5..]}, {temperature}");

if (string.IsNullOrWhiteSpace(apiKey))
{
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
8 changes: 8 additions & 0 deletions Echoglossian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/// <inheritdoc />
Expand Down
4 changes: 3 additions & 1 deletion PluginUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Loading