Backup #1921

ID1921
Dateipfad/var/www/dev.campus.systemische-tools.de/src/View/chat/partials/response.php
Version4
Typ modified
Größe3.9 KB
Hash46eb90c7dc68f7c7d198680685133871339691fe24a9eac0c312a35fc303163f
Datum2025-12-28 01:20:17
Geändert vonclaude-code-hook
GrundClaude Code Pre-Hook Backup vor Edit-Operation
Datei existiert Ja

Dateiinhalt

<?php
/**
 * HTMX Response Partial - Renders both user question and assistant response
 * Uses same CSS classes as index.php for consistent styling
 *
 * @var string $question The user's question
 * @var array $result AI response with 'answer', 'sources', 'usage'
 * @var string $model The model used
 * @var string $formattedAnswer Pre-formatted answer HTML
 */

$answer = $formattedAnswer ?? htmlspecialchars($result['answer'] ?? '');
$sources = $result['sources'] ?? [];
$usage = $result['usage'] ?? null;
$isOllama = str_starts_with($model, 'ollama:');
$modelLabel = $isOllama ? substr($model, 7) : $model;

$inputTokens = (int) ($usage['input_tokens'] ?? 0);
$outputTokens = (int) ($usage['output_tokens'] ?? 0);
$cost = ($inputTokens * 0.000015) + ($outputTokens * 0.000075);

$qualityValidation = $result['quality_validation'] ?? null;
$uniqueId = uniqid('sources-');
?>
<!-- User Message -->
<div class="chat-msg chat-msg--user">
    <div class="chat-msg__content"><?= htmlspecialchars($question) ?></div>
</div>

<!-- Assistant Message -->
<div class="chat-msg chat-msg--assistant">
    <div class="chat-msg__content">
        <?= $answer ?>

        <?php if ($qualityValidation !== null): ?>
        <div class="chat-quality chat-quality--<?= $qualityValidation['passed'] ? 'passed' : 'failed' ?>"
             title="<?= htmlspecialchars($qualityValidation['details'] ?? '') ?>">
            <span class="chat-quality__icon"><?= $qualityValidation['passed'] ? '✓' : '⚠' ?></span>
            <span class="chat-quality__score"><?= round($qualityValidation['score'] ?? 0) ?>%</span>
            <?php if (!empty($qualityValidation['issues'])): ?>
            <div class="chat-quality__issues">
                <strong>Hinweise:</strong>
                <ul>
                <?php foreach ($qualityValidation['issues'] as $issue): ?>
                    <li><?= htmlspecialchars($issue) ?></li>
                <?php endforeach; ?>
                </ul>
            </div>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <?php if (!empty($sources)): ?>
        <div class="chat-sources" id="<?= $uniqueId ?>">
            <button type="button" class="chat-sources__toggle" onclick="this.parentElement.classList.toggle('chat-sources--open')">
                <?= count($sources) ?> Quelle<?= count($sources) > 1 ? 'n' : '' ?> &#9662;
            </button>
            <div class="chat-sources__list">
                <?php foreach ($sources as $source): ?>
                <div class="chat-source">
                    <div class="chat-source__header">
                        <?php if (!empty($source['collection'])): ?>
                        <span class="chat-source__collection">[<?= htmlspecialchars($source['collection']) ?>]</span>
                        <?php endif; ?>
                        <span class="chat-source__title"><?= htmlspecialchars($source['title'] ?? 'Unbekannt') ?></span>
                        <span class="chat-source__score"><?= round(($source['score'] ?? 0) * 100) ?>%</span>
                    </div>
                    <?php if (!empty($source['content'])): ?>
                    <div class="chat-source__content">"<?= htmlspecialchars(mb_substr($source['content'], 0, 200)) ?><?= mb_strlen($source['content']) > 200 ? '...' : '' ?>"</div>
                    <?php endif; ?>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
        <?php endif; ?>

        <div class="chat-msg__meta">
            <span><?= htmlspecialchars($modelLabel) ?></span>
            <?php if (!$isOllama && ($inputTokens > 0 || $outputTokens > 0)): ?>
            <span class="chat-msg__tokens">&darr;<?= number_format($inputTokens) ?> &uarr;<?= number_format($outputTokens) ?></span>
            <span class="chat-msg__cost">~$<?= number_format($cost, 4) ?></span>
            <?php elseif ($isOllama): ?>
            <span class="chat-msg__local">lokal</span>
            <?php endif; ?>
        </div>
    </div>
</div>

Vollständig herunterladen

Aktionen

Herunterladen

Andere Versionen dieser Datei

ID Version Typ Größe Datum
2123 5 modified 4.0 KB 2025-12-29 14:57
1921 4 modified 3.9 KB 2025-12-28 01:20
1550 3 modified 3.5 KB 2025-12-26 20:07
566 2 modified 2.6 KB 2025-12-23 03:36
536 1 modified 2.4 KB 2025-12-22 22:27

← Zurück zur Übersicht