-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsynthesizer_ocaml.py
More file actions
54 lines (47 loc) · 2.62 KB
/
synthesizer_ocaml.py
File metadata and controls
54 lines (47 loc) · 2.62 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import tempfile
import subprocess
import time
from typing import Optional
from synthesizer import ProgramSynthesizer
from logger import SynthesisLogger
from report import EvaluationReport
from dataset import ProgramSynthesisDatapoint
class OCamlProgramSynthesizer(ProgramSynthesizer):
def __init__(self, prompting_method: str = "zero_shot", model_name: str = "gemini-1.5-flash",
api_key: Optional[str] = None, logger: Optional[SynthesisLogger] = None):
super().__init__("ocaml", prompting_method, model_name, api_key, logger)
self._ocaml_available = self._check_ocaml_availability()
def _check_ocaml_availability(self) -> bool:
"""Check if OCaml is available and set up environment once."""
try:
# Check if ocaml command is available
result = subprocess.run(
["ocaml", "-version"],
capture_output=True,
timeout=5,
text=True
)
return result.returncode == 0
except (FileNotFoundError, subprocess.TimeoutExpired):
return False
def evaluate(self, datapoint: ProgramSynthesisDatapoint, synthesized_program: str) -> EvaluationReport:
"""Evaluate OCaml program with comprehensive execution testing."""
report = EvaluationReport(synthesized_program)
# Create temporary directory for execution
with tempfile.TemporaryDirectory() as temp_dir:
################################################################################
# #
# TODO: Part 1c. Evaluate OCaml program with comprehensive execution testing. #
# #
# Populate the report with the evaluation results. Check for syntax errors, #
# runtime errors, and test cases (which are in datapoint.sample_inputs and #
# datapoint.sample_outputs). #
# #
# To run the program, you can create a temporary file and write the program to #
# it. Then, you can use subprocess to run the program with the test cases. #
# #
################################################################################
pass
report.finalize()
return report