Spaces:
Runtime error
Runtime error
| 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 |