Repository navigation
fix(tools): keep Chinese and Japanese lines in load_web_page - #7957
Open
Fruiterer333 wants to merge 2 commits into
Open
Fruiterer333 wants to merge 2 commits into
Fruiterer333 wants to merge 2 commits into
Conversation
mangeshraut712
left a comment
There was a problem hiding this comment.
Very thoughtful fix for #7956.
A few positive observations from inspecting the logic:
- Fast path: tokens without unspaced scripts take the early
if not any(...)return, preserving identical behavior and performance for whitespace-delimited languages. - Mixed token boundary handling: in strings like
2024款Model Y, the Latin/digit runs are correctly separated from the ideographs, and purely punctuation runs (such as。) do not trigger word increments because ofany(c.isalnum() for c in run). - Script scope: keeping Korean (Hangul) on whitespace-delimited counting while including Thai, Lao, Myanmar, Khmer, Kana, and CJK ideographs matches real-world typographic word boundary conventions.
- The test coverage validates both pure and mixed text lines against the
> 3threshold.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
load_web_pagekeeps only lines with more than three words and counted words withlen(line.split()). Chinese and Japanese text has no spaces between words, so every line counted as one word, and a Chinese or Japanese page came back as an empty string.Solution:
Lines are now measured with
_count_words. Whitespace-separated tokens count as before. In a script written without spaces (Han, Hiragana, Katakana, Thai, Lao, Khmer, Myanmar), each letter counts as a word, and the text between those letters counts only if it holds a letter or a digit, so a full stop such as "。" is not a word. Word counts for space-separated text are unchanged.One trade-off: counting by character keeps a short Chinese label of four or more characters, such as "关于我们" ("About us"), while its two-word English equivalent is still dropped. Character-level counting matches how
final_response_match_v1tokenizes these scripts.Testing Plan
Unit Tests:
Added
test_load_web_page_keeps_lines_of_scripts_written_without_spaces(Chinese and Japanese pages; both fail onmainwith an empty result) andtest_count_words_counts_each_letter_of_an_unspaced_script.Manual End-to-End (E2E) Tests:
Ran the reproduction script from #7956, which feeds the same page in three languages through
load_web_page:Checklist
Additional context
I used Claude Code to help find the issue and draft the change; I reproduced the bug and verified the fix and tests locally.