mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-24 20:22:41 +01:00
parent
4e165cc719
commit
aa3dcb00e6
@ -47,7 +47,14 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
|
||||
|
||||
public async Task<string> Translate(string text, string sourceLanguageCode, string targetLanguageCode, CancellationToken cancellationToken)
|
||||
{
|
||||
var input = "{\"model\": \"gpt-3.5-turbo\",\"messages\": [{ \"role\": \"user\", \"content\": \"Please translate the following text from " + sourceLanguageCode + " to " + targetLanguageCode + ", only write the result: \\n\\n" + Json.EncodeJsonText(text.Trim()) + "\" }]}";
|
||||
var model = Configuration.Settings.Tools.ChatGptApiKey;
|
||||
if (string.IsNullOrEmpty(model))
|
||||
{
|
||||
model = "gpt-3.5-turbo";
|
||||
Configuration.Settings.Tools.ChatGptApiKey = model;
|
||||
}
|
||||
|
||||
var input = "{\"model\": \"" + model + "\",\"messages\": [{ \"role\": \"user\", \"content\": \"Please translate the following text from " + sourceLanguageCode + " to " + targetLanguageCode + ", only write the result: \\n\\n" + Json.EncodeJsonText(text.Trim()) + "\" }]}";
|
||||
var content = new StringContent(input, Encoding.UTF8);
|
||||
content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
|
||||
var result = await _httpClient.PostAsync(string.Empty, content, cancellationToken);
|
||||
|
@ -175,6 +175,7 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
public bool TranslateViaCopyPasteAutoCopyToClipboard { get; set; }
|
||||
public string ChatGptUrl { get; set; }
|
||||
public string ChatGptApiKey { get; set; }
|
||||
public string ChatGptModel { get; set; }
|
||||
public int ChatGptDelaySeconds { get; set; }
|
||||
public string GeminiProApiKey { get; set; }
|
||||
public bool DisableVidoInfoViaLabel { get; set; }
|
||||
@ -530,6 +531,7 @@ namespace Nikse.SubtitleEdit.Core.Common
|
||||
AutoTranslateSeamlessM4TUrl = "http://localhost:5000/";
|
||||
AutoTranslateDeepLUrl = "https://api-free.deepl.com/";
|
||||
ChatGptUrl = "https://api.openai.com/v1/chat/completions";
|
||||
ChatGptModel = "gpt-3.5-turbo";
|
||||
TranslateAllowSplit = true;
|
||||
TranslateViaCopyPasteAutoCopyToClipboard = true;
|
||||
TranslateViaCopyPasteMaxSize = 5000;
|
||||
@ -5328,6 +5330,12 @@ $HorzAlign = Center
|
||||
settings.Tools.ChatGptApiKey = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("ChatGptModel");
|
||||
if (subNode != null)
|
||||
{
|
||||
settings.Tools.ChatGptModel = subNode.InnerText;
|
||||
}
|
||||
|
||||
subNode = node.SelectSingleNode("ChatGptDelaySeconds");
|
||||
if (subNode != null)
|
||||
{
|
||||
@ -11802,6 +11810,7 @@ $HorzAlign = Center
|
||||
textWriter.WriteElementString("TranslateViaCopyPasteAutoCopyToClipboard", settings.Tools.TranslateViaCopyPasteAutoCopyToClipboard.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("ChatGptUrl", settings.Tools.ChatGptUrl);
|
||||
textWriter.WriteElementString("ChatGptApiKey", settings.Tools.ChatGptApiKey);
|
||||
textWriter.WriteElementString("ChatGptModel", settings.Tools.ChatGptModel);
|
||||
textWriter.WriteElementString("ChatGptDelaySeconds", settings.Tools.ChatGptDelaySeconds.ToString(CultureInfo.InvariantCulture));
|
||||
textWriter.WriteElementString("GeminiProApiKey", settings.Tools.GeminiProApiKey);
|
||||
textWriter.WriteElementString("DisableVidoInfoViaLabel", settings.Tools.DisableVidoInfoViaLabel.ToString(CultureInfo.InvariantCulture));
|
||||
|
Loading…
Reference in New Issue
Block a user