Download augmentoolkit/generation_functions/safe_formatter.py from Leon4gr45/agent-0: direct link, hf CLI and curl.
- Browser
- Download file 577 Bytes
-
https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/augmentoolkit/generation_functions/safe_formatter.py
- Command line
-
hf download hf://spaces/Leon4gr45/agent-0/augmentoolkit/generation_functions/safe_formatter.py
-
curl -L -o safe_formatter.py https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/augmentoolkit/generation_functions/safe_formatter.py
577 Bytes
| import string | |
| class SafeFormatter(string.Formatter): | |
| def get_value(self, key, args, kwargs): | |
| if isinstance(key, str): | |
| return kwargs.get(key, "{" + key + "}") | |
| else: | |
| return super().get_value(key, args, kwargs) | |
| def parse(self, format_string): | |
| try: | |
| return super().parse(format_string) | |
| except ValueError: | |
| return [(format_string, None, None, None)] | |
| def safe_format(format_string, *args, **kwargs): | |
| formatter = SafeFormatter() | |
| return formatter.format(format_string, *args, **kwargs) | |