Dr.Yasuda_streamlit / utils /chunking.py
Blue2962
a
1fd68ae
raw
history blame contribute delete
372 Bytes
def chunk_text(text: str, max_length: int = 1000):
chunks = []
while len(text) > max_length:
split_pos = text.rfind("。", 0, max_length)
if split_pos == -1:
split_pos = max_length
chunks.append(text[:split_pos + 1].strip())
text = text[split_pos + 1:]
if text:
chunks.append(text.strip())
return chunks