|
import re |
|
|
|
|
|
def parse_chat(chat): |
|
|
|
regex = r"(\S+)\n\s*```[^\n]*\n(.+?)```" |
|
matches = re.finditer(regex, chat, re.DOTALL) |
|
|
|
files = [] |
|
for match in matches: |
|
|
|
path = re.sub(r'[<>"|?*]', "", match.group(1)) |
|
|
|
|
|
path = re.sub(r"^\[(.*)\]$", r"\1", path) |
|
|
|
|
|
path = re.sub(r"^`(.*)`$", r"\1", path) |
|
|
|
|
|
path = re.sub(r"\]$", "", path) |
|
|
|
|
|
code = match.group(2) |
|
|
|
|
|
files.append((path, code)) |
|
|
|
|
|
readme = chat.split("```")[0] |
|
files.append(("README.md", readme)) |
|
|
|
|
|
return files |
|
|
|
|
|
def to_files(chat, workspace): |
|
workspace["all_output.txt"] = chat |
|
|
|
files = parse_chat(chat) |
|
for file_name, file_content in files: |
|
workspace[file_name] = file_content |
|
|