mirror of
https://github.com/open-webui/open-webui
synced 2025-04-22 23:35:26 +00:00
refac
This commit is contained in:
parent
648878782b
commit
1e67956db9
@ -1205,7 +1205,7 @@ async def process_chat_response(
|
|||||||
block_content = str(block["content"]).strip()
|
block_content = str(block["content"]).strip()
|
||||||
content = f"{content}{block['type']}: {block_content}\n"
|
content = f"{content}{block['type']}: {block_content}\n"
|
||||||
|
|
||||||
return content
|
return content.strip()
|
||||||
|
|
||||||
def tag_content_handler(content_type, tags, content, content_blocks):
|
def tag_content_handler(content_type, tags, content, content_blocks):
|
||||||
end_flag = False
|
end_flag = False
|
||||||
@ -1234,11 +1234,22 @@ async def process_chat_response(
|
|||||||
attr_content
|
attr_content
|
||||||
) # Extract attributes safely
|
) # Extract attributes safely
|
||||||
|
|
||||||
|
# Capture everything before and after the matched tag
|
||||||
|
before_tag = content[
|
||||||
|
: match.start()
|
||||||
|
] # Content before opening tag
|
||||||
|
after_tag = content[
|
||||||
|
match.end() :
|
||||||
|
] # Content after opening tag
|
||||||
|
|
||||||
# Remove the start tag from the currently handling text block
|
# Remove the start tag from the currently handling text block
|
||||||
content_blocks[-1]["content"] = content_blocks[-1][
|
content_blocks[-1]["content"] = content_blocks[-1][
|
||||||
"content"
|
"content"
|
||||||
].replace(match.group(0), "")
|
].replace(match.group(0), "")
|
||||||
|
|
||||||
|
if before_tag:
|
||||||
|
content_blocks[-1]["content"] = before_tag
|
||||||
|
|
||||||
if not content_blocks[-1]["content"]:
|
if not content_blocks[-1]["content"]:
|
||||||
content_blocks.pop()
|
content_blocks.pop()
|
||||||
|
|
||||||
@ -1252,6 +1263,10 @@ async def process_chat_response(
|
|||||||
"started_at": time.time(),
|
"started_at": time.time(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if after_tag:
|
||||||
|
content_blocks[-1]["content"] = after_tag
|
||||||
|
|
||||||
break
|
break
|
||||||
elif content_blocks[-1]["type"] == content_type:
|
elif content_blocks[-1]["type"] == content_type:
|
||||||
tag = content_blocks[-1]["tag"]
|
tag = content_blocks[-1]["tag"]
|
||||||
@ -1289,7 +1304,11 @@ async def process_chat_response(
|
|||||||
content_blocks[-1]["ended_at"]
|
content_blocks[-1]["ended_at"]
|
||||||
- content_blocks[-1]["started_at"]
|
- content_blocks[-1]["started_at"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reset the content_blocks by appending a new text block
|
# Reset the content_blocks by appending a new text block
|
||||||
|
if content_type != "code_interpreter":
|
||||||
|
if leftover_content:
|
||||||
|
|
||||||
content_blocks.append(
|
content_blocks.append(
|
||||||
{
|
{
|
||||||
"type": "text",
|
"type": "text",
|
||||||
|
Loading…
Reference in New Issue
Block a user