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:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -6,6 +6,9 @@ from typing import Dict, Any, List
|
||||
from abc import ABC, abstractmethod
|
||||
from models.ollama_client import OllamaClient
|
||||
|
||||
# Импортируем константы
|
||||
from constants import TEST_SEPARATOR
|
||||
|
||||
class Benchmark(ABC):
|
||||
"""Базовый класс для всех бенчмарков."""
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, Any, List
|
||||
from benchmarks.base import Benchmark
|
||||
from benchmarks.base import Benchmark, TEST_SEPARATOR
|
||||
|
||||
class CodeGenBenchmark(Benchmark):
|
||||
class CodegenBenchmark(Benchmark):
|
||||
"""Бенчмарк для тестирования генерации кода."""
|
||||
|
||||
def __init__(self):
|
||||
@@ -21,14 +21,17 @@ class CodeGenBenchmark(Benchmark):
|
||||
data_dir = "tests/codegen"
|
||||
|
||||
for filename in os.listdir(data_dir):
|
||||
if filename.endswith('.json'):
|
||||
if filename.endswith('.txt'):
|
||||
with open(os.path.join(data_dir, filename), 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
test_data.append({
|
||||
'name': filename.replace('.json', ''),
|
||||
'prompt': data['prompt'],
|
||||
'expected': data['expected']
|
||||
})
|
||||
content = f.read()
|
||||
# Разделяем по разделителю
|
||||
parts = content.split(TEST_SEPARATOR, 1)
|
||||
if len(parts) == 2:
|
||||
test_data.append({
|
||||
'name': filename.replace('.txt', ''),
|
||||
'prompt': parts[0],
|
||||
'expected': parts[1]
|
||||
})
|
||||
|
||||
return test_data
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, Any, List
|
||||
from benchmarks.base import Benchmark
|
||||
from benchmarks.base import Benchmark, TEST_SEPARATOR
|
||||
|
||||
class SummarizationBenchmark(Benchmark):
|
||||
"""Бенчмарк для тестирования пересказов."""
|
||||
@@ -21,14 +21,17 @@ class SummarizationBenchmark(Benchmark):
|
||||
data_dir = "tests/summarization"
|
||||
|
||||
for filename in os.listdir(data_dir):
|
||||
if filename.endswith('.json'):
|
||||
if filename.endswith('.txt'):
|
||||
with open(os.path.join(data_dir, filename), 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
test_data.append({
|
||||
'name': filename.replace('.json', ''),
|
||||
'prompt': data['prompt'],
|
||||
'expected': data['expected']
|
||||
})
|
||||
content = f.read()
|
||||
# Разделяем по разделителю
|
||||
parts = content.split(TEST_SEPARATOR, 1)
|
||||
if len(parts) == 2:
|
||||
test_data.append({
|
||||
'name': filename.replace('.txt', ''),
|
||||
'prompt': parts[0],
|
||||
'expected': parts[1]
|
||||
})
|
||||
|
||||
return test_data
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Dict, Any, List
|
||||
from benchmarks.base import Benchmark
|
||||
from benchmarks.base import Benchmark, TEST_SEPARATOR
|
||||
|
||||
class TranslationBenchmark(Benchmark):
|
||||
"""Бенчмарк для тестирования переводов."""
|
||||
@@ -21,14 +21,17 @@ class TranslationBenchmark(Benchmark):
|
||||
data_dir = "tests/translation"
|
||||
|
||||
for filename in os.listdir(data_dir):
|
||||
if filename.endswith('.json'):
|
||||
if filename.endswith('.txt'):
|
||||
with open(os.path.join(data_dir, filename), 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
test_data.append({
|
||||
'name': filename.replace('.json', ''),
|
||||
'prompt': data['prompt'],
|
||||
'expected': data['expected']
|
||||
})
|
||||
content = f.read()
|
||||
# Разделяем по разделителю
|
||||
parts = content.split(TEST_SEPARATOR, 1)
|
||||
if len(parts) == 2:
|
||||
test_data.append({
|
||||
'name': filename.replace('.txt', ''),
|
||||
'prompt': parts[0],
|
||||
'expected': parts[1]
|
||||
})
|
||||
|
||||
return test_data
|
||||
|
||||
|
||||
4
src/constants.py
Normal file
4
src/constants.py
Normal file
@@ -0,0 +1,4 @@
|
||||
"""Константы для проекта."""
|
||||
|
||||
# Константа для разделителя в TXT файлах
|
||||
TEST_SEPARATOR = "\n==============\n"
|
||||
@@ -4,7 +4,7 @@ from typing import List
|
||||
from models.ollama_client import OllamaClient
|
||||
from benchmarks.translation import TranslationBenchmark
|
||||
from benchmarks.summarization import SummarizationBenchmark
|
||||
from benchmarks.codegen import CodeGenBenchmark
|
||||
from benchmarks.codegen import CodegenBenchmark
|
||||
from utils.report import ReportGenerator
|
||||
|
||||
def setup_logging(verbose: bool = False):
|
||||
@@ -33,7 +33,7 @@ def run_benchmarks(ollama_client: OllamaClient, model_name: str, benchmarks: Lis
|
||||
benchmark_classes = {
|
||||
'translation': TranslationBenchmark,
|
||||
'summarization': SummarizationBenchmark,
|
||||
'codegen': CodeGenBenchmark
|
||||
'codegen': CodegenBenchmark
|
||||
}
|
||||
|
||||
results = []
|
||||
|
||||
Reference in New Issue
Block a user