@page "/models" @attribute [Authorize] @inject IOllamaService OllamaService @inject ISettingsService SettingsService @inject NavigationManager Navigation @T("Modelle - Author Buddy", "Models - Author Buddy")

@T("Ollama Modelle verwalten", "Manage Ollama models")

@if (isLoading) {

@T("Lade Modelle...", "Loading models...")

} else if (!string.IsNullOrEmpty(errorMessage)) {
@errorMessage
} else {
@foreach (var model in localModels) {
@model.Name
@T("Größe:", "Size:") @FormatSize(model.Size) | @T("Geändert:", "Modified:") @model.ModifiedAt?.ToString("g")
}
}

@T("Neues Modell herunterladen", "Download new model")

@if (isPulling) {
@pullStatus (@pullPercentDisplay)
}
@if (pullResult != null) {
@pullResult
} @code { private string _language = "de"; private List localModels = new(); private bool isLoading; private string? errorMessage; private string modelToPull = string.Empty; private bool isPulling; private double pullProgress; private string pullStatus = string.Empty; private string? pullResult; private string pullPercentDisplay => $"{pullProgress:F0}%"; private string T(string de, string en) => _language == "en" ? en : de; protected override async Task OnInitializedAsync() { _language = await SettingsService.GetLanguageAsync() ?? "de"; await RefreshModels(); } private async Task RefreshModels() { isLoading = true; errorMessage = null; try { var models = await OllamaService.GetLocalModelsAsync(); localModels = models.ToList(); } catch (Exception ex) { errorMessage = $"{T("Fehler beim Laden der Modelle:", "Error loading models:")} {ex.Message}"; localModels = new(); } finally { isLoading = false; } } private async Task PullModel() { if (string.IsNullOrWhiteSpace(modelToPull)) return; isPulling = true; pullProgress = 0; pullStatus = T("Starte Download...", "Starting download..."); pullResult = null; try { var progress = new Progress(status => { pullStatus = status; InvokeAsync(StateHasChanged); }); await OllamaService.PullModelAsync(modelToPull, progress); pullResult = $"{T("Modell", "Model")} '{modelToPull}' {T("erfolgreich heruntergeladen.", "downloaded successfully.")}"; modelToPull = string.Empty; await RefreshModels(); } catch (Exception ex) { pullResult = $"{T("Fehler:", "Error:")} {ex.Message}"; } finally { isPulling = false; } } private static string FormatSize(long? bytes) { if (!bytes.HasValue) return "---"; if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB"; if (bytes < 1024 * 1024 * 1024) return $"{bytes / (1024.0 * 1024):F1} MB"; return $"{bytes / (1024.0 * 1024 * 1024):F1} GB"; } }