Spaces:
Sleeping
Sleeping
File size: 1,983 Bytes
3860419 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from dataclasses import dataclass, field
from pathlib import Path
from tomlkit.items import Integer
from gpt_engineer.core.project_config import read_config
@dataclass
class AppsConfig:
active: bool | None = True
test_start_index: int | None = 0
test_end_index: int | None = 1
train_start_index: int | None = 0
train_end_index: int | None = 0
examples_per_problem: int | None = 10
@dataclass
class MbppConfig:
active: bool | None = True
test_len: int | None = 1
train_len: int | None = 0
@dataclass
class GptmeConfig:
active: bool | None = True
@dataclass
class BenchConfig:
"""Configuration for the GPT Engineer CLI and gptengineer.app via `gpt-engineer.toml`."""
apps: AppsConfig = field(default_factory=AppsConfig)
mbpp: MbppConfig = field(default_factory=MbppConfig)
gptme: GptmeConfig = field(default_factory=GptmeConfig)
@classmethod
def from_toml(cls, config_file: Path | str):
if isinstance(config_file, str):
config_file = Path(config_file)
config_dict = read_config(config_file)
return cls.from_dict(config_dict)
@classmethod
def from_dict(cls, config_dict: dict):
return cls(
apps=AppsConfig(**config_dict.get("apps", {})),
mbpp=MbppConfig(**config_dict.get("mbpp", {})),
gptme=GptmeConfig(**config_dict.get("gptme", {})),
)
@staticmethod
def recursive_resolve(data_dict):
for key, value in data_dict.items():
if isinstance(value, Integer):
data_dict[key] = int(value)
elif isinstance(value, dict):
BenchConfig.recursive_resolve(value)
def to_dict(self):
dict_config = {
benchmark_name: {key: val for key, val in spec_config.__dict__.items()}
for benchmark_name, spec_config in self.__dict__.items()
}
BenchConfig.recursive_resolve(dict_config)
return dict_config
|