fix: <think> tag

This commit is contained in:
Timothy Jaeryang Baek 2025-02-05 02:10:28 -08:00
parent 1ab66e83c6
commit c36c63f1e8

View File

@ -1233,6 +1233,16 @@ async def process_chat_response(
].replace(match.group(0), "") ].replace(match.group(0), "")
if not content_blocks[-1]["content"]: if not content_blocks[-1]["content"]:
content_blocks.pop() content_blocks.pop()
if not content_blocks:
# Append the new block
content_blocks.append(
{
"type": "text",
"content": "",
}
)
# Append the new block # Append the new block
content_blocks.append( content_blocks.append(
{ {
@ -1461,14 +1471,23 @@ async def process_chat_response(
log.debug("Error: ", e) log.debug("Error: ", e)
continue continue
# Clean up the last text block if content_blocks:
if content_blocks[-1]["type"] == "text": # Clean up the last text block
content_blocks[-1]["content"] = content_blocks[-1][ if content_blocks[-1]["type"] == "text":
"content" content_blocks[-1]["content"] = content_blocks[-1][
].strip() "content"
].strip()
if not content_blocks[-1]["content"]: if not content_blocks[-1]["content"]:
content_blocks.pop() content_blocks.pop()
if not content_blocks:
content_blocks.append(
{
"type": "text",
"content": "",
}
)
if response_tool_calls: if response_tool_calls:
tool_calls.append(response_tool_calls) tool_calls.append(response_tool_calls)