Skip to content

Commit a9d177e

Browse files
authored
Remove unused function split_file from file_operations.py (Significant-Gravitas#4658)
1 parent ff46c16 commit a9d177e

File tree

2 files changed

+0
-69
lines changed

2 files changed

+0
-69
lines changed

autogpt/commands/file_operations.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,6 @@ def log_operation(
119119
)
120120

121121

122-
def split_file(
123-
content: str, max_length: int = 4000, overlap: int = 0
124-
) -> Generator[str, None, None]:
125-
"""
126-
Split text into chunks of a specified maximum length with a specified overlap
127-
between chunks.
128-
129-
:param content: The input text to be split into chunks
130-
:param max_length: The maximum length of each chunk,
131-
default is 4000 (about 1k token)
132-
:param overlap: The number of overlapping characters between chunks,
133-
default is no overlap
134-
:return: A generator yielding chunks of text
135-
"""
136-
start = 0
137-
content_length = len(content)
138-
139-
while start < content_length:
140-
end = start + max_length
141-
if end + overlap < content_length:
142-
chunk = content[start : end + max(overlap - 1, 0)]
143-
else:
144-
chunk = content[start:content_length]
145-
146-
# Account for the case where the last chunk is shorter than the overlap, so it has already been consumed
147-
if len(chunk) <= overlap:
148-
break
149-
150-
yield chunk
151-
start += max_length - overlap
152-
153-
154122
@command("read_file", "Read a file", '"filename": "<filename>"')
155123
def read_file(filename: str, agent: Agent) -> str:
156124
"""Read a file and return the contents

tests/unit/test_file_operations.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -188,43 +188,6 @@ def test_log_operation_with_checksum(agent: Agent):
188188
assert f"log_test: path/to/test #ABCDEF\n" in content
189189

190190

191-
@pytest.mark.parametrize(
192-
"max_length, overlap, content, expected",
193-
[
194-
(
195-
4,
196-
1,
197-
"abcdefghij",
198-
["abcd", "defg", "ghij"],
199-
),
200-
(
201-
4,
202-
0,
203-
"abcdefghijkl",
204-
["abcd", "efgh", "ijkl"],
205-
),
206-
(
207-
4,
208-
0,
209-
"abcdefghijklm",
210-
["abcd", "efgh", "ijkl", "m"],
211-
),
212-
(
213-
4,
214-
0,
215-
"abcdefghijk",
216-
["abcd", "efgh", "ijk"],
217-
),
218-
],
219-
)
220-
# Test splitting a file into chunks
221-
def test_split_file(max_length, overlap, content, expected):
222-
assert (
223-
list(file_ops.split_file(content, max_length=max_length, overlap=overlap))
224-
== expected
225-
)
226-
227-
228191
def test_read_file(
229192
mock_MemoryItem_from_text,
230193
test_file_with_content_path: Path,

0 commit comments

Comments
 (0)