Allow change of ChatGPT model in translate window

This commit is contained in:
Nikolaj Olsson 2024-07-19 15:52:17 +02:00
parent f67cca37d1
commit 9b019db887
4 changed files with 22 additions and 6 deletions

View File

@ -2,6 +2,7 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats; using Nikse.SubtitleEdit.Core.SubtitleFormats;
using Nikse.SubtitleEdit.Core.Translate; using Nikse.SubtitleEdit.Core.Translate;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
@ -22,6 +23,10 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
public string Url => "https://chat.openai.com/"; public string Url => "https://chat.openai.com/";
public string Error { get; set; } public string Error { get; set; }
public int MaxCharacters => 1500; public int MaxCharacters => 1500;
public static string[] Models => new[]
{
"gpt-4o-mini", "gpt-4o", "gpt-4-turbo", "gpt-3.5-turbo", "gpt-4"
};
public static string RemovePreamble(string original, string translation) public static string RemovePreamble(string original, string translation)
{ {

View File

@ -6549,12 +6549,6 @@
this.nikseComboBoxChatGptModel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.nikseComboBoxChatGptModel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.nikseComboBoxChatGptModel.DropDownWidth = 375; this.nikseComboBoxChatGptModel.DropDownWidth = 375;
this.nikseComboBoxChatGptModel.FormattingEnabled = true; this.nikseComboBoxChatGptModel.FormattingEnabled = true;
this.nikseComboBoxChatGptModel.Items.AddRange(new string[] {
"gpt-4o-mini",
"gpt-4o",
"gpt-4-turbo",
"gpt-3.5-turbo",
"gpt-4"});
this.nikseComboBoxChatGptModel.Location = new System.Drawing.Point(52, 109); this.nikseComboBoxChatGptModel.Location = new System.Drawing.Point(52, 109);
this.nikseComboBoxChatGptModel.MaxLength = 32767; this.nikseComboBoxChatGptModel.MaxLength = 32767;
this.nikseComboBoxChatGptModel.Name = "nikseComboBoxChatGptModel"; this.nikseComboBoxChatGptModel.Name = "nikseComboBoxChatGptModel";

View File

@ -911,6 +911,9 @@ namespace Nikse.SubtitleEdit.Forms.Options
nikseTextBoxLibreTranslateApiKey.Left = labelLibreApiKey.Right + 3; nikseTextBoxLibreTranslateApiKey.Left = labelLibreApiKey.Right + 3;
nikseTextBoxLibreTranslateApiKey.Width = nikseTextBoxLibreTranslateUrl.Width - labelLibreApiKey.Width - 3; nikseTextBoxLibreTranslateApiKey.Width = nikseTextBoxLibreTranslateUrl.Width - labelLibreApiKey.Width - 3;
nikseComboBoxChatGptModel.Items.Clear();
nikseComboBoxChatGptModel.Items.AddRange(ChatGptTranslate.Models);
labelLibreUrl.Text = LanguageSettings.Current.Main.Url; labelLibreUrl.Text = LanguageSettings.Current.Main.Url;
labelNllbApiUrl.Text = LanguageSettings.Current.Main.Url; labelNllbApiUrl.Text = LanguageSettings.Current.Main.Url;
labelNllbServeUrl.Text = LanguageSettings.Current.Main.Url; labelNllbServeUrl.Text = LanguageSettings.Current.Main.Url;

View File

@ -14,6 +14,7 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Vosk;
using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox; using MessageBox = Nikse.SubtitleEdit.Forms.SeMsgBox.MessageBox;
using Timer = System.Windows.Forms.Timer; using Timer = System.Windows.Forms.Timer;
@ -308,6 +309,18 @@ namespace Nikse.SubtitleEdit.Forms.Translate
Configuration.Settings.Tools.ChatGptUrl.StartsWith("http://localhost:1234/v1/chat/completions", StringComparison.OrdinalIgnoreCase) ? "https://api.openai.com/v1/chat/completions" : "http://localhost:1234/v1/chat/completions" Configuration.Settings.Tools.ChatGptUrl.StartsWith("http://localhost:1234/v1/chat/completions", StringComparison.OrdinalIgnoreCase) ? "https://api.openai.com/v1/chat/completions" : "http://localhost:1234/v1/chat/completions"
}); });
labelFormality.Text = LanguageSettings.Current.AudioToText.Model;
labelFormality.Enabled = true;
labelFormality.Visible = true;
comboBoxFormality.DropDownStyle = ComboBoxStyle.DropDown;
comboBoxFormality.Items.Clear();
comboBoxFormality.Enabled = true;
comboBoxFormality.Left = labelFormality.Right + 3;
comboBoxFormality.Visible = true;
comboBoxFormality.Items.AddRange(ChatGptTranslate.Models);
comboBoxFormality.Text = Configuration.Settings.Tools.ChatGptModel;
labelApiKey.Left = nikseComboBoxUrl.Right + 12; labelApiKey.Left = nikseComboBoxUrl.Right + 12;
nikseTextBoxApiKey.Text = Configuration.Settings.Tools.ChatGptApiKey; nikseTextBoxApiKey.Text = Configuration.Settings.Tools.ChatGptApiKey;
nikseTextBoxApiKey.Left = labelApiKey.Right + 3; nikseTextBoxApiKey.Left = labelApiKey.Right + 3;
@ -1055,6 +1068,7 @@ namespace Nikse.SubtitleEdit.Forms.Translate
{ {
Configuration.Settings.Tools.ChatGptApiKey = nikseTextBoxApiKey.Text.Trim(); Configuration.Settings.Tools.ChatGptApiKey = nikseTextBoxApiKey.Text.Trim();
Configuration.Settings.Tools.ChatGptUrl = nikseComboBoxUrl.Text.Trim(); Configuration.Settings.Tools.ChatGptUrl = nikseComboBoxUrl.Text.Trim();
Configuration.Settings.Tools.ChatGptModel = comboBoxFormality.Text.Trim();
} }
if (engineType == typeof(LmStudioTranslate)) if (engineType == typeof(LmStudioTranslate))