2024-09-23 19:32:01 +08:00
|
|
|
from pathlib import Path
|
2024-05-21 22:48:41 +08:00
|
|
|
|
|
|
|
|
import yaml
|
2024-07-25 15:20:04 +08:00
|
|
|
|
2024-06-05 15:36:15 +08:00
|
|
|
from rdagent.core.utils import SingletonBaseClass
|
2024-05-21 22:48:41 +08:00
|
|
|
|
|
|
|
|
|
2024-09-20 12:07:13 +08:00
|
|
|
class Prompts(SingletonBaseClass, dict[str, str]):
|
2024-06-12 15:12:11 +08:00
|
|
|
def __init__(self, file_path: Path) -> None:
|
2024-07-25 15:20:04 +08:00
|
|
|
super().__init__()
|
2024-06-12 15:12:11 +08:00
|
|
|
with file_path.open(encoding="utf8") as file:
|
|
|
|
|
prompt_yaml_dict = yaml.safe_load(file)
|
2024-05-21 22:48:41 +08:00
|
|
|
|
2024-06-05 15:36:15 +08:00
|
|
|
if prompt_yaml_dict is None:
|
2024-06-12 15:12:11 +08:00
|
|
|
error_message = f"Failed to load prompts from {file_path}"
|
|
|
|
|
raise ValueError(error_message)
|
2024-06-05 15:36:15 +08:00
|
|
|
|
2024-05-21 22:48:41 +08:00
|
|
|
for key, value in prompt_yaml_dict.items():
|
|
|
|
|
self[key] = value
|