-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathprompt.py
More file actions
39 lines (28 loc) · 1.59 KB
/
Copy pathprompt.py
File metadata and controls
39 lines (28 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import re
from pathlib import Path
from jinja2.sandbox import SandboxedEnvironment
from bcbench.config import get_config
from bcbench.dataset import BaseDatasetEntry
from bcbench.types import EvaluationCategory
_config = get_config()
_jinja = SandboxedEnvironment(autoescape=False)
def _transform_image_paths(content: str) -> str:
dest_dir = _config.file_patterns.problem_statement_dest_dir
return re.sub(r"!\[([^\]]*)\]\(\./([^)]+)\)", rf"", content)
def build_prompt(entry: BaseDatasetEntry, repo_path: Path, config: dict, category: EvaluationCategory, al_mcp: bool = False) -> str:
prompt_config = config.get("prompt", {})
template_str = prompt_config.get(f"{category.value}-template")
include_project_paths = prompt_config.get("include_project_paths")
test_gen_input: str = prompt_config.get("test-generation-input", "problem-statement")
is_gold_patch: bool = category == EvaluationCategory.TEST_GENERATION and test_gen_input in ("gold-patch", "both")
is_problem_statement: bool = category == EvaluationCategory.TEST_GENERATION and test_gen_input in ("problem-statement", "both")
task = _transform_image_paths(entry.get_task())
return _jinja.from_string(template_str).render(
repo_path=repo_path,
task=task,
project_paths=", ".join(entry.project_paths),
include_project_paths=include_project_paths,
is_gold_patch=is_gold_patch, # only relevant for test-generation
is_problem_statement=is_problem_statement, # only relevant for test-generation
al_mcp=al_mcp, # whether AL MCP server is enabled
)