Skip to content

Commit 2973b3b

Browse files
committed
[bugfix] fix rstrip (#5519)
1 parent 84a438f commit 2973b3b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

swift/llm/template/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,7 @@ def _swift_prepare_inputs(self, inputs):
10581058
i += 1
10591059
pre_message['content'], tool_content = self.agent_template._format_tool_responses(
10601060
pre_content, messages[i_start:i + 1])
1061+
# where tool_content is a List.
10611062
messages[i_start:i + 1] = [{'role': 'tool', 'content': tool_content}]
10621063
i = i_start + 1
10631064
elif pre_role == 'assistant' and role == 'assistant' or pre_role == 'user' and role == 'user':

swift/llm/template/template/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def _swift_prepare_inputs(self, inputs):
4545
# Delete the content before '</think>' in all assistant turns except the last round.
4646
if message['role'] == 'assistant' and isinstance(message['content'], str) and i != len(messages) - 1:
4747
if self.with_answer:
48-
message['content'] = message['content'].split('<answer>')[-1].rstrip().rstrip(
49-
'</answer>').strip()
48+
message['content'] = message['content'].split('<answer>')[-1].rstrip()
49+
if message['content'].endswith('</answer>'):
50+
message['content'] = message['content'][:-len('</answer>')]
51+
message['content'] = message['content'].strip()
5052
else:
5153
message['content'] = message['content'].split('</think>')[-1].strip()
5254

0 commit comments

Comments
 (0)