Spaces:
Sleeping
Sleeping
from dataclasses import dataclass, field | |
from pathlib import Path | |
from tomlkit.items import Integer | |
from gpt_engineer.core.project_config import read_config | |
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 | |
class MbppConfig: | |
active: bool | None = True | |
test_len: int | None = 1 | |
train_len: int | None = 0 | |
class GptmeConfig: | |
active: bool | None = True | |
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) | |
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) | |
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", {})), | |
) | |
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 | |