Реализованы настройки пользователя и новые типы заданий
Создано: - bot/handlers/settings.py - обработчик команды /settings Реализовано: ✅ /settings - настройки пользователя - Выбор уровня английского (A1-C2) - Выбор языка интерфейса (RU/EN) - Интерактивные inline-кнопки ✅ Новый тип заданий - заполнение пропусков - AI генерирует предложение с пропуском - Показывает перевод для контекста - Проверка ответа через AI ✅ Смешанные задания - Случайное чередование типов (переводы + fill-in) - Более разнообразная практика Изменено: - services/ai_service.py - метод generate_fill_in_sentence() - services/task_service.py - метод generate_mixed_tasks() - services/user_service.py - методы обновления настроек - bot/handlers/tasks.py - использование смешанных заданий - main.py - регистрация роутера настроек Теперь бот предлагает: - Перевод EN→RU - Перевод RU→EN - Заполнение пропусков в предложениях 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from database.models import Task, Vocabulary
|
||||
from services.ai_service import ai_service
|
||||
|
||||
|
||||
class TaskService:
|
||||
@@ -70,6 +71,87 @@ class TaskService:
|
||||
|
||||
return tasks
|
||||
|
||||
@staticmethod
|
||||
async def generate_mixed_tasks(
|
||||
session: AsyncSession,
|
||||
user_id: int,
|
||||
count: int = 5
|
||||
) -> List[Dict]:
|
||||
"""
|
||||
Генерация заданий разных типов (переводы + заполнение пропусков)
|
||||
|
||||
Args:
|
||||
session: Сессия базы данных
|
||||
user_id: ID пользователя
|
||||
count: Количество заданий
|
||||
|
||||
Returns:
|
||||
Список заданий разных типов
|
||||
"""
|
||||
# Получаем слова пользователя
|
||||
result = await session.execute(
|
||||
select(Vocabulary)
|
||||
.where(Vocabulary.user_id == user_id)
|
||||
.order_by(Vocabulary.last_reviewed.asc().nullsfirst())
|
||||
.limit(count * 2)
|
||||
)
|
||||
words = list(result.scalars().all())
|
||||
|
||||
if not words:
|
||||
return []
|
||||
|
||||
# Выбираем случайные слова
|
||||
selected_words = random.sample(words, min(count, len(words)))
|
||||
|
||||
tasks = []
|
||||
for word in selected_words:
|
||||
# Случайно выбираем тип задания
|
||||
task_type = random.choice(['translate', 'fill_in'])
|
||||
|
||||
if task_type == 'translate':
|
||||
# Задание на перевод
|
||||
direction = random.choice(['en_to_ru', 'ru_to_en'])
|
||||
|
||||
if direction == 'en_to_ru':
|
||||
task = {
|
||||
'type': 'translate_to_ru',
|
||||
'word_id': word.id,
|
||||
'question': f"Переведи слово: <b>{word.word_original}</b>",
|
||||
'word': word.word_original,
|
||||
'correct_answer': word.word_translation,
|
||||
'transcription': word.transcription
|
||||
}
|
||||
else:
|
||||
task = {
|
||||
'type': 'translate_to_en',
|
||||
'word_id': word.id,
|
||||
'question': f"Переведи слово: <b>{word.word_translation}</b>",
|
||||
'word': word.word_translation,
|
||||
'correct_answer': word.word_original,
|
||||
'transcription': word.transcription
|
||||
}
|
||||
else:
|
||||
# Задание на заполнение пропуска
|
||||
# Генерируем предложение с пропуском через AI
|
||||
sentence_data = await ai_service.generate_fill_in_sentence(word.word_original)
|
||||
|
||||
task = {
|
||||
'type': 'fill_in',
|
||||
'word_id': word.id,
|
||||
'question': (
|
||||
f"Заполни пропуск в предложении:\n\n"
|
||||
f"<b>{sentence_data['sentence']}</b>\n\n"
|
||||
f"<i>{sentence_data.get('translation', '')}</i>"
|
||||
),
|
||||
'word': word.word_original,
|
||||
'correct_answer': sentence_data['answer'],
|
||||
'sentence': sentence_data['sentence']
|
||||
}
|
||||
|
||||
tasks.append(task)
|
||||
|
||||
return tasks
|
||||
|
||||
@staticmethod
|
||||
async def save_task_result(
|
||||
session: AsyncSession,
|
||||
|
||||
Reference in New Issue
Block a user