Spaces:
Runtime error
Runtime error
Download parser.py from recallai/mycodesucks: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/recallai/mycodesucks/resolve/main/parser.py
- Command line
-
hf download hf://spaces/recallai/mycodesucks/parser.py
-
curl -L -o parser.py https://huggingface.co/spaces/recallai/mycodesucks/resolve/main/parser.py
1.11 kB
| class MinimalPromptParser: | |
| def __init__(self): | |
| self.parsed_data = [] | |
| def parse_file(self, filename, user_input): | |
| with open(filename, 'r') as file: | |
| role = None | |
| content = "" | |
| for line in file: | |
| line = line.strip() | |
| if line.startswith("system:") or line.startswith("user:"): | |
| if role is not None: | |
| self.parsed_data.append({"role": role, "content": content}) | |
| role = line.split(":")[0] | |
| content = "" | |
| else: | |
| content += line + "\n" | |
| if role is not None: | |
| self.parsed_data.append({"role": role, "content": content}) | |
| self.replace_placeholders(user_input) | |
| return self.parsed_data | |
| def replace_placeholders(self, user_input): | |
| for item in self.parsed_data: | |
| content = item["content"] | |
| for key, value in user_input.items(): | |
| content = content.replace("{{" + key + "}}", value) | |
| item["content"] = content |