test_trim_messages_allow_partial_text_splitter() — langchain Function Reference
Architecture documentation for the test_trim_messages_allow_partial_text_splitter() function in test_utils.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD abbaf0ba_da3b_e27e_1dd3_8fc3c9689801["test_trim_messages_allow_partial_text_splitter()"] ea3f8d89_f44b_6738_3cb9_a740a73cfca4["test_utils.py"] abbaf0ba_da3b_e27e_1dd3_8fc3c9689801 -->|defined in| ea3f8d89_f44b_6738_3cb9_a740a73cfca4 style abbaf0ba_da3b_e27e_1dd3_8fc3c9689801 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/messages/test_utils.py lines 467–497
def test_trim_messages_allow_partial_text_splitter() -> None:
expected = [
HumanMessage("a 4 token text.", id="third"),
AIMessage("This is a 4 token text.", id="fourth"),
]
def count_words(msgs: list[BaseMessage]) -> int:
count = 0
for msg in msgs:
if isinstance(msg.content, str):
count += len(msg.content.split(" "))
else:
count += len(
" ".join(block["text"] for block in msg.content).split(" ") # type: ignore[index]
)
return count
def _split_on_space(text: str) -> list[str]:
splits = text.split(" ")
return [s + " " for s in splits[:-1]] + splits[-1:]
actual = trim_messages(
_MESSAGES_TO_TRIM,
max_tokens=10,
token_counter=count_words,
strategy="last",
allow_partial=True,
text_splitter=_split_on_space,
)
assert actual == expected
assert _MESSAGES_TO_TRIM == _MESSAGES_TO_TRIM_COPY
Domain
Subdomains
Source
Frequently Asked Questions
What does test_trim_messages_allow_partial_text_splitter() do?
test_trim_messages_allow_partial_text_splitter() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/messages/test_utils.py.
Where is test_trim_messages_allow_partial_text_splitter() defined?
test_trim_messages_allow_partial_text_splitter() is defined in libs/core/tests/unit_tests/messages/test_utils.py at line 467.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free