Skip to content

Commit c36c63f

Browse files
committed
fix: <think> tag
1 parent 1ab66e8 commit c36c63f

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

backend/open_webui/utils/middleware.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,16 @@ def extract_attributes(tag_content):
12331233
].replace(match.group(0), "")
12341234
if not content_blocks[-1]["content"]:
12351235
content_blocks.pop()
1236+
1237+
if not content_blocks:
1238+
# Append the new block
1239+
content_blocks.append(
1240+
{
1241+
"type": "text",
1242+
"content": "",
1243+
}
1244+
)
1245+
12361246
# Append the new block
12371247
content_blocks.append(
12381248
{
@@ -1461,14 +1471,23 @@ async def stream_body_handler(response):
14611471
log.debug("Error: ", e)
14621472
continue
14631473

1464-
# Clean up the last text block
1465-
if content_blocks[-1]["type"] == "text":
1466-
content_blocks[-1]["content"] = content_blocks[-1][
1467-
"content"
1468-
].strip()
1474+
if content_blocks:
1475+
# Clean up the last text block
1476+
if content_blocks[-1]["type"] == "text":
1477+
content_blocks[-1]["content"] = content_blocks[-1][
1478+
"content"
1479+
].strip()
1480+
1481+
if not content_blocks[-1]["content"]:
1482+
content_blocks.pop()
14691483

1470-
if not content_blocks[-1]["content"]:
1471-
content_blocks.pop()
1484+
if not content_blocks:
1485+
content_blocks.append(
1486+
{
1487+
"type": "text",
1488+
"content": "",
1489+
}
1490+
)
14721491

14731492
if response_tool_calls:
14741493
tool_calls.append(response_tool_calls)

0 commit comments

Comments
 (0)