-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_code_splitting.py
More file actions
38 lines (29 loc) · 955 Bytes
/
python_code_splitting.py
File metadata and controls
38 lines (29 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from langchain.text_splitter import RecursiveCharacterTextSplitter,Language
text=""" class Student:
def __init__(self, first, last, age, major):
self.first = first
self.last = last
self.age = age
self.major = major
self.courses = []
def profile(self):
print(f"Student name: {self.first} {self.last}")
print(f"Student age: {self.age}")
print(f"Major: {self.major}")
def enrol(self, course):
self.courses.append(course)
print(f"Enrolled {self.first} in {course}")
def show_courses(self):
print(f"{self.first} {self.last} is taking the following courses:")
for course in self.courses:
print(course)
"""
splitter = RecursiveCharacterTextSplitter.from_language(
language=Language.PYTHON,
chunk_size=500,
chunk_overlap=0
)
chunks = splitter.split_text(text)
print(len(chunks))
print(chunks[1])
print