{% extends "base.html" %} {% block title %}{{ t('system.ai', name=ai_name) }}{% endblock %} {% block header %}
{{ t('nav.system_group') }}

{{ t('system.ai', name=ai_name) }}

{% endblock %} {% macro money(v) %}${{ '%.4f' | format(v) }}{% endmacro %} {% macro num(v) %}{{ '{:,}'.format(v) | replace(',', '.') }}{% endmacro %} {% block content %} {% if tab == 'overview' %}
{{ t('system.ai_state') }}
{% if d.state.on %}{{ t('system.ai_on') }}{% else %}{{ t('system.ai_off') }}{% endif %}
{{ d.state.why }}
{{ t('system.ai_cost_month') }}
{{ money(d.month.cost) }}
{% if d.settings.monthly_budget_usd %}{{ t('system.ai_budget', v='%.2f' | format(d.settings.monthly_budget_usd)) }}{% else %}{{ t('system.ai_no_budget') }}{% endif %}
{{ t('system.ai_tokens_today') }}
{{ num(d.today.tokens) }}
{{ t('system.ai_today_note', q=d.today.questions, r=d.today.refused, e=d.today.errors) }}
{{ t('system.ai_tokens_month') }}
{{ num(d.month.tokens) }}
{{ t('system.ai_tokens_note', i=num(d.month.input), o=num(d.month.output), r=num(d.month.cache_read), w=num(d.month.cache_write)) }}

{{ t('system.ai_all_time', q=d.all_time.questions, tk=num(d.all_time.tokens), c=money(d.all_time.cost)) }}

{{ t('system.ai_by_user') }}

{% for u in d.by_user %} {% else %}{% endfor %}
{{ t('system.col_user') }}{{ t('system.ai_questions') }} {{ t('system.ai_tokens') }}{{ t('system.ai_cost') }}{{ t('system.ai_last') }}
{{ u.name or u.username }}
{{ u.username }}
{{ u.questions }}{{ num(u.tokens) }}{{ money(u.cost) }} {{ u.last.astimezone(tz).strftime('%H:%M %d/%m') }}
{{ t('system.no_rows') }}

{{ t('system.ai_by_day') }}

{% for x in d.by_day %} {% else %}{% endfor %}
{{ t('system.ai_day') }}{{ t('system.ai_questions') }}{{ t('system.ai_refused') }} {{ t('system.ai_tokens') }}{{ t('system.ai_cost') }}
{{ x.day }}{{ x.questions }}{{ x.refused }} {{ num(x.tokens) }}{{ money(x.cost) }}
{{ t('system.no_rows') }}

{{ t('system.ai_by_model') }}

{% for m in d.by_model %} {% else %}{% endfor %}
{{ t('system.ai_model') }}{{ t('system.ai_questions') }} {{ t('system.ai_tokens') }}{{ t('system.ai_cost') }}
{{ m.model }}{{ m.questions }}{{ num(m.tokens) }}{{ money(m.cost) }}
{{ t('system.no_rows') }}
{% elif tab == 'history' %}
{% for u in d.latest %} {% else %}{% endfor %}
{{ t('system.col_time') }}{{ t('system.col_user') }}{{ t('system.ai_question') }} {{ t('system.ai_answer') }}{{ t('system.col_result') }}{{ t('system.ai_tokens') }}{{ t('system.ai_cost') }}
{{ u.at.astimezone(tz).strftime('%H:%M %d/%m/%Y') }}{% if u.purpose == 'feedback' %}
{{ t('system.ai_purpose_feedback') }}
{% endif %}
{{ u.user }} {{ u.question }}{% if u.tools %}
{{ t('system.ai_tools') }}: {{ u.tools }}
{% endif %}
{{ u.answer[:120] or u.error }}
{{ u.answer or u.error }}
{% if u.status == 'ok' %}{{ t('system.ok') }}{% elif u.status == 'refused' %}{{ t('system.ai_refused') }}{% else %}{{ t('system.error') }}{% endif %} {% if u.ms %}
{{ (u.ms / 1000) | round(1) }} s
{% endif %}
{{ num(u.tokens) }}{{ money(u.cost) }}
{{ t('system.no_rows') }}
{% else %}

{{ t('system.ai_settings_note') }}

{% for key in ('enabled', 'name', 'model', 'effort', 'read_report_data', 'allowed_roles', 'questions_per_user_per_day', 'monthly_budget_usd', 'feedback_intake', 'max_tokens', 'max_tool_rounds', 'api_key_env') %}
{{ key }}
{{ d.settings[key] if d.settings[key] not in ([], '') else '—' }}
{% endfor %}
{% endif %} {% endblock %}