处理 tool_call字符串
This commit is contained in:
parent
dd8d9f5680
commit
70dcffbb7a
@ -71,18 +71,20 @@ def get_content_from_messages(messages: List[dict], tool_response: bool = True)
|
||||
|
||||
# 匹配并替换不完整的 tool_call 模式
|
||||
content_text = re.sub(r'<t?o?o?l?_?c?a?l?l?$', '', content_text)
|
||||
|
||||
# 只有在处理后内容不为空时才添加
|
||||
if content_text.strip():
|
||||
content.append(f'{ANSWER_S}\n{content_text}')
|
||||
if msg.get('function_call'):
|
||||
content.append(f'{TOOL_CALL_S} {msg["function_call"]["name"]}\n{msg["function_call"]["arguments"]}')
|
||||
content_text = msg["function_call"]["arguments"]
|
||||
content_text = re.sub(r'}\n<\/?t?o?o?l?_?c?a?l?l?$', '', content_text)
|
||||
if content_text.strip():
|
||||
content.append(f'{TOOL_CALL_S} {msg["function_call"]["name"]}\n{content_text}')
|
||||
elif msg['role'] == FUNCTION:
|
||||
if tool_response:
|
||||
content.append(f'{TOOL_RESULT_S} {msg["name"]}\n{msg["content"]}')
|
||||
else:
|
||||
raise TypeError
|
||||
print(content)
|
||||
|
||||
if content:
|
||||
full_text = '\n'.join(content)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user