154 lines
5 KiB
Text
154 lines
5 KiB
Text
|
|
@page "/quick-markdown"
|
|||
|
|
@attribute [Authorize(Roles = "Administrator,Blogger")]
|
|||
|
|
@inject IOllamaService OllamaService
|
|||
|
|
@inject OllamaSettings Settings
|
|||
|
|
@inject IJSRuntime JS
|
|||
|
|
@inject IAuthService AuthService
|
|||
|
|
@inject ISettingsService SettingsService
|
|||
|
|
@inject NavigationManager Navigation
|
|||
|
|
|
|||
|
|
@rendermode InteractiveServer
|
|||
|
|
|
|||
|
|
<PageTitle>Quick Markdown</PageTitle>
|
|||
|
|
|
|||
|
|
<div class="qm-container">
|
|||
|
|
<h2>Quick Markdown</h2>
|
|||
|
|
<p>Erzeugt aus einem Text und einem System-Prompt direkt formatiertes Markdown – ohne Projekt oder Speicherung.</p>
|
|||
|
|
|
|||
|
|
<div class="qm-layout">
|
|||
|
|
<div class="qm-input-panel">
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>System-Prompt</label>
|
|||
|
|
<textarea class="qm-textarea qm-prompt" @bind="_systemPrompt" rows="4"></textarea>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label for="tempRange">Temperatur: @_temperature.ToString("F2")</label>
|
|||
|
|
<input id="tempRange" type="range" min="0" max="2" step="0.05" @bind="_temperature" />
|
|||
|
|
<div class="qm-range-labels">
|
|||
|
|
<span>präzise (0)</span>
|
|||
|
|
<span>kreativ (2)</span>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<div class="qm-prompt-actions">
|
|||
|
|
<button class="btn btn-secondary" @onclick="SaveSettings">System-Prompt & Temperatur speichern</button>
|
|||
|
|
<button class="btn btn-secondary" @onclick="ResetToDefault">Auf Standard zurücksetzen</button>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>Text</label>
|
|||
|
|
<textarea class="qm-textarea" @bind="_inputText" rows="12" placeholder="Text hier eingeben…"></textarea>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<button class="btn btn-primary" @onclick="Generate" disabled="@_isBusy || string.IsNullOrWhiteSpace(_inputText)">
|
|||
|
|
@if (_isBusy)
|
|||
|
|
{
|
|||
|
|
<span>Generiere…</span>
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
<span>Markdown erzeugen</span>
|
|||
|
|
}
|
|||
|
|
</button>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
<div class="qm-output-panel">
|
|||
|
|
<div class="form-group">
|
|||
|
|
<label>Ausgabe</label>
|
|||
|
|
<div class="qm-output-toolbar">
|
|||
|
|
<button class="btn btn-small" @onclick="CopyOutput" disabled="@string.IsNullOrEmpty(_output)">📋 Kopieren</button>
|
|||
|
|
<button class="btn btn-small" @onclick="ClearOutput">🗑 Leeren</button>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
<textarea class="qm-textarea qm-output" @bind="_output" rows="20" readonly></textarea>
|
|||
|
|
</div>
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
@if (!string.IsNullOrEmpty(_error))
|
|||
|
|
{
|
|||
|
|
<div class="auth-error">@_error</div>
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
@if (!string.IsNullOrEmpty(_modelNotice))
|
|||
|
|
{
|
|||
|
|
<div class="qm-notice">@_modelNotice</div>
|
|||
|
|
}
|
|||
|
|
</div>
|
|||
|
|
|
|||
|
|
@code {
|
|||
|
|
private string _systemPrompt = string.Empty;
|
|||
|
|
private string _inputText = string.Empty;
|
|||
|
|
private string _output = string.Empty;
|
|||
|
|
private string _error = string.Empty;
|
|||
|
|
private string _modelNotice = string.Empty;
|
|||
|
|
private bool _isBusy;
|
|||
|
|
private double _temperature = 0.3;
|
|||
|
|
|
|||
|
|
protected override async Task OnInitializedAsync()
|
|||
|
|
{
|
|||
|
|
var user = await AuthService.GetCurrentUserAsync();
|
|||
|
|
if (user == null || !user.HasAnyRole(UserRole.Administrator, UserRole.Blogger))
|
|||
|
|
{
|
|||
|
|
Navigation.NavigateTo("/");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
_systemPrompt = await SettingsService.GetQuickMarkdownPromptAsync()
|
|||
|
|
?? Settings.GetQuickMarkdownDefaultPrompt(Settings.Language);
|
|||
|
|
_temperature = await SettingsService.GetQuickMarkdownTempAsync();
|
|||
|
|
|
|||
|
|
_modelNotice = $"Verwendetes Modell: {Settings.StyleModel} (via {Settings.Backend})";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task SaveSettings()
|
|||
|
|
{
|
|||
|
|
await SettingsService.SaveQuickMarkdownPromptAsync(_systemPrompt);
|
|||
|
|
await SettingsService.SaveQuickMarkdownTempAsync(_temperature);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task ResetToDefault()
|
|||
|
|
{
|
|||
|
|
_systemPrompt = Settings.GetQuickMarkdownDefaultPrompt(Settings.Language);
|
|||
|
|
_temperature = Settings.QuickMarkdownTemp;
|
|||
|
|
await SaveSettings();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task Generate()
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrWhiteSpace(_inputText)) return;
|
|||
|
|
|
|||
|
|
_isBusy = true;
|
|||
|
|
_error = string.Empty;
|
|||
|
|
_output = string.Empty;
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var result = await OllamaService.Chat(Settings.StyleModel, _inputText, _systemPrompt, _temperature);
|
|||
|
|
_output = result;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
_error = $"Fehler bei der Generierung: {ex.Message}";
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
_isBusy = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task CopyOutput()
|
|||
|
|
{
|
|||
|
|
if (string.IsNullOrEmpty(_output)) return;
|
|||
|
|
await JS.InvokeVoidAsync("navigator.clipboard.writeText", _output);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ClearOutput()
|
|||
|
|
{
|
|||
|
|
_output = string.Empty;
|
|||
|
|
_error = string.Empty;
|
|||
|
|
}
|
|||
|
|
}
|