Skip to content
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
73 changes: 68 additions & 5 deletions src/ui/Features/Translate/AutoTranslateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public partial class AutoTranslateViewModel : ObservableObject
[ObservableProperty] private LlamaCppModelDisplay? _selectedLlamaCppModel;
[ObservableProperty] private bool _llamaCppModelComboIsVisible;
[ObservableProperty] private bool _llamaCppButtonsAreVisible;
[ObservableProperty] private bool _llamaCppRemoteToggleIsVisible;
[ObservableProperty] private bool _llamaCppUseRemoteServer;
[ObservableProperty] private string _llamaCppServerButtonText = "Start server";
[ObservableProperty] private string _llamaCppDownloadButtonText = string.Empty;
[ObservableProperty] private string _crispAsrDownloadButtonText = string.Empty;
Expand All @@ -107,6 +109,7 @@ public partial class AutoTranslateViewModel : ObservableObject
private Subtitle _subtitle = new Subtitle();
private int _translationProgressIndex;
private bool _llamaCppUpdatePromptShown;
private bool _suppressLlamaCppRemoteToggle;
private readonly IWindowService _windowService;
private readonly IFolderHelper _folderHelper;

Expand Down Expand Up @@ -318,8 +321,18 @@ public void SaveSettings()
Configuration.Settings.Tools.LmStudioModel = apiModel.Trim();
}

// llama.cpp is server-managed: the API URL is set by LlamaCppServerManager and the
// model is persisted via OnSelectedLlamaCppModelChanged, so nothing to save here.
if (engineType == typeof(LlamaCppTranslate))
{
Se.Settings.AutoTranslate.LlamaCppUseRemoteServer = LlamaCppUseRemoteServer;
if (LlamaCppUseRemoteServer)
{
// Remote mode: persist the user-entered endpoint.
Configuration.Settings.Tools.LlamaCppApiUrl = apiUrl.Trim();
Se.Settings.AutoTranslate.LlamaCppApiUrl = apiUrl.Trim();
}
// Local mode stays server-managed: the API URL is set by LlamaCppServerManager and the
// model is persisted via OnSelectedLlamaCppModelChanged, so nothing else to save here.
}

