Skip to content

Commit ebb5b92

Browse files
refactor action string parsing to support python 3.11
1 parent f6060c2 commit ebb5b92

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/agentlab/llm/response_api.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,8 @@ def _parse_response(self, response: dict) -> dict:
358358
for output in response.output:
359359
if output.type == "function_call":
360360
arguments = json.loads(output.arguments)
361-
result.action = (
362-
# f"{output.name}({", ".join([f"{k}={v}" for k, v in arguments.items()])})"
363-
f"{output.name}({', '.join([f'{k}=\"{v}\"' if isinstance(v, str) else f'{k}={v}' for k, v in arguments.items()])})"
364-
)
361+
func_args_str = ', '.join([f'{k}="{v}"' if isinstance(v, str) else f'{k}={v}' for k, v in arguments.items()])
362+
result.action = f"{output.name}({func_args_str})"
365363
result.tool_calls = output
366364
break
367365
elif output.type == "reasoning":
@@ -439,7 +437,8 @@ def _parse_response(self, response: openai.types.chat.ChatCompletion) -> LLMOutp
439437
for tool_call in tool_calls:
440438
function = tool_call["function"]
441439
arguments = json.loads(function["arguments"])
442-
output.action = f"{function['name']}({', '.join([f'{k}=\"{v}\"' if isinstance(v, str) else f'{k}={v}' for k, v in arguments.items()])})"
440+
func_args_str = ', '.join([f'{k}="{v}"' if isinstance(v, str) else f'{k}={v}' for k, v in arguments.items()])
441+
output.action = f"{function['name']}({func_args_str})"
443442
output.tool_calls = {
444443
"role": "assistant",
445444
"tool_calls": [message["tool_calls"][0]], # Use only the first tool call
@@ -574,7 +573,8 @@ def _parse_response(self, response: dict) -> dict:
574573
)
575574
for output in response.content:
576575
if output.type == "tool_use":
577-
result.action = f"{output.name}({', '.join([f'{k}=\"{v}\"' if isinstance(v, str) else f'{k}={v}' for k, v in output.input.items()])})"
576+
func_args_str = ', '.join([f'{k}="{v}"' if isinstance(v, str) else f'{k}={v}' for k, v in output.input.items()])
577+
result.action = f"{output.name}({func_args_str})"
578578
elif output.type == "text":
579579
result.think += output.text
580580
return result

0 commit comments

Comments
 (0)