Spaces:
Runtime error
Runtime error
File size: 1,108 Bytes
6510272 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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 |