File size: 674 Bytes
c4e9c8e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def chunk_text_by_tokens(text, max_tokens=1300, approx_tokens_per_word=1.3):
    """
    Metni yaklaşık token sayısına göre parçalara böler.

    Args:
        text (str): Bölünecek uzun metin.
        max_tokens (int): Her bir parçanın tahmini token limiti.
        approx_tokens_per_word (float): Kelime başına ortalama token sayısı.

    Returns:
        List[str]: Token limitine uygun metin parçaları.
    """
    words = text.split()
    max_words = int(max_tokens / approx_tokens_per_word)

    chunks = []
    for i in range(0, len(words), max_words):
        chunk = " ".join(words[i:i + max_words])
        chunks.append(chunk)

    return chunks