This commit is contained in:
Константин Лебединский
2026-04-30 14:11:15 +05:00
parent ebb58d4b5a
commit db9851eeda
8 changed files with 527 additions and 24 deletions
+28 -2
View File
@@ -33,7 +33,30 @@ def parse_and_validate_shape(s: Any) -> list[dict]:
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
if n < 2 or n > 12:
raise HttpError(400, f'shape[{i}]: optionsCount от 2 до 12.')
out.append({'optionsCount': n, 'hasMultipleAnswers': bool(row.get('hasMultipleAnswers'))})
has_multi = bool(row.get('hasMultipleAnswers'))
raw_min = row.get('minCorrect', 1)
raw_max = row.get('maxCorrect', n if has_multi else 1)
try:
min_c = int(float(raw_min))
max_c = int(float(raw_max))
except (TypeError, ValueError):
raise HttpError(400, f'shape[{i}]: minCorrect/maxCorrect должны быть числами.')
if not has_multi:
min_c = 1
max_c = 1
if min_c < 1 or max_c < 1 or min_c > max_c or max_c > n:
raise HttpError(
400,
f'shape[{i}]: корректный диапазон правильных ответов — от 1 до {n}, min<=max.',
)
out.append(
{
'optionsCount': n,
'hasMultipleAnswers': has_multi,
'minCorrect': min_c,
'maxCorrect': max_c,
}
)
return out
@@ -51,7 +74,10 @@ def generate_full_test_by_shape(test_title: str, test_description: str, shape: l
lines = []
for i, sh in enumerate(shape):
if sh['hasMultipleAnswers']:
tail = 'несколько вариантов помечены как верные (hasMultipleAnswers: true).'
tail = (
'несколько вариантов помечены как верные (hasMultipleAnswers: true), '
f'число правильных от {sh["minCorrect"]} до {sh["maxCorrect"]}.'
)
else:
tail = 'ровно один верный вариант (hasMultipleAnswers: false).'
lines.append(f'Вопрос {i + 1}: ровно {sh["optionsCount"]} вариантов ответа; {tail}')
+17 -2
View File
@@ -2,6 +2,7 @@
from __future__ import annotations
from .draft_validator import (
normalize_draft_to_shape,
parse_json_from_llm_text,
validate_and_normalize_draft,
)
@@ -11,7 +12,7 @@ from .llm_client import LlmError, chat_completion_text_content, get_llm_config
MAX_EXTRACT_CHARS = 14000
def generation_for_import_document(extracted_text: str, user_hint: str = '') -> dict:
def generation_for_import_document(extracted_text: str, user_hint: str = '', shape: list[dict] | None = None) -> dict:
text = (extracted_text or '').strip()
if not text:
return {
@@ -42,13 +43,27 @@ def generation_for_import_document(extracted_text: str, user_hint: str = '') ->
'Текст и формулировки — на русском, по содержанию входного материала.'
)
hint_block = f'\n\nДополнительные инструкции от автора теста:\n{user_hint.strip()}' if user_hint and user_hint.strip() else ''
shape_block = ''
if shape:
rows = []
for i, sh in enumerate(shape):
if sh.get('hasMultipleAnswers'):
rows.append(
f'- Вопрос {i + 1}: ровно {sh["optionsCount"]} вариантов, '
f'правильных от {sh.get("minCorrect", 1)} до {sh.get("maxCorrect", sh["optionsCount"])}.'
)
else:
rows.append(f'- Вопрос {i + 1}: ровно {sh["optionsCount"]} вариантов, ровно 1 правильный.')
shape_block = '\n\nСтрого соблюди шаблон:\n' + '\n'.join(rows)
user = (
'Составь тест с вопросами с одним или несколькими правильными ответами '
'на основе текста:\n\n' + slice_ + hint_block
'на основе текста:\n\n' + slice_ + hint_block + shape_block
)
raw = chat_completion_text_content(cfg, system, user, 0.25)
parsed = parse_json_from_llm_text(raw)
draft = validate_and_normalize_draft(parsed)
if shape:
draft = normalize_draft_to_shape(draft, shape)
return {
'available': True,
'message': (
+62
View File
@@ -103,3 +103,65 @@ def assert_draft_matches_shape(o: dict, shape: list[dict]) -> None:
f'Вопрос {i + 1}: hasMultipleAnswers должен быть {sh["hasMultipleAnswers"]}.',
code='llm_shape',
)
min_c = int(sh.get('minCorrect', 1))
max_c = int(sh.get('maxCorrect', sh['optionsCount']))
correct_n = sum(1 for op in opts if bool(op.get('isCorrect')))
if correct_n < min_c or correct_n > max_c:
raise LlmError(
f'Вопрос {i + 1}: правильных ответов должно быть от {min_c} до {max_c}, в ответе: {correct_n}.',
code='llm_shape',
)
def normalize_draft_to_shape(draft: dict, shape: list[dict]) -> dict:
"""Приводит draft к shape: число вопросов/вариантов/мульти и диапазон correct."""
qs = list((draft or {}).get('questions') or [])
out_qs = []
def _mk_option(i: int) -> dict:
return {'text': f'Вариант {i + 1}', 'isCorrect': False}
for i, sh in enumerate(shape):
src = qs[i] if i < len(qs) and isinstance(qs[i], dict) else {}
text = str(src.get('text') or '').strip() or f'Вопрос {i + 1}'
has_multi = bool(sh.get('hasMultipleAnswers'))
min_c = int(sh.get('minCorrect', 1))
max_c = int(sh.get('maxCorrect', sh['optionsCount']))
if not has_multi:
min_c = 1
max_c = 1
raw_opts = src.get('options') if isinstance(src.get('options'), list) else []
opts = []
for j in range(sh['optionsCount']):
if j < len(raw_opts) and isinstance(raw_opts[j], dict):
t = str(raw_opts[j].get('text') or '').strip() or f'Вариант {j + 1}'
opts.append({'text': t, 'isCorrect': bool(raw_opts[j].get('isCorrect'))})
else:
opts.append(_mk_option(j))
true_idx = [idx for idx, op in enumerate(opts) if op['isCorrect']]
if not has_multi:
keep = true_idx[0] if true_idx else 0
for idx, op in enumerate(opts):
op['isCorrect'] = (idx == keep)
else:
if len(true_idx) < min_c:
for idx in range(len(opts)):
if idx not in true_idx:
opts[idx]['isCorrect'] = True
true_idx.append(idx)
if len(true_idx) >= min_c:
break
if len(true_idx) > max_c:
keep = set(true_idx[:max_c])
for idx, op in enumerate(opts):
op['isCorrect'] = idx in keep
out_qs.append({'text': text, 'hasMultipleAnswers': has_multi, 'options': opts})
return {
'title': str((draft or {}).get('title') or '').strip() or 'Тест',
'description': (draft or {}).get('description'),
'questions': out_qs,
}
+22 -5
View File
@@ -364,9 +364,18 @@ def count_missing_hints(session_or_eng, test_id: str) -> dict:
if not active_version:
return {'total': 0, 'missing': 0}
all_qs = session.query(Question).filter(Question.test_version_id == active_version.id).all()
total = len(all_qs)
missing = sum(1 for q in all_qs if not q.ai_hint)
all_qs = session.query(Question).options(selectinload(Question.options)).filter(
Question.test_version_id == active_version.id
).all()
filled_qs = []
for q in all_qs:
if not (q.text or '').strip():
continue
if len([o for o in q.options if (o.text or '').strip()]) < 2:
continue
filled_qs.append(q)
total = len(filled_qs)
missing = sum(1 for q in filled_qs if not q.ai_hint)
return {'total': total, 'missing': missing}
@@ -400,8 +409,16 @@ def generate_missing_hints_for_test(session_or_eng, author_id: str, test_id: str
.all()
)
generated = failed = 0
generated = failed = skipped = 0
for q in missing_qs:
# Подсказку строим только по заполненному вопросу (есть текст и >=2 непустых варианта).
if not (q.text or '').strip():
skipped += 1
continue
valid_opts = [o for o in q.options if (o.text or '').strip()]
if len(valid_opts) < 2:
skipped += 1
continue
opt_payload = [{'text': o.text, 'isCorrect': bool(o.is_correct)} for o in q.options]
hint = generate_question_hint(question_text=q.text, options=opt_payload)
if hint:
@@ -410,7 +427,7 @@ def generate_missing_hints_for_test(session_or_eng, author_id: str, test_id: str
else:
failed += 1
session.commit()
return {'generated': generated, 'failed': failed, 'total': len(missing_qs)}
return {'generated': generated, 'failed': failed, 'skipped': skipped, 'total': len(missing_qs)}
def check_question_for_attempt(session_or_eng, user_id: str, test_id: str, attempt_id: str,
+146 -12
View File
@@ -31,6 +31,13 @@
const aiTopicEl = $('#ai-topic');
const aiQCountEl = $('#ai-q-count');
const aiOCountEl = $('#ai-o-count');
const templateGlobalMultiEl = $('#template-global-multi');
const templateMinCorrectEl = $('#template-min-correct');
const templateMaxCorrectEl = $('#template-max-correct');
const hintsStatusEl = $('#hints-status');
const hintsActionsEl = $('#test-hints-actions');
const generateHintsBtn = $('#btn-generate-hints');
const docProgressEl = $('#doc-progress');
const introUpdatedEl = $('#intro-updated');
const introForkBannerEl = $('#intro-fork-banner');
const versionsListEl = $('#versions-list');
@@ -56,6 +63,34 @@
let baselineDraftKey = '';
let dirtyCheckQueued = false;
function getTemplateCorrectRange(optionsCount, hasMultipleAnswers) {
const maxOpt = Math.max(2, Number(optionsCount || 2));
const rawMin = Math.max(1, Number(templateMinCorrectEl?.value || 1) || 1);
const rawMax = Math.max(1, Number(templateMaxCorrectEl?.value || 1) || 1);
if (!hasMultipleAnswers) return { minCorrect: 1, maxCorrect: 1 };
const minCorrect = Math.min(maxOpt, rawMin);
const maxCorrect = Math.max(minCorrect, Math.min(maxOpt, rawMax));
return { minCorrect, maxCorrect };
}
function syncTemplateRangeUi() {
const hasMulti = !!(templateGlobalMultiEl && templateGlobalMultiEl.checked);
const maxOpt = Math.min(MAX_OPTIONS, Math.max(2, Number(aiOCountEl?.value || 3) || 3));
const range = getTemplateCorrectRange(maxOpt, hasMulti);
if (templateMinCorrectEl) {
templateMinCorrectEl.min = '1';
templateMinCorrectEl.max = String(maxOpt);
templateMinCorrectEl.value = String(range.minCorrect);
templateMinCorrectEl.disabled = !hasMulti;
}
if (templateMaxCorrectEl) {
templateMaxCorrectEl.min = '1';
templateMaxCorrectEl.max = String(maxOpt);
templateMaxCorrectEl.value = String(range.maxCorrect);
templateMaxCorrectEl.disabled = !hasMulti;
}
}
function currentDraftKey() {
return JSON.stringify(collectPayload());
}
@@ -379,15 +414,22 @@
const mode = document.querySelector('input[name="result-mode"]:checked');
const isImmediate = mode && mode.value === 'immediate';
if (hintsRow) hintsRow.style.display = isImmediate ? '' : 'none';
if (hintsActionsEl) hintsActionsEl.style.display = (isImmediate && hintsEl && hintsEl.checked) ? '' : 'none';
if (hintsEl && !isImmediate) hintsEl.checked = false;
scheduleDirtyCheck();
});
});
if (hintsEl) {
hintsEl.checked = !!initial.test.hintsEnabled;
hintsEl.addEventListener('change', scheduleDirtyCheck);
hintsEl.addEventListener('change', () => {
const mode = document.querySelector('input[name="result-mode"]:checked');
const isImmediate = mode && mode.value === 'immediate';
if (hintsActionsEl) hintsActionsEl.style.display = (isImmediate && hintsEl.checked) ? '' : 'none';
scheduleDirtyCheck();
});
}
if (hintsRow) hintsRow.style.display = (initMode === 'immediate') ? '' : 'none';
if (hintsActionsEl) hintsActionsEl.style.display = (initMode === 'immediate' && hintsEl && hintsEl.checked) ? '' : 'none';
questionsEl.innerHTML = '';
(initial.questions || []).forEach((q) => questionsEl.appendChild(renderQuestion(q)));
@@ -452,10 +494,29 @@
}
function collectShape() {
return $$('#questions .q-item').map((li) => ({
optionsCount: Math.max(2, $$('.opt-item', li).length || 4),
hasMultipleAnswers: $('.q-multi', li).checked,
}));
return $$('#questions .q-item').map((li) => {
const optionsCount = Math.max(2, $$('.opt-item', li).length || 4);
const hasMultipleAnswers = $('.q-multi', li).checked;
const range = getTemplateCorrectRange(optionsCount, hasMultipleAnswers);
return {
optionsCount,
hasMultipleAnswers,
minCorrect: hasMultipleAnswers ? range.minCorrect : 1,
maxCorrect: hasMultipleAnswers ? range.maxCorrect : 1,
};
});
}
async function saveCurrentDraftQuietly() {
const r = await fetch(`/api/tests/${TEST_ID}/draft`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(collectPayload()),
});
const data = await r.json().catch(() => ({}));
if (!r.ok) throw new Error(data.error || 'Не удалось сохранить черновик перед генерацией подсказок.');
resetBaselineDraft();
return data;
}
// ─── actions ───────────────────────────────────────────────────────
@@ -520,9 +581,10 @@
if (saveModal) saveModal.showModal();
return;
}
const skipped = Number(gd.skipped || 0);
const tail = gd.failed
? ` Подсказки: ${gd.generated} создано, ${gd.failed} не удалось.`
: ` Подсказки созданы (${gd.generated}).`;
? ` Подсказки: ${gd.generated} создано, ${gd.failed} не удалось${skipped ? `, пропущено ${skipped}` : ''}.`
: ` Подсказки созданы (${gd.generated})${skipped ? `, пропущено ${skipped}` : ''}.`;
if (saveMsg) saveMsg.textContent = msg + tail;
} else {
if (saveMsg) saveMsg.textContent = msg;
@@ -561,11 +623,15 @@
}
const nQ = Math.min(30, Math.max(1, Number(aiQCountEl?.value || 7) || 7));
const nO = Math.min(8, Math.max(2, Number(aiOCountEl?.value || 3) || 3));
const globalMulti = !!(templateGlobalMultiEl && templateGlobalMultiEl.checked);
const globalRange = getTemplateCorrectRange(nO, globalMulti);
const shape = Array.from({ length: nQ }, () => ({
optionsCount: nO,
hasMultipleAnswers: false,
hasMultipleAnswers: globalMulti,
minCorrect: globalMulti ? globalRange.minCorrect : 1,
maxCorrect: globalMulti ? globalRange.maxCorrect : 1,
}));
aiStatusEl.textContent = 'Генерируем…';
aiStatusEl.textContent = 'Генерируем структуру и вопросы…';
try {
const r = await fetch(`/api/tests/${TEST_ID}/ai/generate-test`, {
method: 'POST',
@@ -589,6 +655,25 @@
renumber();
scheduleDirtyCheck();
aiStatusEl.textContent = `Готово: ${draft.questions?.length || 0} вопросов.`;
const hintsEl = document.getElementById('test-hints-enabled');
const modeEl = document.querySelector('input[name="result-mode"]:checked');
if (hintsEl && hintsEl.checked && modeEl && modeEl.value === 'immediate') {
aiStatusEl.textContent = 'Сохраняем черновик…';
try {
await saveCurrentDraftQuietly();
aiStatusEl.textContent = 'Генерируем вопросы… затем подсказки…';
const hr = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' });
const hd = await hr.json().catch(() => ({}));
if (hr.ok) {
const skipped = Number(hd.skipped || 0);
aiStatusEl.textContent = skipped
? `Готово: вопросы + подсказки (${hd.generated}, пропущено ${skipped}).`
: `Готово: вопросы + подсказки (${hd.generated}).`;
}
} catch (_) {
// Оставляем базовый статус готовности вопросов.
}
}
setTimeout(() => (aiStatusEl.textContent = ''), 4000);
} catch (e) {
aiStatusEl.textContent = '';
@@ -662,16 +747,29 @@
docGenerateBtn.disabled = true;
docGenerateBtn.textContent = 'Генерируем…';
aiStatusEl.textContent = 'Генерируем тест из документа…';
if (docProgressEl) docProgressEl.textContent = 'Шаг 1/3: подготовка шаблона…';
try {
const nQ = Math.min(30, Math.max(1, Number(aiQCountEl?.value || 7) || 7));
const nO = Math.min(8, Math.max(2, Number(aiOCountEl?.value || 3) || 3));
const globalMulti = !!(templateGlobalMultiEl && templateGlobalMultiEl.checked);
const globalRange = getTemplateCorrectRange(nO, globalMulti);
const shape = Array.from({ length: nQ }, () => ({
optionsCount: nO,
hasMultipleAnswers: globalMulti,
minCorrect: globalMulti ? globalRange.minCorrect : 1,
maxCorrect: globalMulti ? globalRange.maxCorrect : 1,
}));
if (docProgressEl) docProgressEl.textContent = 'Шаг 2/3: генерация вопросов…';
const r = await fetch('/api/tests/generate-from-extracted', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ extractedText: _extractedText, userHint }),
body: JSON.stringify({ extractedText: _extractedText, userHint, shape }),
});
const data = await r.json();
if (!r.ok) throw new Error(data.error || 'Ошибка генерации.');
const g = data.generation || {};
aiStatusEl.textContent = '';
if (docProgressEl) docProgressEl.textContent = 'Шаг 3/3: подготовка к применению…';
if (!g.available) {
openImportModal(
@@ -741,6 +839,7 @@
docGenerateBtn.disabled = false;
docGenerateBtn.innerHTML = '<span class="material-symbols-outlined text-base" style="vertical-align:-3px;">auto_awesome</span> Сгенерировать из документа';
}
if (docProgressEl) setTimeout(() => { docProgressEl.textContent = ''; }, 2500);
}
}
@@ -1393,6 +1492,8 @@
createTemplateBtn.addEventListener('click', () => {
const qCount = Math.min(30, Math.max(1, parseInt($('#ai-q-count').value || '7', 10)));
const oCount = Math.min(MAX_OPTIONS, Math.max(2, parseInt($('#ai-o-count').value || '3', 10)));
const globalMulti = !!(templateGlobalMultiEl && templateGlobalMultiEl.checked);
const range = getTemplateCorrectRange(oCount, globalMulti);
const existing = $$('#questions .q-item').length;
if (existing > 0) {
const ok = confirm(
@@ -1405,9 +1506,9 @@
for (let qi = 0; qi < qCount; qi++) {
const opts = [];
for (let oi = 0; oi < oCount; oi++) {
opts.push({ text: '', isCorrect: oi === 0 });
opts.push({ text: '', isCorrect: oi < range.minCorrect });
}
questionsEl.appendChild(renderQuestion({ text: '', hasMultipleAnswers: false, options: opts }));
questionsEl.appendChild(renderQuestion({ text: '', hasMultipleAnswers: globalMulti, options: opts }));
}
renumber();
scheduleDirtyCheck();
@@ -1416,6 +1517,39 @@
});
}
async function generateHintsForCurrentTest() {
if (!generateHintsBtn) return;
generateHintsBtn.disabled = true;
if (hintsStatusEl) hintsStatusEl.textContent = 'Сохраняем текущие изменения…';
try {
await saveCurrentDraftQuietly();
if (hintsStatusEl) hintsStatusEl.textContent = 'Генерируем подсказки…';
const r = await fetch(`/api/tests/${TEST_ID}/ai/hints/generate`, { method: 'POST' });
const data = await r.json().catch(() => ({}));
if (!r.ok) throw new Error(data.error || 'Не удалось сгенерировать подсказки.');
const skipped = Number(data.skipped || 0);
if (hintsStatusEl) {
hintsStatusEl.textContent = data.failed
? `Создано ${data.generated}, ошибок ${data.failed}${skipped ? `, пропущено ${skipped}` : ''}.`
: `Подсказки созданы: ${data.generated}${skipped ? `, пропущено ${skipped}` : ''}.`;
}
} catch (e) {
if (hintsStatusEl) hintsStatusEl.textContent = e.message || 'Ошибка генерации подсказок.';
} finally {
generateHintsBtn.disabled = false;
}
}
if (generateHintsBtn) {
generateHintsBtn.addEventListener('click', generateHintsForCurrentTest);
}
if (templateGlobalMultiEl) templateGlobalMultiEl.addEventListener('change', syncTemplateRangeUi);
if (templateMinCorrectEl) templateMinCorrectEl.addEventListener('input', syncTemplateRangeUi);
if (templateMaxCorrectEl) templateMaxCorrectEl.addEventListener('input', syncTemplateRangeUi);
if (aiOCountEl) aiOCountEl.addEventListener('input', syncTemplateRangeUi);
syncTemplateRangeUi();
Promise.all([
fetch(`/api/tests/${TEST_ID}/versions`).then((r) => r.json()).catch(() => null),
fetch(`/api/tests/${TEST_ID}/attempts`).then((r) => r.json()).catch(() => null),
+24 -2
View File
@@ -83,7 +83,7 @@
</label>
<label class="settings-radio">
<input type="radio" name="result-mode" value="immediate" />
<span>Сразу после ответа <span class="settings-row__hint">(с ИИ-подсказкой)</span></span>
<span>Сразу после ответа <span class="settings-row__hint">(с подсказкой)</span></span>
</label>
</fieldset>
@@ -94,6 +94,10 @@
</span>
<input id="test-hints-enabled" type="checkbox" />
</label>
<div class="settings-row settings-row--block" id="test-hints-actions" style="display:none;">
<button id="btn-generate-hints" class="btn btn-ghost btn--sm" type="button">Сгенерировать подсказки</button>
<p id="hints-status" class="settings-row__hint" style="margin-top:0.35rem;"></p>
</div>
<div class="settings-row settings-row--block" style="padding-top:0.75rem; border-top:1px solid var(--outline-variant); margin-top:0.25rem;">
<span class="settings-row__label">Видимость в каталоге</span>
@@ -137,6 +141,23 @@
Создать шаблон
</button>
</div>
<div class="mt-3 grid gap-2 sm:grid-cols-3 items-end">
<label class="inline-flex items-center gap-2 min-h-9">
<input id="template-global-multi" type="checkbox"
class="rounded border-ink-300 text-brand-600 focus:ring-brand-500" />
<span class="text-sm">Несколько правильных ответов (все вопросы)</span>
</label>
<label class="block">
<span class="form-label">Правильных: от</span>
<input id="template-min-correct" type="number" min="1" max="8" step="1" value="1"
class="form-input" style="width:90px;" />
</label>
<label class="block">
<span class="form-label">до</span>
<input id="template-max-correct" type="number" min="1" max="8" step="1" value="1"
class="form-input" style="width:90px;" />
</label>
</div>
</div>
{# ── Заполнить через ИИ по теме ──────────────────────────── #}
@@ -197,6 +218,7 @@
<span class="material-symbols-outlined text-base" style="vertical-align:-3px;">auto_awesome</span>
Сгенерировать из документа
</button>
<p id="doc-progress" class="mt-2 text-xs text-ink-500 min-h-[1rem]"></p>
</div>
{# ── Модалка результата импорта документа ─────────────────── #}
@@ -356,7 +378,7 @@
placeholder="Краткий текст подсказки (если в параметрах теста включены подсказки и режим «Сразу после ответа»)"
style="resize:none; overflow:hidden; font-family:inherit;"></textarea>
</label>
<p class="mt-1.5 text-xs text-ink-400 leading-snug">Необязательно. Показывается участнику во всплывающем окне при верном ответе.</p>
<p class="mt-1.5 text-xs text-ink-400 leading-snug">Необязательно. Показывается участнику во всплывающем окне после ответа на вопрос.</p>
</div>
</li>
</template>
+8 -1
View File
@@ -545,9 +545,16 @@ def api_generate_from_extracted():
body = request.get_json(silent=True) or {}
extracted = (body.get('extractedText') or '').strip()
user_hint = (body.get('userHint') or '').strip()
shape_raw = body.get('shape')
if not extracted:
return jsonify(error='Нет текста для генерации.'), 400
generation = generation_for_import_document(extracted, user_hint=user_hint)
shape = None
if shape_raw:
try:
shape = parse_and_validate_shape(shape_raw)
except (AiHttpError, LlmError) as e:
return _ai_error_response(e)
generation = generation_for_import_document(extracted, user_hint=user_hint, shape=shape)
return jsonify(generation=generation)