Spaces:
Runtime error
Runtime error
| import re | |
| with open("backend/prompts/synthesis.py", "r", encoding="utf-8") as f: | |
| content = f.read() | |
| # Separate MASTER_SYNTHESIS_PROMPT from the rest | |
| idx = content.find('WRITING_PROMPT = """') | |
| if idx == -1: | |
| print("Could not find WRITING_PROMPT") | |
| exit(1) | |
| master_part = content[:idx] | |
| rest_part = content[idx:] | |
| # In rest_part, we want to fix the curly braces. | |
| # \section{{{section}}} -> \section{{section}} | |
| rest_part = rest_part.replace(r"\section{{{section}}}", r"\section{{section}}") | |
| # \subsection{{}} -> \subsection{} | |
| rest_part = rest_part.replace(r"\subsection{{}}", r"\subsection{}") | |
| # \subsubsection{{}} -> \subsubsection{} | |
| rest_part = rest_part.replace(r"\subsubsection{{}}", r"\subsubsection{}") | |
| # \textbf{{texto}} -> \textbf{texto} | |
| rest_part = rest_part.replace(r"\textbf{{texto}}", r"\textbf{texto}") | |
| # \textit{{texto}} -> \textit{texto} | |
| rest_part = rest_part.replace(r"\textit{{texto}}", r"\textit{texto}") | |
| # \begin{{itemize}} -> \begin{itemize} | |
| rest_part = rest_part.replace(r"\begin{{itemize}}", r"\begin{itemize}") | |
| # \end{{itemize}} -> \end{itemize} | |
| rest_part = rest_part.replace(r"\end{{itemize}}", r"\end{itemize}") | |
| # {{{{BIB:ID}}}} -> {{BIB:ID}} | |
| rest_part = rest_part.replace(r"{{{{BIB:ID}}}}", r"{{BIB:ID}}") | |
| # For JSON in VALIDATION_PROMPT, AUDIT_PROMPT, ARA_PROMPT | |
| # We can replace {{ with { and }} with } but we MUST NOT break {{BIB:ID}} | |
| # So first we temporarily change {{BIB:ID}} to something else | |
| rest_part = rest_part.replace(r"{{BIB:ID}}", r"__BIB_ID__") | |
| rest_part = rest_part.replace(r"{{", r"{") | |
| rest_part = rest_part.replace(r"}}", r"}") | |
| rest_part = rest_part.replace(r"__BIB_ID__", r"{{BIB:ID}}") | |
| # Write back | |
| with open("backend/prompts/synthesis.py", "w", encoding="utf-8") as f: | |
| f.write(master_part + rest_part) | |
| print("Fixed backend/prompts/synthesis.py") | |