mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Add JSON serialization for array and object parameters when converting tools (#8780)
This commit is contained in:
parent
73f01657eb
commit
b634e10b45
@ -426,7 +426,10 @@ def convert_tool_call_to_string(tool_call: dict) -> str:
|
||||
ret += f'<parameter={param_name}>'
|
||||
if is_multiline:
|
||||
ret += '\n'
|
||||
ret += f'{param_value}'
|
||||
if isinstance(param_value, list) or isinstance(param_value, dict):
|
||||
ret += json.dumps(param_value)
|
||||
else:
|
||||
ret += f'{param_value}'
|
||||
if is_multiline:
|
||||
ret += '\n'
|
||||
ret += '</parameter>\n'
|
||||
|
||||
@ -680,6 +680,44 @@ def example():
|
||||
print("hello")
|
||||
return True
|
||||
</parameter>
|
||||
</function>""",
|
||||
),
|
||||
# Test case with list parameter value
|
||||
(
|
||||
[
|
||||
{
|
||||
'index': 1,
|
||||
'function': {
|
||||
'arguments': '{"command": "test", "path": "/test/file.py", "tags": ["tag1", "tag2", "tag with spaces"]}',
|
||||
'name': 'test_function',
|
||||
},
|
||||
'id': 'test_id',
|
||||
'type': 'function',
|
||||
}
|
||||
],
|
||||
"""<function=test_function>
|
||||
<parameter=command>test</parameter>
|
||||
<parameter=path>/test/file.py</parameter>
|
||||
<parameter=tags>["tag1", "tag2", "tag with spaces"]</parameter>
|
||||
</function>""",
|
||||
),
|
||||
# Test case with dict parameter value
|
||||
(
|
||||
[
|
||||
{
|
||||
'index': 1,
|
||||
'function': {
|
||||
'arguments': '{"command": "test", "path": "/test/file.py", "metadata": {"key1": "value1", "key2": 42, "nested": {"subkey": "subvalue"}}}',
|
||||
'name': 'test_function',
|
||||
},
|
||||
'id': 'test_id',
|
||||
'type': 'function',
|
||||
}
|
||||
],
|
||||
"""<function=test_function>
|
||||
<parameter=command>test</parameter>
|
||||
<parameter=path>/test/file.py</parameter>
|
||||
<parameter=metadata>{"key1": "value1", "key2": 42, "nested": {"subkey": "subvalue"}}</parameter>
|
||||
</function>""",
|
||||
),
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user