Skip to content

The agent engineering platform.

speed up enforce_stop_tokens helper function (#10984)

Tomáš Dvořák865a21938c0e
diff --git a/libs/langchain/langchain/llms/utils.py b/libs/langchain/langchain/llms/utils.py
index 32fdb52eb3..b69c759eea 100644
--- a/libs/langchain/langchain/llms/utils.py
+++ b/libs/langchain/langchain/llms/utils.py
@@ -5,4 +5,4 @@ from typing import List
def enforce_stop_tokens(text: str, stop: List[str]) -> str:
"""Cut off the text as soon as any stop words occur."""
- return re.split("|".join(stop), text)[0]
+ return re.split("|".join(stop), text, maxsplit=1)[0]