if (engineType == typeof(OllamaTranslate))
{
Expand Down Expand Up @@ -1164,10 +1177,18 @@ await MessageBox.Show(

_cancellationTokenSource = new CancellationTokenSource();

if (engineType == typeof(LlamaCppTranslate) && !await EnsureLlamaCppReady())
if (engineType == typeof(LlamaCppTranslate))
{
IsProgressEnabled = false;
return false;
if (Se.Settings.AutoTranslate.LlamaCppUseRemoteServer)
{
// Remote server: use the configured endpoint directly, skip local server management.
Configuration.Settings.Tools.LlamaCppApiUrl = (ApiUrlText ?? string.Empty).Trim();
}
else if (!await EnsureLlamaCppReady())
{
IsProgressEnabled = false;
return false;
}
}

_translationInProgress = true;
Expand Down Expand Up @@ -1456,6 +1477,7 @@ private void SetAutoTranslatorEngine(IAutoTranslator translator)
SelectedCrispAsrModel = null;
LlamaCppModelComboIsVisible = false;
LlamaCppButtonsAreVisible = false;
LlamaCppRemoteToggleIsVisible = false;
LlamaCppModels.Clear();
SelectedLlamaCppModel = null;
ModelText = string.Empty;
Expand Down Expand Up @@ -1629,6 +1651,30 @@ private void SetAutoTranslatorEngine(IAutoTranslator translator)

if (engineType == typeof(LlamaCppTranslate))
{
// The remote toggle is always available for llama.cpp; its current value decides
// whether we show the local model/server controls or a plain API URL field (#11584).
LlamaCppRemoteToggleIsVisible = true;
_suppressLlamaCppRemoteToggle = true;
LlamaCppUseRemoteServer = Se.Settings.AutoTranslate.LlamaCppUseRemoteServer;
_suppressLlamaCppRemoteToggle = false;

if (LlamaCppUseRemoteServer)
{
// Remote/external server: just edit the URL (the llama.cpp server is OpenAI-compatible,
// same as the LM Studio engine). No local download or server management.
if (string.IsNullOrEmpty(Se.Settings.AutoTranslate.LlamaCppApiUrl))
{
Se.Settings.AutoTranslate.LlamaCppApiUrl = "http://localhost:8080/v1/chat/completions";
}

FillUrls(new List<string>
{
Se.Settings.AutoTranslate.LlamaCppApiUrl.TrimEnd('/'),
});

return;
}

LlamaCppModelComboIsVisible = true;
LlamaCppButtonsAreVisible = true;
var savedModelName = Path.GetFileName(Se.Settings.AutoTranslate.LlamaCppModel ?? string.Empty);
Expand Down Expand Up @@ -1832,6 +1878,23 @@ private void SetAutoTranslatorEngine(IAutoTranslator translator)
throw new Exception($"Engine {translator.Name} not handled!");
}

partial void OnLlamaCppUseRemoteServerChanged(bool value)
{
// Ignore the programmatic assignment made while SetAutoTranslatorEngine builds the panel.
if (_suppressLlamaCppRemoteToggle)
{
return;
}

Se.Settings.AutoTranslate.LlamaCppUseRemoteServer = value;

// Swap the llama.cpp panel between the local model/server controls and the remote URL field.
if (SelectedAutoTranslator is LlamaCppTranslate)
{
SetAutoTranslatorEngine(SelectedAutoTranslator);
}
}

private void FillUrls(List<string> urls)
{
ApiUrlText = urls.Count > 0 ? urls[0] : string.Empty;
Expand Down
4 changes: 4 additions & 0 deletions src/ui/Features/Translate/AutoTranslateWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ private static Border BuildApiConfigCard(AutoTranslateViewModel vm)
settingsPanel.Children.Add(UiUtil.MakeTextBlock(Se.Language.General.ApiKey, vm, null, nameof(vm.ApiKeyIsVisible)).WithMarginRight(5));
settingsPanel.Children.Add(UiUtil.MakeTextBox(150, vm, nameof(vm.ApiKeyText), nameof(vm.ApiKeyIsVisible)).WithMarginRight(15));

var checkBoxLlamaCppRemote = UiUtil.MakeCheckBox(Se.Language.General.LlamaCppUseRemoteServer, vm, nameof(vm.LlamaCppUseRemoteServer)).WithMarginRight(15);
checkBoxLlamaCppRemote.Bind(CheckBox.IsVisibleProperty, new Binding(nameof(vm.LlamaCppRemoteToggleIsVisible)));
settingsPanel.Children.Add(checkBoxLlamaCppRemote);

settingsPanel.Children.Add(UiUtil.MakeTextBlock(Se.Language.General.Url, vm, null, nameof(vm.ApiUrlIsVisible)).WithMarginRight(5));
settingsPanel.Children.Add(UiUtil.MakeTextBox(200, vm, nameof(vm.ApiUrlText), nameof(vm.ApiUrlIsVisible)).WithMarginRight(15));

Expand Down
2 changes: 2 additions & 0 deletions src/ui/Logic/Config/Language/LanguageGeneral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ public class LanguageGeneral
public string Percent { get; set; }
public string PickLayer { get; set; }
public string PickOllamaModel { get; set; }
public string LlamaCppUseRemoteServer { get; set; }
public string PickOutputFolder { get; set; }
public string PickResolutionFromCurrentVideo { get; set; }
public string PickResolutionFromVideoDotDotDot { get; set; }
Expand Down Expand Up @@ -1117,6 +1118,7 @@ public LanguageGeneral()
Percent = "Percent";
PickLayer = "Set layer";
PickOllamaModel = "Pick Ollama model";
LlamaCppUseRemoteServer = "Use external server (URL)";
PickOutputFolder = "Pick output folder";
PickResolutionFromCurrentVideo = "Pick resolution from current video";
PickResolutionFromVideoDotDotDot = "Pick resolution from video...";
Expand Down
6 changes: 6 additions & 0 deletions src/ui/Logic/Config/SeAutoTranslate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class SeAutoTranslate
public string LlamaCppApiUrl { get; set; }
public string LlamaCppModel { get; set; }
public string LlamaCppPrompt { get; set; }

/// <summary>
/// When true, connect to an external/remote llama.cpp server at <see cref="LlamaCppApiUrl"/>
/// (e.g. a GPU box) instead of downloading a model and managing a local server (#11584).
/// </summary>
public bool LlamaCppUseRemoteServer { get; set; }
public string GroqUrl { get; set; }
public string GroqPrompt { get; set; }
public string GroqApiKey { get; set; }
Expand Down