@page "/settings" @inject IDbContextFactory ContextFactory @inject IOllamaService OllamaService @inject OllamaSettings OllamaConfig @inject NavigationManager Navigation @inject IJSRuntime JSRuntime @inject IProjectService ProjectService Einstellungen - Author Buddy

Modelle

Ollama Server

Adresse des Ollama-Servers (z. B. http://192.168.1.100:11434)

Design

Neues Projekt

Der Projektordner wird in "Dokumente\AuthorBuddy\" erstellt.
@if (!string.IsNullOrEmpty(statusMessage)) {
@statusMessage
}
@code { private string ragModel = "llama3.2"; private string styleModel = "llama3.2"; private string spellingModel = "phi3:mini"; private string selectedTheme = "light"; private string ollamaUrl = "http://localhost:11434"; private string newProjectName = string.Empty; private string statusMessage = string.Empty; private List availableModels = new(); protected override async Task OnInitializedAsync() { await using var context = await ContextFactory.CreateDbContextAsync(); ragModel = await GetSettingAsync(context, "ollama_rag_model") ?? "llama3.2"; styleModel = await GetSettingAsync(context, "ollama_style_model") ?? "llama3.2"; spellingModel = await GetSettingAsync(context, "ollama_spelling_model") ?? "phi3:mini"; selectedTheme = await GetSettingAsync(context, "theme") ?? "light"; ollamaUrl = await GetSettingAsync(context, "ollama_url") ?? "http://localhost:11434"; try { var models = await OllamaService.GetLocalModelsAsync(); availableModels = models.ToList(); } catch { availableModels = new(); } } private static async Task GetSettingAsync(AppDbContext context, string key) { var setting = await context.Settings.FindAsync(key); return setting?.Value; } private static async Task SaveSettingAsync(AppDbContext context, string key, string value) { var existing = await context.Settings.FindAsync(key); if (existing != null) { existing.Value = value; } else { context.Settings.Add(new SettingEntity { Key = key, Value = value }); } } private async Task SaveSettings() { await using var context = await ContextFactory.CreateDbContextAsync(); await SaveSettingAsync(context, "ollama_rag_model", ragModel); await SaveSettingAsync(context, "ollama_style_model", styleModel); await SaveSettingAsync(context, "ollama_spelling_model", spellingModel); await SaveSettingAsync(context, "theme", selectedTheme); await SaveSettingAsync(context, "ollama_url", ollamaUrl); await context.SaveChangesAsync(); OllamaConfig.OllamaUrl = ollamaUrl; OllamaConfig.ChatModel = ragModel; OllamaConfig.SpellingModel = spellingModel; await OllamaService.ReconfigureAsync(ollamaUrl); statusMessage = "Einstellungen gespeichert."; await ApplyTheme(selectedTheme); } private async Task CreateProject() { if (string.IsNullOrWhiteSpace(newProjectName)) return; try { string rootPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "AuthorBuddy", newProjectName); await ProjectService.CreateNewProjectAsync(newProjectName, rootPath); statusMessage = $"Projekt '{newProjectName}' erstellt unter: {rootPath}"; newProjectName = string.Empty; } catch (Exception ex) { statusMessage = $"Fehler beim Erstellen: {ex.Message}"; } } private async Task ApplyTheme(string theme) { await JSRuntime.InvokeVoidAsync("eval", $"document.getElementById('theme-css')?.remove(); " + $"var link = document.createElement('link'); " + $"link.id = 'theme-css'; " + $"link.rel = 'stylesheet'; " + $"link.href = 'css/themes/{theme}.css'; " + $"document.head.appendChild(link);"); } }