@@ -582,22 +582,25 @@ def postprocess_messages(
582
582
{
583
583
"role" : Role .SYSTEM ,
584
584
"content" : None ,
585
- "tools" : functions or [t [ " function"] for t in tools ]
585
+ "tools" : tools or [{ "type" : " function", "function" : f } for f in functions ]
586
586
}
587
587
)
588
588
589
589
for m in _messages :
590
590
role , content , func_call = m ["role" ], m ["content" ], m .get ("function_call" )
591
- if role == Role .FUNCTION :
591
+ if role in [ Role .FUNCTION , Role . TOOL ] :
592
592
messages .append (
593
593
{
594
594
"role" : "observation" ,
595
595
"content" : content
596
596
}
597
597
)
598
598
elif role == "assistant" and func_call is not None :
599
- for response in content .split ("" ):
600
- metadata , sub_content = response .split ("\n " , maxsplit = 1 )
599
+ for response in content .split ("<|assistant|>" ):
600
+ if "\n " in response :
601
+ metadata , sub_content = response .split ("\n " , maxsplit = 1 )
602
+ else :
603
+ metadata , sub_content = "" , response
601
604
messages .append (
602
605
{
603
606
"role" : role ,
@@ -620,7 +623,7 @@ def parse_assistant_response(
620
623
tools : Optional [List [Dict [str , Any ]]] = None ,
621
624
) -> Tuple [str , Optional [Union [str , Dict [str , Any ]]]]:
622
625
content = ""
623
- for response in output .split ("" ):
626
+ for response in output .split ("<|assistant|> " ):
624
627
if "\n " in response :
625
628
metadata , content = response .split ("\n " , maxsplit = 1 )
626
629
else :
@@ -630,8 +633,7 @@ def parse_assistant_response(
630
633
content = content .strip ()
631
634
else :
632
635
if functions or tools :
633
- content = "\n " .join (content .split ("\n " )[1 :- 1 ])
634
- parameters = eval (content )
636
+ parameters = eval (content .strip ())
635
637
if functions :
636
638
content = {
637
639
"name" : metadata .strip (),
0 commit comments