Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions gpt_oss/tools/simple_browser/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ def with_retries(
return func


def maybe_truncate(text: str, num_chars: int = 1024) -> str:
if len(text) > num_chars:
text = text[: (num_chars - 3)] + "..."
return text


@chz.chz(typecheck=True)
class Backend:
source: str = chz.field(doc="Description of the backend source")
Expand Down
6 changes: 5 additions & 1 deletion gpt_oss/tools/simple_browser/simple_browser_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
VIEW_SOURCE_PREFIX,
Backend,
BackendError,
maybe_truncate,
)
from .page_contents import Extract, PageContents

Expand Down Expand Up @@ -175,6 +174,11 @@ def wrap_lines(text: str, width: int = 80) -> list[str]:
return list(wrapped)


def maybe_truncate(text: str, num_chars: int = 1024) -> str:
"""Truncate ``text`` to at most ``num_chars`` characters."""
return text if len(text) <= num_chars else text[: num_chars - 3] + "..."


def strip_links(text: str) -> str:
text = re.sub(PARTIAL_INITIAL_LINK_PATTERN, "", text)
text = re.sub(PARTIAL_FINAL_LINK_PATTERN, lambda mo: mo.group("content"), text)
Expand Down