@@ -358,7 +358,12 @@ 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- func_args_str = ', ' .join ([f'{ k } ="{ v } "' if isinstance (v , str ) else f'{ k } ={ v } ' for k , v in arguments .items ()])
361+ func_args_str = ", " .join (
362+ [
363+ f'{ k } ="{ v } "' if isinstance (v , str ) else f"{ k } ={ v } "
364+ for k , v in arguments .items ()
365+ ]
366+ )
362367 result .action = f"{ output .name } ({ func_args_str } )"
363368 result .tool_calls = output
364369 break
@@ -437,7 +442,12 @@ def _parse_response(self, response: openai.types.chat.ChatCompletion) -> LLMOutp
437442 for tool_call in tool_calls :
438443 function = tool_call ["function" ]
439444 arguments = json .loads (function ["arguments" ])
440- func_args_str = ', ' .join ([f'{ k } ="{ v } "' if isinstance (v , str ) else f'{ k } ={ v } ' for k , v in arguments .items ()])
445+ func_args_str = ", " .join (
446+ [
447+ f'{ k } ="{ v } "' if isinstance (v , str ) else f"{ k } ={ v } "
448+ for k , v in arguments .items ()
449+ ]
450+ )
441451 output .action = f"{ function ['name' ]} ({ func_args_str } )"
442452 output .tool_calls = {
443453 "role" : "assistant" ,
@@ -449,9 +459,16 @@ def _parse_response(self, response: openai.types.chat.ChatCompletion) -> LLMOutp
449459 @staticmethod
450460 def format_tools_for_chat_completion (tools ):
451461 """Formats response tools format for OpenAI Chat Completion API.
462+
452463 Why we need this?
453464 Ans: actionset.to_tool_description() in bgym only returns description
454465 format valid for OpenAI Response API.
466+
467+ Args:
468+ tools: List of tool descriptions to format for Chat Completion API.
469+
470+ Returns:
471+ Formatted tools list compatible with OpenAI Chat Completion API, or None if tools is None.
455472 """
456473 formatted_tools = None
457474 if tools is not None :
@@ -467,7 +484,17 @@ def format_tools_for_chat_completion(tools):
467484 @staticmethod
468485 def extract_content_with_reasoning (message , wrap_tag = "think" ):
469486 """Extracts the content from the message, including reasoning if available.
470- It wraps the reasoning around <think>...</think> for backward compatibility."""
487+ It wraps the reasoning around <think>...</think> for easy identification of reasoning content,
488+ When LLM produces 'text' and 'reasoning' in the same message.
489+ Note: The wrapping of 'thinking' content may not be nedeed and may be reconsidered.
490+
491+ Args:
492+ message: The message object or dict containing content and reasoning.
493+ wrap_tag: The tag name to wrap reasoning content (default: "think").
494+
495+ Returns:
496+ str: The extracted content with reasoning wrapped in specified tags.
497+ """
471498 if not isinstance (message , dict ):
472499 message = message .to_dict ()
473500
@@ -573,7 +600,12 @@ def _parse_response(self, response: dict) -> dict:
573600 )
574601 for output in response .content :
575602 if output .type == "tool_use" :
576- func_args_str = ', ' .join ([f'{ k } ="{ v } "' if isinstance (v , str ) else f'{ k } ={ v } ' for k , v in output .input .items ()])
603+ func_args_str = ", " .join (
604+ [
605+ f'{ k } ="{ v } "' if isinstance (v , str ) else f"{ k } ={ v } "
606+ for k , v in output .input .items ()
607+ ]
608+ )
577609 result .action = f"{ output .name } ({ func_args_str } )"
578610 elif output .type == "text" :
579611 result .think += output .text
0 commit comments