feat: add MongoDB test generation and update dependencies
- Added pymongo==3.13.0 to requirements.txt for MongoDB connectivity - Implemented generate_summarization_from_mongo.py script to generate summarization tests from MongoDB - Updated run.sh to support 'gen-mongo' command for MongoDB test generation - Enhanced scripts/README.md with documentation for new MongoDB functionality - Improved help text in run.sh to clarify available commands and usage examples ``` This commit adds MongoDB integration for test generation and updates the documentation and scripts accordingly.
This commit is contained in:
73
scripts/convert_json_to_txt.py
Normal file
73
scripts/convert_json_to_txt.py
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/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 src.benchmarks.base 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()
|
||||
Reference in New Issue
Block a user