{% extends 'admin/base.html.twig' %}

{% block title %}Neue Modell-Generierungskonfiguration{% endblock %}

{% block body %}
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h3">Neue Modell-Generierungskonfiguration</h1>

        <a href="{{ path('admin_model_config_list') }}"
           class="btn btn-sm btn-outline-secondary">
            Zurück
        </a>
    </div>

    <div class="card bg-black border-secondary text-light">
        <div class="card-body">

            <form method="post">

                <input type="hidden" name="_token"
                       value="{{ csrf_token('create_model_config') }}">

                <div class="row g-4">

                    <!-- ============================== -->
                    <!-- Modell-Basis -->
                    <!-- ============================== -->

                    <div class="col-md-6">
                        <label class="form-label">Modellname</label>
                        <input type="text"
                               name="model_name"
                               class="form-control bg-dark text-light border-secondary"
                               placeholder="z. B. qwen3:latest"
                               required>
                        <div class="form-text text-secondary">
                            Exakter Modellname wie im KI-Endpunkt konfiguriert.
                        </div>
                    </div>

                    <div class="col-md-6 d-flex align-items-center">
                        <div class="form-check form-switch mt-4">
                            <input class="form-check-input"
                                   type="checkbox"
                                   name="stream"
                                   value="1"
                                   id="streamSwitch" checked>
                            <label class="form-check-label" for="streamSwitch">
                                Streaming aktivieren
                            </label>
                        </div>
                        <div class="form-text text-secondary ms-3">
                            Token-Streaming im Chat (empfohlen).
                        </div>
                    </div>

                </div>

                <hr class="border-secondary my-4">

                <!-- ============================== -->
                <!-- GENERATION -->
                <!-- ============================== -->

                <h5 class="text-info mb-3">Generation (LLM Sampling)</h5>

                <div class="row g-4">

                    <div class="col-md-4">
                        <label class="form-label">Temperature</label>
                        <input type="number"
                               step="0.05"
                               min="0"
                               max="2"
                               name="temperature"
                               value="0.35"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Kreativität des Modells. Für RAG 0.2–0.4 empfohlen.
                        </div>
                    </div>

                    <div class="col-md-4">
                        <label class="form-label">Top K</label>
                        <input type="number"
                               min="0"
                               max="200"
                               name="top_k"
                               value="40"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Begrenzt die Auswahl wahrscheinlicher Token.
                        </div>
                    </div>

                    <div class="col-md-4">
                        <label class="form-label">Top P</label>
                        <input type="number"
                               step="0.05"
                               min="0"
                               max="1"
                               name="top_p"
                               value="0.9"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Nucleus Sampling – Balance zwischen Stabilität und Natürlichkeit.
                        </div>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Repeat Penalty</label>
                        <input type="number"
                               step="0.05"
                               min="0"
                               max="5"
                               name="repeat_penalty"
                               value="1.1"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Verhindert Wiederholungen (1.1–1.15 empfohlen).
                        </div>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Context Window (num_ctx)</label>
                        <input type="number"
                               min="512"
                               max="32768"
                               name="num_ctx"
                               value="8192"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Maximale Kontextlänge (System + Frage + Retrieval).
                        </div>
                    </div>

                </div>

                <hr class="border-secondary my-4">

                <!-- ============================== -->
                <!-- RETRIEVAL -->
                <!-- ============================== -->

                <h5 class="text-warning mb-3">Retrieval (Wissensabruf)</h5>

                <div class="row g-4">

                    <div class="col-md-6">
                        <label class="form-label">Max Chunks</label>
                        <input type="number"
                               min="1"
                               max="200"
                               name="retrieval_max_chunks"
                               value="25"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Maximale Anzahl an Wissens-Chunks,
                            die dem Modell übergeben werden.
                            20–40 ist für die meisten Systeme optimal.
                        </div>
                    </div>

                    <div class="col-md-6">
                        <label class="form-label">Vector Top K</label>
                        <input type="number"
                               min="1"
                               max="200"
                               name="retrieval_vector_top_k"
                               value="25"
                               class="form-control bg-dark text-light border-secondary"
                               required>
                        <div class="form-text text-secondary">
                            Anzahl der Vektor-Treffer vor Filterung.
                            Höhere Werte erhöhen Recall, können aber Rauschen verstärken.
                        </div>
                    </div>

                </div>

                <hr class="border-secondary my-4">

                <div class="d-flex justify-content-end">
                    <button type="submit"
                            class="btn btn-outline-info">
                        Konfiguration speichern
                    </button>
                </div>

            </form>
        </div>
    </div>

    <div class="mt-4 small text-secondary">
        Hinweis: Neue Konfigurationen werden zunächst inaktiv gespeichert und
        müssen separat aktiviert werden. Pro Modell kann nur eine Version aktiv sein.
    </div>
{% endblock %}