Skip to content

Commit 513d7fe

Browse files
Copilotdvejsada
andcommitted
Include truncation notice in length calculation to stay within max_length
Co-authored-by: dvejsada <95045003+dvejsada@users.noreply.github.com>
1 parent 625dc7b commit 513d7fe

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

search/serper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ async def extract_page_content(url: str) -> str:
281281
# Truncate content if it exceeds the configured maximum length
282282
max_length = config.MAX_CONTENT_LENGTH
283283
if max_length > 0 and len(result) > max_length:
284-
result = result[:max_length] + "\n\n[Content truncated - extracted text exceeded the maximum allowed length]"
284+
truncation_notice = "\n\n[Content truncated - extracted text exceeded the maximum allowed length]"
285+
result = result[:max_length - len(truncation_notice)] + truncation_notice
285286

286287
return result
287288

0 commit comments

Comments
 (0)