More on custom prompt

This commit is contained in:
Nikolaj Olsson 2024-03-31 19:50:45 +02:00
parent c141068b4a
commit 2b3354fcd5
3 changed files with 18 additions and 4 deletions

View File

@ -19,7 +19,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
public string Name => StaticName;
public string Url => "https://www.anthropic.com/";
public string Error { get; set; }
public int MaxCharacters => 1500;
public int MaxCharacters => 900;
public void Initialize()
{
@ -55,7 +55,12 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
Configuration.Settings.Tools.AnthropicApiModel = model;
}
var input = "{ \"model\": \"" + model + "\", \"max_tokens\": 1024, \"messages\": [{ \"role\": \"user\", \"content\": \"Please translate the following text from " + sourceLanguageCode + " to " + targetLanguageCode + ", do not censor the translation, give only the output:\\n\\n" + Json.EncodeJsonText(text.Trim()) + "\" }]}";
if (string.IsNullOrEmpty(Configuration.Settings.Tools.AnthropicPrompt))
{
Configuration.Settings.Tools.AnthropicPrompt = "Translate from {0} to {1}, keep sentences in {1} as they are, do not censor the translation, give only the output without commenting on what you read:";
}
var prompt = string.Format(Configuration.Settings.Tools.AnthropicPrompt, sourceLanguageCode, targetLanguageCode);
var input = "{ \"model\": \"" + model + "\", \"max_tokens\": 1024, \"messages\": [{ \"role\": \"user\", \"content\": \"" + prompt + "\\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);

View File

@ -57,7 +57,7 @@ namespace Nikse.SubtitleEdit.Core.AutoTranslate
if (string.IsNullOrEmpty(Configuration.Settings.Tools.ChatGptPrompt))
{
Configuration.Settings.Tools.ChatGptPrompt = "Please translate the following text from {0} to {1}, do not censor the translation, give only the output:";
Configuration.Settings.Tools.ChatGptPrompt = "Translate from {0} to {1}, keep sentences in {1} as they are, do not censor the translation, give only the output without commenting on what you read:";
}
var prompt = string.Format(Configuration.Settings.Tools.ChatGptPrompt, sourceLanguageCode, targetLanguageCode);
var input = "{\"model\": \"" + model + "\",\"messages\": [{ \"role\": \"user\", \"content\": \"" + prompt + "\\n\\n" + Json.EncodeJsonText(text.Trim()) + "\" }]}";

View File

@ -178,6 +178,7 @@ namespace Nikse.SubtitleEdit.Core.Common
public string ChatGptApiKey { get; set; }
public string ChatGptModel { get; set; }
public string AnthropicApiUrl { get; set; }
public string AnthropicPrompt { get; set; }
public string AnthropicApiKey { get; set; }
public string AnthropicApiModel { get; set; }
public int AutoTranslateDelaySeconds { get; set; }
@ -536,9 +537,10 @@ namespace Nikse.SubtitleEdit.Core.Common
AutoTranslateSeamlessM4TUrl = "http://localhost:5000/";
AutoTranslateDeepLUrl = "https://api-free.deepl.com/";
ChatGptUrl = "https://api.openai.com/v1/chat/completions";
ChatGptPrompt = "Please translate the following text from {0} to {1}, do not censor the translation, give only the output:";
ChatGptPrompt = "Translate from {0} to {1}, keep sentences in {1} as they are, do not censor the translation, give only the output without commenting on what you read:";
ChatGptModel = "gpt-3.5-turbo";
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 commenting on what you read:";
AnthropicApiModel = "claude-3-opus-20240229";
TranslateAllowSplit = true;
TranslateViaCopyPasteAutoCopyToClipboard = true;
@ -5371,6 +5373,12 @@ $HorzAlign = Center
settings.Tools.AnthropicApiUrl = subNode.InnerText;
}
subNode = node.SelectSingleNode("AnthropicPrompt");
if (subNode != null)
{
settings.Tools.AnthropicPrompt = subNode.InnerText;
}
subNode = node.SelectSingleNode("AnthropicApiKey");
if (subNode != null)
{
@ -11898,6 +11906,7 @@ $HorzAlign = Center
textWriter.WriteElementString("ChatGptApiKey", settings.Tools.ChatGptApiKey);
textWriter.WriteElementString("ChatGptModel", settings.Tools.ChatGptModel);
textWriter.WriteElementString("AnthropicApiUrl", settings.Tools.AnthropicApiUrl);
textWriter.WriteElementString("AnthropicPrompt", settings.Tools.AnthropicPrompt);
textWriter.WriteElementString("AnthropicApiKey", settings.Tools.AnthropicApiKey);
textWriter.WriteElementString("AnthropicApiModel", settings.Tools.AnthropicApiModel);
textWriter.WriteElementString("AutoTranslateDelaySeconds", settings.Tools.AutoTranslateDelaySeconds.ToString(CultureInfo.InvariantCulture));