<div class="question">question_name: {{ question }}</div>


<h2>Exception details</h2>

{% for exception_message in exceptions %}
<div class="exception-detail">
        <div class="exception-header">
        <span class="exception-exception">Exception: {{ exception_message.name }}</span>
        <button class="toggle-btn">▼</button>
        </div>
        <div class="exception-content">
        <table border="1">
            <tr>
                <th>Key</th>
                <th>Value</th>
            </tr>
            <tr>
                <td>Interview ID (index in results)</td>
                <td>{{ index }}</td>
            </tr>
            <tr>
                <td>Question name (question_name)</td>
                <td>{{ question }}</td>
            </tr>
 
            <tr>
                <td>Question type (question_type)</td>
                <td>{{ exception_message.question_type }}</td>
            </tr>
 
            <tr>
                <td>Human-readable question</td>
                <td>{{ interview.survey.get_question(question).html(
                    scenario = interview.scenario, 
                    agent = interview.agent,
                    answers = exception_message.answers) 
                
                }}</td>
            </tr>
            <tr>
                <td>Scenario</td>
                <td>{{ interview.scenario._repr_html_() }}</td>
            </tr>
            <tr>
                <td>Agent</td>
                <td>{{ interview.agent._repr_html_() }}</td>
            </tr>
            <tr>
                <td>Model name</td>
                <td>{{ interview.model.model }}</td>
            </tr>
            <tr>
                <td>Inference service</td>
                <td>{{ interview.model._inference_service_ }}</td>
            </tr>
            <tr>
                <td>Model parameters</td>
                <td>{{ interview.model._repr_html_() }}</td>
            </tr>
            <tr>
                <td>User Prompt</td>
                <td><pre>{{ exception_message.rendered_prompts['user_prompt'] }}</pre></td>
            </tr>
            <tr>
                <td>System Prompt</td>
                <td><pre>{{ exception_message.rendered_prompts['system_prompt'] }}</pre></td>
            </tr>
            <tr>
                <td>Raw model response</td>
                <td><pre>{{ exception_message.raw_model_response }}</pre>
                </td>
            </tr>
            <tr>
                <td>Generated token string (at {{ exception_message.key_sequence }}) in raw response</td>
                <td><pre>{{ exception_message.generated_token_string }}</pre>
                </td>
            </tr>
            <tr>
            <td>Code to (likely) reproduce the error</td>
            <td>
                <textarea id="codeToCopy" rows="10" cols="90">{{ exception_message.code_to_reproduce }}</textarea>
                <button onclick="copyCode()">Copy</button>
            </td>
            </tr>

        </table>

        
            {% if exception_message.exception.__class__.__name__ == 'QuestionAnswerValidationError' %}        
            <h3>Answer validation details</h3>
            <table border="1">
                <tr>
                    <th>Field</th>
                    <th>Value</th>
                </tr>
                {% for field, (explanation, open_tag, close_tag, value) in exception_message.exception.to_html_dict().items() %}
                
                <tr>
                    <td>{{ field }}: ({{ explanation }})</td>
                    <td><{{open_tag}}> {{ value | escape }} <{{close_tag}}></td>
                </tr>
                {% endfor %}
            </table>
        {% endif %}

            <div class="exception-time">Time: {{ exception_message.time }}</div>          
            <div class="exception-traceback">Traceback: 
                <text>
                <pre>{{ exception_message.traceback }}</pre>
                </text>
            </div>
        </div>
    </div>

{% endfor %}