/
gr.ev.vl
/
TestGen
Обзор
Документация
Войти
/
gr.ev.vl
/
TestGen
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
scripts/fix_prompts.cmd
76 строк
3 KB
gr.ev.vl
Initial commit
06 июн 2026, 02:41
06 июн 2026, 02:41
02fb1fb
Код
Авторство
О чём код?
@echo off chcp 65001 >nul setlocal enabledelayedexpansion set "SCRIPT_DIR=%~dp0" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%" set "BACKEND_DIR=%SCRIPT_DIR%\.." cd /d "%BACKEND_DIR%" :: ����� Python set "PYTHON_EXE=" if exist ".venv\Scripts\python.exe" set "PYTHON_EXE=.venv\Scripts\python.exe" if "%PYTHON_EXE%"=="" if exist "..\.venv\Scripts\python.exe" set "PYTHON_EXE=..\.venv\Scripts\python.exe" if "%PYTHON_EXE%"=="" ( where python >nul 2>&1 if !errorlevel! equ 0 for /f "delims=" %%i in ('where python') do set "PYTHON_EXE=%%i" ) if "%PYTHON_EXE%"=="" ( echo Python not found pause exit /b 1 ) echo Python: %PYTHON_EXE% echo. echo Fixing prompts... echo. set "TMP_PY=%TEMP%\fix_prompts_%RANDOM%.py" ( echo import asyncio echo from uuid import uuid4 echo from .testgen.infrastructure.database.session import async_session_factory echo from sqlalchemy import text echo. echo async def fix_prompts^(^): echo async with async_session_factory^(^) as session: echo r = await session.execute^(text^("SELECT id FROM users LIMIT 1"^)^) echo uid = str^(r.fetchone^(^)[0]^) echo r = await session.execute^(text^("SELECT id, name, prompt_type FROM prompts"^)^) echo prompts = r.fetchall^(^) echo print^(f"Prompts found: {len(prompts)}"^) echo for pid, name, pt in prompts: echo r2 = await session.execute^(text^("SELECT COUNT^(^*^) FROM prompt_versions WHERE prompt_id = :p"^), {"p": pid}^) echo vc = r2.fetchone^(^)[0] echo if vc == 0: echo if pt.startswith^("question"^): echo content = "Create {{count}} test questions for topic {{subtopic_name}}. Bloom level: {{bloom_level}}. Return JSON." echo elif pt.startswith^("misconception"^): echo content = "List {{count}} common student misconceptions for topic {{subtopic_name}}. Return JSON." echo elif pt.startswith^("distractor"^): echo content = "Generate distractors for question: {{question_text}}. Correct answer: {{correct_answer}}. Return JSON." echo else: echo content = "Prompt content with {{variable}}" echo await session.execute^(text^("INSERT INTO prompt_versions (id, prompt_id, version_number, content, variables, response_format, is_current, created_by, created_at, updated_at) VALUES (:vid, :pid, 1, :c, '{}'::jsonb, '{}'::jsonb, true, :uid, now(), now())"^), {"vid": str^(uuid4^(^)^), "pid": pid, "c": content, "uid": uid}^) echo print^(f" + version for: {name}"^) echo else: echo r3 = await session.execute^(text^("SELECT COUNT^(^*^) FROM prompt_versions WHERE prompt_id = :p AND is_current = true"^), {"p": pid}^) echo if r3.fetchone^(^)[0] == 0: echo await session.execute^(text^("UPDATE prompt_versions SET is_current = true WHERE prompt_id = :p AND version_number = 1"^), {"p": pid}^) echo print^(f" * activated: {name}"^) echo else: echo print^(f" OK: {name}"^) echo await session.commit^(^) echo print^("Done!"^) echo. echo asyncio.run^(fix_prompts^(^)^) ) > "%TMP_PY%" "%PYTHON_EXE%" "%TMP_PY%" del "%TMP_PY%" >nul 2>&1 echo. pause