Updated import paths to use direct module references instead of relative paths. Implemented dynamic benchmark discovery based on the contents of the tests/ directory, allowing for more flexible benchmark configuration without requiring code changes. This change improves maintainability and makes it easier to add new benchmarks.
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Скрипт для конвертации существующих JSON тестов в новый TXT формат.
|
||
|
||
Конвертирует все тесты из JSON в TXT с разделителем ================
|
||
"""
|
||
|
||
import json
|
||
import os
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
# Добавляем путь к исходникам, чтобы импортировать base
|
||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||
|
||
from benchmark import TEST_SEPARATOR
|
||
|
||
def convert_tests(test_dir: str) -> None:
|
||
"""Конвертирует все тесты в указанной директории."""
|
||
test_dir_path = Path(test_dir)
|
||
if not test_dir_path.exists():
|
||
print(f"❌ Директория {test_dir} не существует")
|
||
return
|
||
|
||
converted_count = 0
|
||
|
||
for json_file in test_dir_path.glob("*.json"):
|
||
try:
|
||
# Читаем JSON файл
|
||
with open(json_file, "r", encoding="utf-8") as f:
|
||
data = json.load(f)
|
||
|
||
# Создаем имя TXT файла
|
||
txt_file = test_dir_path / f"{json_file.stem}.txt"
|
||
|
||
# Сохраняем в TXT формате
|
||
with open(txt_file, "w", encoding="utf-8") as f:
|
||
f.write(f"{data['prompt']}{TEST_SEPARATOR}{data['expected']}")
|
||
|
||
converted_count += 1
|
||
print(f"✅ Конвертирован {json_file.name} в {txt_file.name}")
|
||
|
||
except Exception as e:
|
||
print(f"❌ Ошибка при конвертации {json_file.name}: {str(e)}")
|
||
|
||
print(f"\nРезультаты конвертации:")
|
||
print(f"Конвертировано тестов: {converted_count}")
|
||
|
||
def main():
|
||
"""Основная функция скрипта."""
|
||
import argparse
|
||
|
||
parser = argparse.ArgumentParser(
|
||
description="Конвертер тестовых данных из JSON в TXT формат",
|
||
epilog="Примеры использования:\n"
|
||
" python scripts/convert_json_to_txt.py tests/translation\n"
|
||
" python scripts/convert_json_to_txt.py tests/summarization\n"
|
||
" python scripts/convert_json_to_txt.py tests/codegen"
|
||
)
|
||
parser.add_argument(
|
||
"test_dir",
|
||
type=str,
|
||
help="Директория с тестами для конвертации (например: tests/translation)"
|
||
)
|
||
|
||
args = parser.parse_args()
|
||
|
||
print(f"🔄 Конвертирую тесты в {args.test_dir}")
|
||
convert_tests(args.test_dir)
|
||
print("\n✨ Готово!")
|
||
|
||
if __name__ == "__main__":
|
||
main()
|