2026-05-20 06:12:54 +02:00
@page "/assistant"
2026-05-21 11:04:42 +02:00
@attribute [Authorize]
2026-05-20 06:12:54 +02:00
@inject IOllamaService OllamaService
@inject ISettingsService SettingsService
@inject NavigationManager Navigation
@rendermode InteractiveServer
2026-05-20 07:27:41 +02:00
<PageTitle>@T("Assistent - Author Buddy", "Assistant - Author Buddy")</PageTitle>
2026-05-20 06:12:54 +02:00
<div class="assistant-page">
<div class="assistant-toolbar">
<select @bind="selectedMode">
2026-05-20 07:27:41 +02:00
<option value="lektorat">@T("Lektorat", "Editing")</option>
<option value="advocatus">@T("Advocatus Diaboli", "Advocatus Diaboli")</option>
<option value="hookfinder">@T("Hook-Finder", "Hook finder")</option>
<option value="eli5">@T("ELI5-Vereinfachung", "ELI5 simplification")</option>
2026-05-20 06:12:54 +02:00
</select>
2026-05-20 07:27:41 +02:00
<button @onclick="RunAssistant" disabled="@(() => isRunning || string.IsNullOrWhiteSpace(inputText))">@T("Ausführen", "Execute")</button>
@if (!string.IsNullOrEmpty(outputText))
{
<button @onclick="SendToEditor" class="primary">@T("An Editor übermitteln", "Send to editor")</button>
}
2026-05-20 06:12:54 +02:00
<span style="flex:1;font-size:12px;color:var(--border-color);text-align:right;">@statusText</span>
@if (isRunning)
{
<progress value="@progress" max="100"></progress>
}
</div>
<div class="assistant-panels">
<div class="assistant-input-panel">
2026-05-20 07:27:41 +02:00
<h4>@T("Eingabetext", "Input text")</h4>
<textarea class="assistant-textarea" @bind="inputText" placeholder="@T("Füge hier deinen Text ein...", "Paste your text here...")"></textarea>
2026-05-20 06:12:54 +02:00
</div>
<div class="assistant-output-panel">
2026-05-20 07:27:41 +02:00
<h4>@T("Ergebnis", "Result")</h4>
2026-05-20 06:12:54 +02:00
<div class="assistant-output">
@if (!string.IsNullOrEmpty(outputText))
{
<pre>@outputText</pre>
}
else if (!string.IsNullOrEmpty(errorMessage))
{
<div class="assistant-error">@errorMessage</div>
}
else
{
2026-05-20 07:27:41 +02:00
<span class="assistant-hint">@T("Ergebnis erscheint hier nach der Ausführung.", "Result appears here after execution.")</span>
2026-05-20 06:12:54 +02:00
}
</div>
</div>
</div>
</div>
@code {
2026-05-20 07:27:41 +02:00
private string _language = "de";
private string selectedMode = "lektorat";
2026-05-20 06:12:54 +02:00
private string inputText = string.Empty;
private string outputText = string.Empty;
private string errorMessage = string.Empty;
2026-05-20 07:27:41 +02:00
private string statusText = string.Empty;
2026-05-20 06:12:54 +02:00
private bool isRunning;
private double progress;
2026-05-20 07:27:41 +02:00
private string T(string de, string en) => _language == "en" ? en : de;
2026-05-20 06:12:54 +02:00
protected override async Task OnInitializedAsync()
{
2026-05-20 07:27:41 +02:00
_language = await SettingsService.GetLanguageAsync() ?? "de";
statusText = T("Bereit", "Ready");
var pending = SettingsService.PendingAssistantInput;
if (!string.IsNullOrEmpty(pending))
{
inputText = pending;
SettingsService.PendingAssistantInput = null;
}
2026-05-20 06:12:54 +02:00
}
private async Task RunAssistant()
{
if (string.IsNullOrWhiteSpace(inputText)) return;
isRunning = true;
progress = 50;
outputText = string.Empty;
errorMessage = string.Empty;
2026-05-20 07:27:41 +02:00
statusText = T("Verarbeite...", "Processing...");
2026-05-20 06:12:54 +02:00
try
{
var systemPrompt = selectedMode switch
{
2026-05-20 07:27:41 +02:00
"lektorat" => await SettingsService.GetLektorSystemPromptAsync() ?? string.Empty,
2026-05-20 06:12:54 +02:00
"advocatus" => await SettingsService.GetAdvocatusDiaboliPromptAsync() ?? string.Empty,
"hookfinder" => await SettingsService.GetHookFinderPromptAsync() ?? string.Empty,
"eli5" => await SettingsService.GetEli5PromptAsync() ?? string.Empty,
_ => string.Empty
};
if (string.IsNullOrEmpty(systemPrompt))
{
2026-05-20 07:27:41 +02:00
errorMessage = T("Kein System-Prompt für diesen Modus konfiguriert. Bitte in den Einstellungen hinterlegen.", "No system prompt configured for this mode. Please configure in settings.");
2026-05-20 06:12:54 +02:00
return;
}
var model = await SettingsService.GetStyleModelAsync() ?? "llama3.2";
outputText = await OllamaService.Chat(model, inputText, systemPrompt);
2026-05-20 07:27:41 +02:00
statusText = T("Fertig.", "Done.");
2026-05-20 06:12:54 +02:00
}
catch (Exception ex)
{
2026-05-20 07:27:41 +02:00
errorMessage = $"{T("Fehler:", "Error:")} {ex.Message}";
statusText = T("Fehler", "Error");
2026-05-20 06:12:54 +02:00
}
finally
{
isRunning = false;
progress = 0;
}
}
2026-05-20 07:27:41 +02:00
private void SendToEditor()
{
SettingsService.PendingAssistantOutput = outputText;
Navigation.NavigateTo("/editor");
}
2026-05-20 06:12:54 +02:00
}