mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
fix: chat read limit failing on chats with empty or non-text messages
With a chat read limit set, reading an imported chat that held empty or non-text message content ended in an error instead of the chat. Such content is now counted and cut as plain text.
This commit is contained in:
parent
4e21ddc8d8
commit
e288cdc470
1 changed files with 2 additions and 2 deletions
|
|
@ -1752,13 +1752,13 @@ async def view_chat(
|
|||
|
||||
truncation = {}
|
||||
max_chars = await Config.get('chats.view_max_chars')
|
||||
if max_chars and sum(len(message['content']) for message in messages) > max_chars:
|
||||
if max_chars and sum(len(str(message['content'] or '')) for message in messages) > max_chars:
|
||||
remaining_chars = max_chars
|
||||
kept_messages = []
|
||||
for message in messages:
|
||||
if remaining_chars <= 0:
|
||||
break
|
||||
content = message['content'][:remaining_chars]
|
||||
content = str(message['content'] or '')[:remaining_chars]
|
||||
kept_messages.append({**message, 'content': content})
|
||||
remaining_chars -= len(content)
|
||||
truncation = {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue