🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
fix: Enable extractor to handle single boxed backslashes (#2167)
Apokryphosxf2b14c2494b6
diff --git a/camel/extractors/python_strategies.py b/camel/extractors/python_strategies.pyindex 25f4531f7..895920597 100644--- a/camel/extractors/python_strategies.py+++ b/camel/extractors/python_strategies.py@@ -22,21 +22,30 @@ logger = get_logger(__name__)class BoxedStrategy(BaseExtractorStrategy):- r"""Extracts content from \\boxed{} environments."""+ r"""Extracts content from \\boxed{} and \boxed{} environments."""async def extract(self, text: str) -> Optional[str]:- r"""Extract content from \\boxed{} environments.+ r"""Extract content from \\boxed{} and \boxed{} environments.Args:text (str): The input text to process.Returns:- Optional[str]: Content inside \\boxed{} if found, else None.+ Optional[str]: Content inside \\boxed{} or \boxed{} if found, else+ None."""# Find the start of the boxed contentboxed_pattern = "\\boxed{"- if boxed_pattern not in text:- logger.debug("No \\boxed{} content found in the response")+ single_backslash_boxed_pattern = "\boxed{"++ if (+ boxed_pattern not in text+ and single_backslash_boxed_pattern not in text+ ):+ logger.debug(+ f"Patterns '{boxed_pattern}' or "+ f"'{single_backslash_boxed_pattern}' not found in text: {text}"+ )return Nonestart_idx = text.find(boxed_pattern) + len(boxed_pattern)diff --git a/test/extractors/test_python_strategies.py b/test/extractors/test_python_strategies.pyindex 8138cad61..c263b3559 100644--- a/test/extractors/test_python_strategies.py+++ b/test/extractors/test_python_strategies.py@@ -31,6 +31,16 @@ async def test_boxed_strategy():result = await strategy.extract(text)assert result == "test content"+ # Test not so basic boxed content+ text = r"\boxed{\dfrac{9}{7}}"+ result = await strategy.extract(text)+ assert result == r"\dfrac{9}{7}"++ # Test not so basic boxed content with double backslash+ text = r"\\boxed{\dfrac{9}{7}}"+ result = await strategy.extract(text)+ assert result == r"\dfrac{9}{7}"+# Test nested bracestext = r"\boxed{nested {braces} test}"result = await strategy.extract(text)