AuthorBuddy/Components/Pages/Settings.razor

171 lines
6.7 KiB
Text
Raw Normal View History

2026-05-14 12:31:35 +02:00
@page "/settings"
2026-05-16 16:13:35 +02:00
@inject ISettingsService SettingsService
@inject IThemeService ThemeService
2026-05-14 12:31:35 +02:00
@inject IOllamaService OllamaService
@inject NavigationManager Navigation
@inject IJSRuntime JSRuntime
@inject IProjectService ProjectService
<PageTitle>Einstellungen - Author Buddy</PageTitle>
<div class="settings-page">
2026-05-16 16:13:35 +02:00
<div class="settings-layout">
<div class="settings-layout-left">
<div class="settings-section">
<h3 class="settings-section-title">Modelle</h3>
<div class="form-group">
<label for="ragModel">RAG-Modell (Faktenabfrage):</label>
<select id="ragModel" @bind="ragModel">
@if (availableModels.Count == 0)
{
<option value="">Keine Modelle gefunden</option>
}
@foreach (var m in availableModels)
{
<option value="@m.Name">@m.Name</option>
}
</select>
</div>
<div class="form-group">
<label for="styleModel">Stil-Modell (Lektorat):</label>
<select id="styleModel" @bind="styleModel">
@if (availableModels.Count == 0)
{
<option value="">Keine Modelle gefunden</option>
}
@foreach (var m in availableModels)
{
<option value="@m.Name">@m.Name</option>
}
</select>
</div>
<div class="form-group">
<label for="spellingModel">Rechtschreibprüfungs-Modell:</label>
<select id="spellingModel" @bind="spellingModel">
@if (availableModels.Count == 0)
{
<option value="">Keine Modelle gefunden</option>
}
@foreach (var m in availableModels)
{
<option value="@m.Name">@m.Name</option>
}
</select>
</div>
</div>
<div class="settings-section">
<h3 class="settings-section-title">Ollama Server</h3>
<div class="form-group">
<label for="ollamaUrl">Server-URL:</label>
<input id="ollamaUrl" @bind="ollamaUrl" placeholder="http://localhost:11434" />
<div class="form-hint">Adresse des Ollama-Servers (z. B. http://192.168.1.100:11434)</div>
</div>
</div>
<div class="settings-section">
<h3 class="settings-section-title">Design</h3>
<div class="form-group">
<label for="themeSelect">Theme:</label>
<select id="themeSelect" @bind="selectedTheme">
<option value="light">Hell</option>
<option value="dark">Dunkel</option>
<option value="w95">W95 (Retro)</option>
</select>
</div>
</div>
2026-05-14 12:31:35 +02:00
</div>
2026-05-16 16:13:35 +02:00
<div class="settings-layout-right">
<div class="settings-section">
<h3 class="settings-section-title">Lektor-System-Prompt</h3>
<div class="form-group">
<textarea id="lektorPrompt" @bind="lektorPrompt" rows="6"></textarea>
</div>
</div>
<div class="settings-section">
<h3 class="settings-section-title">Fact-Check-Vorlage</h3>
<div class="form-group">
<textarea id="factCheckTemplate" @bind="factCheckTemplate" rows="6"></textarea>
</div>
</div>
<div class="settings-section">
<h3 class="settings-section-title">Rechtschreibprüfungs-Prompt</h3>
<div class="form-group">
<textarea id="spellingPrompt" @bind="spellingPrompt" rows="6"></textarea>
</div>
</div>
2026-05-14 12:31:35 +02:00
</div>
</div>
2026-05-16 16:13:35 +02:00
<div class="settings-actions">
<button class="btn btn-primary" @onclick="SaveSettings">Speichern</button>
@if (!string.IsNullOrEmpty(statusMessage))
{
<span class="settings-status">@statusMessage</span>
}
2026-05-14 12:31:35 +02:00
</div>
</div>
@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";
2026-05-16 16:13:35 +02:00
private string lektorPrompt = string.Empty;
private string factCheckTemplate = string.Empty;
private string spellingPrompt = string.Empty;
2026-05-14 12:31:35 +02:00
private string newProjectName = string.Empty;
private string statusMessage = string.Empty;
2026-05-16 16:13:35 +02:00
private List<LLM_Model> availableModels = new();
2026-05-14 12:31:35 +02:00
protected override async Task OnInitializedAsync()
{
2026-05-16 16:13:35 +02:00
ragModel = await SettingsService.GetRagModelAsync() ?? "llama3.2";
styleModel = await SettingsService.GetStyleModelAsync() ?? "llama3.2";
spellingModel = await SettingsService.GetSpellingModelAsync() ?? "phi3:mini";
selectedTheme = await SettingsService.GetThemeAsync() ?? "light";
ollamaUrl = await SettingsService.GetOllamaUrlAsync() ?? "http://localhost:11434";
lektorPrompt = await SettingsService.GetLektorSystemPromptAsync() ?? string.Empty;
factCheckTemplate = await SettingsService.GetFactCheckTemplateAsync() ?? string.Empty;
spellingPrompt = await SettingsService.GetSpellingPromptAsync() ?? string.Empty;
2026-05-14 12:31:35 +02:00
try
{
2026-05-16 16:13:35 +02:00
2026-05-14 12:31:35 +02:00
var models = await OllamaService.GetLocalModelsAsync();
availableModels = models.ToList();
}
catch
{
availableModels = new();
}
}
private async Task SaveSettings()
{
2026-05-16 16:13:35 +02:00
await SettingsService.SaveOllamaUrlAsync(ollamaUrl);
await SettingsService.SaveRagModelAsync(ragModel);
await SettingsService.SaveStyleModelAsync(styleModel);
await SettingsService.SaveSpellingModelAsync(spellingModel);
await SettingsService.SaveThemeAsync(selectedTheme);
await SettingsService.SaveLektorSystemPromptAsync(lektorPrompt);
await SettingsService.SaveFactCheckTemplateAsync(factCheckTemplate);
await SettingsService.SaveSpellingPromptAsync(spellingPrompt);
OllamaService.Reconfigure(ollamaUrl);
2026-05-14 12:31:35 +02:00
statusMessage = "Einstellungen gespeichert.";
2026-05-16 16:13:35 +02:00
await ThemeService.ApplyTheme(selectedTheme);
2026-05-14 12:31:35 +02:00
}
2026-05-16 16:13:35 +02:00
2026-05-14 12:31:35 +02:00
}