Skip to content

Commit ab94468

Browse files
authored
Merge pull request open-webui#9387 from open-webui/dev
0.5.9
2 parents dc3b2f1 + 13c7d96 commit ab94468

File tree

4 files changed

+74
-22
lines changed

4 files changed

+74
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.9] - 2025-02-05
9+
10+
### Fixed
11+
12+
- **💡 "Think" Tag Display Issue**: Resolved a bug where the "Think" tag was not functioning correctly, ensuring proper visualization of the model's reasoning process before delivering responses.
13+
814
## [0.5.8] - 2025-02-05
915

1016
### Added

backend/open_webui/utils/middleware.py

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,10 @@ def extract_attributes(tag_content):
12311231
content_blocks[-1]["content"] = content_blocks[-1][
12321232
"content"
12331233
].replace(match.group(0), "")
1234+
12341235
if not content_blocks[-1]["content"]:
12351236
content_blocks.pop()
1237+
12361238
# Append the new block
12371239
content_blocks.append(
12381240
{
@@ -1248,18 +1250,34 @@ def extract_attributes(tag_content):
12481250
tag = content_blocks[-1]["tag"]
12491251
# Match end tag e.g., </tag>
12501252
end_tag_pattern = rf"</{tag}>"
1253+
12511254
if re.search(end_tag_pattern, content):
1255+
end_flag = True
1256+
12521257
block_content = content_blocks[-1]["content"]
12531258
# Strip start and end tags from the content
12541259
start_tag_pattern = rf"<{tag}(.*?)>"
12551260
block_content = re.sub(
12561261
start_tag_pattern, "", block_content
12571262
).strip()
1258-
block_content = re.sub(
1259-
end_tag_pattern, "", block_content
1260-
).strip()
1263+
1264+
end_tag_regex = re.compile(end_tag_pattern, re.DOTALL)
1265+
split_content = end_tag_regex.split(block_content, maxsplit=1)
1266+
1267+
# Content inside the tag
1268+
block_content = (
1269+
split_content[0].strip() if split_content else ""
1270+
)
1271+
1272+
# Leftover content (everything after `</tag>`)
1273+
leftover_content = (
1274+
split_content[1].strip() if len(split_content) > 1 else ""
1275+
)
1276+
1277+
print(f"block_content: {block_content}")
1278+
print(f"leftover_content: {leftover_content}")
1279+
12611280
if block_content:
1262-
end_flag = True
12631281
content_blocks[-1]["content"] = block_content
12641282
content_blocks[-1]["ended_at"] = time.time()
12651283
content_blocks[-1]["duration"] = int(
@@ -1270,19 +1288,29 @@ def extract_attributes(tag_content):
12701288
content_blocks.append(
12711289
{
12721290
"type": "text",
1273-
"content": "",
1291+
"content": leftover_content,
12741292
}
12751293
)
1276-
# Clean processed content
1277-
content = re.sub(
1278-
rf"<{tag}(.*?)>(.|\n)*?</{tag}>",
1279-
"",
1280-
content,
1281-
flags=re.DOTALL,
1282-
)
12831294
else:
12841295
# Remove the block if content is empty
12851296
content_blocks.pop()
1297+
1298+
if leftover_content:
1299+
content_blocks.append(
1300+
{
1301+
"type": "text",
1302+
"content": leftover_content,
1303+
}
1304+
)
1305+
1306+
# Clean processed content
1307+
content = re.sub(
1308+
rf"<{tag}(.*?)>(.|\n)*?</{tag}>",
1309+
"",
1310+
content,
1311+
flags=re.DOTALL,
1312+
)
1313+
12861314
return content, content_blocks, end_flag
12871315

12881316
message = Chats.get_message_by_id_and_message_id(
@@ -1402,6 +1430,15 @@ async def stream_body_handler(response):
14021430

14031431
if value:
14041432
content = f"{content}{value}"
1433+
1434+
if not content_blocks:
1435+
content_blocks.append(
1436+
{
1437+
"type": "text",
1438+
"content": "",
1439+
}
1440+
)
1441+
14051442
content_blocks[-1]["content"] = (
14061443
content_blocks[-1]["content"] + value
14071444
)
@@ -1461,14 +1498,23 @@ async def stream_body_handler(response):
14611498
log.debug("Error: ", e)
14621499
continue
14631500

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()
1501+
if content_blocks:
1502+
# Clean up the last text block
1503+
if content_blocks[-1]["type"] == "text":
1504+
content_blocks[-1]["content"] = content_blocks[-1][
1505+
"content"
1506+
].strip()
14691507

1470-
if not content_blocks[-1]["content"]:
1471-
content_blocks.pop()
1508+
if not content_blocks[-1]["content"]:
1509+
content_blocks.pop()
1510+
1511+
if not content_blocks:
1512+
content_blocks.append(
1513+
{
1514+
"type": "text",
1515+
"content": "",
1516+
}
1517+
)
14721518

14731519
if response_tool_calls:
14741520
tool_calls.append(response_tool_calls)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "open-webui",
3-
"version": "0.5.8",
3+
"version": "0.5.9",
44
"private": true,
55
"scripts": {
66
"dev": "npm run pyodide:fetch && vite dev --host",

0 commit comments

Comments
 (0)