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
+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': (