feat: мульти-провайдер AI, выбор типов заданий, настройка количества
- Добавлена поддержка нескольких AI провайдеров (OpenAI, Google Gemini) - Добавлена админ-панель (/admin) для переключения AI моделей - Добавлен AIModelService для управления моделями в БД - Добавлен выбор типа заданий (микс, перевод слов, подстановка, перевод предложений) - Добавлена настройка количества заданий (5-15) - ai_service динамически выбирает провайдера на основе активной модели - Обработка ограничений моделей (temperature, response_format) - Очистка markdown обёртки из ответов Gemini 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
46
migrations/versions/20251208_add_ai_models.py
Normal file
46
migrations/versions/20251208_add_ai_models.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""Add ai_models table
|
||||
|
||||
Revision ID: 20251208_ai_models
|
||||
Revises: 20251208_tasks_count
|
||||
Create Date: 2024-12-08
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '20251208_ai_models'
|
||||
down_revision: Union[str, None] = '20251208_tasks_count'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Создаём таблицу ai_models (enum aiprovider создаётся автоматически SQLAlchemy)
|
||||
op.create_table(
|
||||
'ai_models',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('provider', postgresql.ENUM('openai', 'google', name='aiprovider', create_type=False), nullable=False),
|
||||
sa.Column('model_name', sa.String(length=100), nullable=False),
|
||||
sa.Column('display_name', sa.String(length=100), nullable=False),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True, server_default='false'),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Добавляем дефолтные модели
|
||||
op.execute("""
|
||||
INSERT INTO ai_models (provider, model_name, display_name, is_active, created_at)
|
||||
VALUES
|
||||
('openai', 'gpt-4o-mini', 'GPT-4o Mini', true, NOW()),
|
||||
('openai', 'gpt-5-nano', 'GPT-5 Nano', false, NOW()),
|
||||
('google', 'gemini-2.5-flash-lite', 'Gemini 2.5 Flash Lite', false, NOW())
|
||||
""")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_table('ai_models')
|
||||
28
migrations/versions/20251208_add_tasks_count.py
Normal file
28
migrations/versions/20251208_add_tasks_count.py
Normal file
@@ -0,0 +1,28 @@
|
||||
"""Add tasks_count field to users
|
||||
|
||||
Revision ID: 20251208_tasks_count
|
||||
Revises: 20251207_translation_language
|
||||
Create Date: 2024-12-08
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '20251208_tasks_count'
|
||||
down_revision: Union[str, None] = '20251207_translation_language'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column('users', sa.Column('tasks_count', sa.Integer(), nullable=True, server_default='5'))
|
||||
# Установим дефолт для существующих записей
|
||||
op.execute("UPDATE users SET tasks_count = 5 WHERE tasks_count IS NULL")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_column('users', 'tasks_count')
|
||||
Reference in New Issue
Block a user