Is anyone else keeping the final prompt so you can regenerate your code
I was trying to capture best practices by using this template which would be saved w/ the source code (see example below)
GROUND RULES ---------------------------------------------------
- Use GPT-4 (32k) model & Code Copilot
- Generate Python code compatible with version 3.8
- Use the PEP8 standard and Use type hints
- Use the role of an expert python programmer
HEADER ------------------------------------------------------------
- Document the file header with best practices
- Include Today's Date
DESCRIPTION ---------------------------------------------------------
- Write a configuration manager that persists key value string pairs
- Save configuration in a yaml file named cfg.yaml
- automatically save the configuration when the program ends
- automatically load the configuration when initially accessed
ARCHITECTURE ---------------------------------------------------
- Use a singleton pattern to get access to the global configuration
- Make globally accessible w/o having to instantiate the class directly each time
INTERFACE ------------------------------------------------------
- Include a get() and set() method
- Use a key value string pair to get/set configuration items
WORKAROUNDS ----------------------------------------------------
- All optional parameters are listed last in the parameter list
I then get the following CODE
import ....
class ConfigManager:
_instance = None
_config_file = "cfg.yaml"
_config_data = {}
def __new__(cls):
if cls._instance is None:
cls._instance = super(ConfigManager, cls).__new__(cls)
cls._instance._load_config()
atexit.register(cls._instance._save_config)
return cls._instance
def _load_config(self) -> None:
if os.path.exists(self._config_file):
with open(self._config_file, 'r') as file:
self._config_data = yaml.safe_load(file) or {}
def _save_config(self) -> None:
with open(self._config_file, 'w') as file:
yaml.dump(self._config_data, file)
def get(self, key: str) -> Optional[str]:
return self._config_data.get(key)
def set(self, key: str, value: str) -> None:
self._config_data[key] = value