From 90e1e53bb69a79afd8dafa87cefd6e75e61ef5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E4=BC=9F=E9=9F=AC?= Date: Mon, 12 Aug 2024 20:07:35 +0800 Subject: [PATCH] add annotations --- metagpt/utils/repair_llm_raw_output.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/metagpt/utils/repair_llm_raw_output.py b/metagpt/utils/repair_llm_raw_output.py index fc27448eb..f1607255e 100644 --- a/metagpt/utils/repair_llm_raw_output.py +++ b/metagpt/utils/repair_llm_raw_output.py @@ -353,6 +353,23 @@ def repair_escape_error(commands): """ Repaires escape errors in command responses. When role-zero parses a command, the command may contain unknown escape characters. + + This function has two steps: + 1. Transform unescaped substrings like "\d" and "\(" to "\\\\d" and "\\\\(". + 2. Transform escaped characters like '\f' to substrings like "\\\\f". + + Example: + When the original JSON string is " {"content":"\\\\( \\\\frac{1}{2} \\\\)"} ", + The "content" will be parsed correctly to "\( \frac{1}{2} \)". + + When there is a wrong JSON string like: " {"content":"\( \frac{1}{2} \)"}", + It will cause a parsing error. + + To repair the wrong JSON string, the following transformations will be used: + "\(" ---> "\\\\(" + '\f' ---> "\\\\f" + "\)" ---> "\\\\)" + """ escape_repair_map = { "\a": "\\\\a",