@@ -41,7 +41,11 @@ def process_response(response):
41
41
def process_response_v3 (output : str , use_tool : bool = False ) -> Union [str , dict ]:
42
42
content = ""
43
43
for response in output .split ("<|assistant|>" ):
44
- metadata , content = response .split ("\n " , maxsplit = 1 )
44
+ if "\n " in response :
45
+ metadata , content = response .split ("\n " , maxsplit = 1 )
46
+ else :
47
+ metadata , content = "" , response
48
+
45
49
if not metadata .strip ():
46
50
content = content .strip ()
47
51
content = content .replace ("[[训练时间]]" , "2023年" )
@@ -241,12 +245,14 @@ def process_chatglm_messages(messages: List[ChatCompletionMessageParam], functio
241
245
242
246
for m in _messages :
243
247
role , content = m ["role" ], m ["content" ]
244
- func_call = m .get ("function_call" , None )
245
248
if role == Role .FUNCTION :
246
249
messages .append ({"role" : "observation" , "content" : content })
247
- elif role == Role .ASSISTANT and func_call is not None :
250
+ elif role == Role .ASSISTANT :
248
251
for response in content .split ("<|assistant|>" ):
249
- metadata , sub_content = response .split ("\n " , maxsplit = 1 )
252
+ if "\n " in response :
253
+ metadata , sub_content = response .split ("\n " , maxsplit = 1 )
254
+ else :
255
+ metadata , sub_content = "" , response
250
256
messages .append ({"role" : role , "metadata" : metadata , "content" : sub_content .strip ()})
251
257
else :
252
258
messages .append ({"role" : role , "content" : content })
0 commit comments