mirror of
https://github.com/langchain-ai/langchain.git
synced 2026-10-09 11:25:21 +03:00
adds support for keeping separators around when using recursive text splitter
2.7 KiB
2.7 KiB
In [1]:
from langchain.text_splitter import PythonCodeTextSplitterIn [2]:
python_text = """
class Foo:
def bar():
def foo():
def testing_func_with_long_name():
def bar():
"""
python_splitter = PythonCodeTextSplitter(chunk_size=40, chunk_overlap=0)In [3]:
docs = python_splitter.create_documents([python_text])In [4]:
docsOut [4]:
[Document(page_content='class Foo:\n\n def bar():', metadata={}),
Document(page_content='def foo():', metadata={}),
Document(page_content='def testing_func_with_long_name():', metadata={}),
Document(page_content='def bar():', metadata={})]In [ ]: