From 35f7efb9d74fadadbb30c293ed105d28ab531644 Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Wed, 28 May 2025 04:24:00 +0800 Subject: [PATCH] Fix: Remove strip() from parameter value extraction to preserve indentation (#8739) Co-authored-by: openhands --- openhands/llm/fn_call_converter.py | 2 +- tests/unit/test_llm_fncall_converter.py | 28 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/openhands/llm/fn_call_converter.py b/openhands/llm/fn_call_converter.py index 09079d4d76..0218107ca6 100644 --- a/openhands/llm/fn_call_converter.py +++ b/openhands/llm/fn_call_converter.py @@ -582,7 +582,7 @@ def _extract_and_validate_params( found_params = set() for param_match in param_matches: param_name = param_match.group(1) - param_value = param_match.group(2).strip() + param_value = param_match.group(2) # Validate parameter is allowed if allowed_params and param_name not in allowed_params: diff --git a/tests/unit/test_llm_fncall_converter.py b/tests/unit/test_llm_fncall_converter.py index 7d3694086b..5bfc14b91e 100644 --- a/tests/unit/test_llm_fncall_converter.py +++ b/tests/unit/test_llm_fncall_converter.py @@ -652,6 +652,34 @@ NON_FNCALL_RESPONSE_MESSAGE = { view /test/file.py [1, 10] +""", + ), + # Test case with indented code block to verify indentation is preserved + ( + [ + { + 'index': 1, + 'function': { + 'arguments': '{"command": "str_replace", "path": "/test/file.py", "old_str": "def example():\\n pass", "new_str": "def example():\\n # This is indented\\n print(\\"hello\\")\\n return True"}', + 'name': 'str_replace_editor', + }, + 'id': 'test_id', + 'type': 'function', + } + ], + """ +str_replace +/test/file.py + +def example(): + pass + + +def example(): + # This is indented + print("hello") + return True + """, ), ],