mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-28 06:22:33 +00:00
fix: file reading tools skip text when paging with line numbers on (#33155)
When a model reads a file or knowledge-base file in pages with line numbers turned on, the position it was told to continue from pointed past the end of the previous page, so a chunk of text between pages was silently skipped and never returned. The gap grew with every page, dropping a few percent of a large file. Reading now continues from the right place and returns every character exactly once; paging with line numbers off is unchanged. Fixes #33099
This commit is contained in:
parent
7f1b618727
commit
a01b36afe8
1 changed files with 8 additions and 6 deletions
|
|
@ -2909,7 +2909,8 @@ async def view_file(
|
|||
return JSONCodec.dumps(result, ensure_ascii=False)
|
||||
|
||||
sliced = content[offset : offset + max_chars]
|
||||
is_truncated = (offset + len(sliced)) < total_chars
|
||||
returned_chars = len(sliced)
|
||||
is_truncated = (offset + returned_chars) < total_chars
|
||||
|
||||
if line_numbers:
|
||||
start_ln = content[:offset].count('\n') + 1
|
||||
|
|
@ -2927,10 +2928,10 @@ async def view_file(
|
|||
if is_truncated or offset > 0:
|
||||
result['truncated'] = is_truncated
|
||||
result['total_chars'] = total_chars
|
||||
result['returned_chars'] = len(sliced)
|
||||
result['returned_chars'] = returned_chars
|
||||
result['offset'] = offset
|
||||
if is_truncated:
|
||||
result['next_offset'] = offset + len(sliced)
|
||||
result['next_offset'] = offset + returned_chars
|
||||
|
||||
return JSONCodec.dumps(result, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
|
|
@ -3052,7 +3053,8 @@ async def view_knowledge_file(
|
|||
return JSONCodec.dumps(result, ensure_ascii=False)
|
||||
|
||||
sliced = content[offset : offset + max_chars]
|
||||
is_truncated = (offset + len(sliced)) < total_chars
|
||||
returned_chars = len(sliced)
|
||||
is_truncated = (offset + returned_chars) < total_chars
|
||||
|
||||
if line_numbers:
|
||||
start_ln = content[:offset].count('\n') + 1
|
||||
|
|
@ -3073,10 +3075,10 @@ async def view_knowledge_file(
|
|||
if is_truncated or offset > 0:
|
||||
result['truncated'] = is_truncated
|
||||
result['total_chars'] = total_chars
|
||||
result['returned_chars'] = len(sliced)
|
||||
result['returned_chars'] = returned_chars
|
||||
result['offset'] = offset
|
||||
if is_truncated:
|
||||
result['next_offset'] = offset + len(sliced)
|
||||
result['next_offset'] = offset + returned_chars
|
||||
|
||||
return JSONCodec.dumps(result, ensure_ascii=False)
|
||||
except Exception as e:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue