106 lines
3.4 KiB
Text
106 lines
3.4 KiB
Text
|
|
@page "/assistant"
|
||
|
|
@inject IOllamaService OllamaService
|
||
|
|
@inject ISettingsService SettingsService
|
||
|
|
@inject NavigationManager Navigation
|
||
|
|
|
||
|
|
@rendermode InteractiveServer
|
||
|
|
|
||
|
|
<PageTitle>Assistent - Author Buddy</PageTitle>
|
||
|
|
|
||
|
|
<div class="assistant-page">
|
||
|
|
<div class="assistant-toolbar">
|
||
|
|
<select @bind="selectedMode">
|
||
|
|
<option value="advocatus">Advocatus Diaboli</option>
|
||
|
|
<option value="hookfinder">Hook-Finder</option>
|
||
|
|
<option value="eli5">ELI5-Vereinfachung</option>
|
||
|
|
</select>
|
||
|
|
<button @onclick="RunAssistant" disabled="@isRunning || string.IsNullOrWhiteSpace(inputText)">Ausführen</button>
|
||
|
|
<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">
|
||
|
|
<h4>Eingabetext</h4>
|
||
|
|
<textarea class="assistant-textarea" @bind="inputText" placeholder="Füge hier deinen Text ein..."></textarea>
|
||
|
|
</div>
|
||
|
|
<div class="assistant-output-panel">
|
||
|
|
<h4>Ergebnis</h4>
|
||
|
|
<div class="assistant-output">
|
||
|
|
@if (!string.IsNullOrEmpty(outputText))
|
||
|
|
{
|
||
|
|
<pre>@outputText</pre>
|
||
|
|
}
|
||
|
|
else if (!string.IsNullOrEmpty(errorMessage))
|
||
|
|
{
|
||
|
|
<div class="assistant-error">@errorMessage</div>
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
<span class="assistant-hint">Ergebnis erscheint hier nach der Ausführung.</span>
|
||
|
|
}
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
private string selectedMode = "advocatus";
|
||
|
|
private string inputText = string.Empty;
|
||
|
|
private string outputText = string.Empty;
|
||
|
|
private string errorMessage = string.Empty;
|
||
|
|
private string statusText = "Bereit";
|
||
|
|
private bool isRunning;
|
||
|
|
private double progress;
|
||
|
|
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
await base.OnInitializedAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task RunAssistant()
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(inputText)) return;
|
||
|
|
|
||
|
|
isRunning = true;
|
||
|
|
progress = 50;
|
||
|
|
outputText = string.Empty;
|
||
|
|
errorMessage = string.Empty;
|
||
|
|
statusText = "Verarbeite...";
|
||
|
|
|
||
|
|
try
|
||
|
|
{
|
||
|
|
var systemPrompt = selectedMode switch
|
||
|
|
{
|
||
|
|
"advocatus" => await SettingsService.GetAdvocatusDiaboliPromptAsync() ?? string.Empty,
|
||
|
|
"hookfinder" => await SettingsService.GetHookFinderPromptAsync() ?? string.Empty,
|
||
|
|
"eli5" => await SettingsService.GetEli5PromptAsync() ?? string.Empty,
|
||
|
|
_ => string.Empty
|
||
|
|
};
|
||
|
|
|
||
|
|
if (string.IsNullOrEmpty(systemPrompt))
|
||
|
|
{
|
||
|
|
errorMessage = "Kein System-Prompt für diesen Modus konfiguriert. Bitte in den Einstellungen hinterlegen.";
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
var model = await SettingsService.GetStyleModelAsync() ?? "llama3.2";
|
||
|
|
outputText = await OllamaService.Chat(model, inputText, systemPrompt);
|
||
|
|
statusText = "Fertig.";
|
||
|
|
}
|
||
|
|
catch (Exception ex)
|
||
|
|
{
|
||
|
|
errorMessage = $"Fehler: {ex.Message}";
|
||
|
|
statusText = "Fehler";
|
||
|
|
}
|
||
|
|
finally
|
||
|
|
{
|
||
|
|
isRunning = false;
|
||
|
|
progress = 0;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|