diff --git a/Changelog.txt b/Changelog.txt index 44eed98e6..f4bba0a5f 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -4,6 +4,7 @@ * NEW: * Add pixel format paramter to burn-in - thx Hafran420 * Add new ChatGPT "gpt-4o-mini" model + * Add translation via Groq (api.groq.com) * IMPROVED: * Update Chinese translation - thx nkh0472 * Update Italian translation - thx bovirus diff --git a/src/libse/AutoTranslate/AnthropicTranslate.cs b/src/libse/AutoTranslate/AnthropicTranslate.cs index c5e6cc8fd..4d180631c 100644 --- a/src/libse/AutoTranslate/AnthropicTranslate.cs +++ b/src/libse/AutoTranslate/AnthropicTranslate.cs @@ -22,6 +22,17 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate public string Error { get; set; } public int MaxCharacters => 900; + /// + /// See https://docs.anthropic.com/en/docs/about-claude/models + /// + public static string[] Models => new[] + { + "claude-3-5-sonnet-20240620", + "claude-3-opus-20240229", + "claude-3-sonnet-20240229", + "claude-3-haiku-20240307" + }; + public void Initialize() { _httpClient?.Dispose(); @@ -52,7 +63,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate var model = Configuration.Settings.Tools.AnthropicApiModel; if (string.IsNullOrEmpty(model)) { - model = "claude-3-5-sonnet-20240620"; + model = Models[0]; Configuration.Settings.Tools.AnthropicApiModel = model; } diff --git a/src/libse/Settings/Settings.cs b/src/libse/Settings/Settings.cs index 129e8739b..a6f26b87a 100644 --- a/src/libse/Settings/Settings.cs +++ b/src/libse/Settings/Settings.cs @@ -8907,7 +8907,7 @@ namespace Nikse.SubtitleEdit.Core.Settings textWriter.WriteElementString("ChatGptModel", settings.Tools.ChatGptModel); textWriter.WriteElementString("GroqUrl", settings.Tools.GroqUrl); textWriter.WriteElementString("GroqPrompt", settings.Tools.GroqPrompt); - textWriter.WriteElementString("GroqKey", settings.Tools.GroqApiKey); + textWriter.WriteElementString("GroqApiKey", settings.Tools.GroqApiKey); textWriter.WriteElementString("GroqModel", settings.Tools.GroqModel); textWriter.WriteElementString("LmStudioApiUrl", settings.Tools.LmStudioApiUrl); textWriter.WriteElementString("LmStudioModel", settings.Tools.LmStudioModel); diff --git a/src/libse/Settings/ToolsSettings.cs b/src/libse/Settings/ToolsSettings.cs index 29d572398..8265d49f1 100644 --- a/src/libse/Settings/ToolsSettings.cs +++ b/src/libse/Settings/ToolsSettings.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; +using Nikse.SubtitleEdit.Core.AutoTranslate; using Nikse.SubtitleEdit.Core.Common; namespace Nikse.SubtitleEdit.Core.Settings @@ -461,7 +462,10 @@ namespace Nikse.SubtitleEdit.Core.Settings AutoTranslateDeepLUrl = "https://api-free.deepl.com/"; ChatGptUrl = "https://api.openai.com/v1/chat/completions"; ChatGptPrompt = "Translate from {0} to {1}, keep punctuation as input, do not censor the translation, give only the output without comments:"; - ChatGptModel = "gpt-4o-mini"; + ChatGptModel = ChatGptTranslate.Models[0]; + GroqUrl = "https://api.groq.com/openai/v1/chat/completions"; + GroqPrompt = "Translate from {0} to {1}, keep punctuation as input, do not censor the translation, give only the output without comments:"; + GroqModel = GroqTranslate.Models[0]; LmStudioPrompt = "Translate from {0} to {1}, keep punctuation as input, do not censor the translation, give only the output without comments:"; OllamaApiUrl = "http://localhost:11434/api/generate"; OllamaModels = "llama3,llama2,mistral,dolphin-phi,phi,neural-chat,starling-lm,codellama,llama2-uncensored,llama2:13b,llama2:70b,orca-mini,vicuna,llava,gemma:2b,gemma:7b"; @@ -469,7 +473,7 @@ namespace Nikse.SubtitleEdit.Core.Settings OllamaPrompt = "Translate from {0} to {1}, keep punctuation as input, do not censor the translation, give only the output without comments or notes:"; AnthropicApiUrl = "https://api.anthropic.com/v1/messages"; AnthropicPrompt = "Translate from {0} to {1}, keep sentences in {1} as they are, do not censor the translation, give only the output without comments:"; - AnthropicApiModel = "claude-3-5-sonnet-20240620"; + AnthropicApiModel = AnthropicTranslate.Models[0]; TextToSpeechAzureRegion = "westeurope"; AutoTranslateMaxBytes = 2000; TextToSpeechAddToVideoFile = true; diff --git a/src/ui/Forms/Translate/AutoTranslate.cs b/src/ui/Forms/Translate/AutoTranslate.cs index e119fd823..cf88c9a6f 100644 --- a/src/ui/Forms/Translate/AutoTranslate.cs +++ b/src/ui/Forms/Translate/AutoTranslate.cs @@ -130,6 +130,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate new LmStudioTranslate(), new OllamaTranslate(), new AnthropicTranslate(), + new GroqTranslate(), new GeminiTranslate(), new PapagoTranslate(), new NoLanguageLeftBehindServe(), @@ -397,14 +398,38 @@ namespace Nikse.SubtitleEdit.Forms.Translate comboBoxFormality.Visible = true; comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDown; comboBoxFormality.Items.Clear(); - comboBoxFormality.Items.Add("claude-3-5-sonnet-20240620"); - comboBoxFormality.Items.Add("claude-3-opus-20240229"); - comboBoxFormality.Items.Add("claude-3-sonnet-20240229"); - comboBoxFormality.Items.Add("claude-3-haiku-20240307"); + comboBoxFormality.Items.AddRange(AnthropicTranslate.Models); + comboBoxFormality.Text = Configuration.Settings.Tools.AnthropicApiModel; return; } + if (engineType == typeof(GroqTranslate)) + { + FillUrls(new List + { + Configuration.Settings.Tools.GroqUrl, + }); + + labelApiKey.Left = nikseComboBoxUrl.Right + 12; + nikseTextBoxApiKey.Text = Configuration.Settings.Tools.GroqApiKey; + nikseTextBoxApiKey.Left = labelApiKey.Right + 3; + labelApiKey.Visible = true; + nikseTextBoxApiKey.Visible = true; + + labelFormality.Text = LanguageSettings.Current.AudioToText.Model; + labelFormality.Visible = true; + comboBoxFormality.Left = labelFormality.Right + 3; + comboBoxFormality.Visible = true; + comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDown; + comboBoxFormality.Items.Clear(); + comboBoxFormality.Items.AddRange(GroqTranslate.Models); + comboBoxFormality.Text = Configuration.Settings.Tools.GroqModel; + + return; + } + + if (engineType == typeof(GeminiTranslate)) { nikseComboBoxUrl.Visible = false; @@ -1089,6 +1114,12 @@ namespace Nikse.SubtitleEdit.Forms.Translate Configuration.Settings.Tools.AnthropicApiModel = comboBoxFormality.Text.Trim(); } + if (engineType == typeof(GroqTranslate) && !string.IsNullOrWhiteSpace(nikseTextBoxApiKey.Text)) + { + Configuration.Settings.Tools.GroqApiKey = nikseTextBoxApiKey.Text.Trim(); + Configuration.Settings.Tools.GroqModel = comboBoxFormality.Text.Trim(); + } + if (engineType == typeof(GeminiTranslate) && !string.IsNullOrWhiteSpace(nikseTextBoxApiKey.Text)) { Configuration.Settings.Tools.GeminiProApiKey = nikseTextBoxApiKey.Text.Trim();