matthoffner commited on
Commit
3fb7a02
Β·
1 Parent(s): 14baa02

Create overwrites.py

Browse files
Files changed (1) hide show
  1. overwrites.py +12 -0
overwrites.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from llama_index import Prompt
2
+ from typing import List
3
+ import logging
4
+
5
+ def compact_text_chunks(self, prompt: Prompt, text_chunks: List[str]) -> List[str]:
6
+ logging.debug("Compacting text chunks...πŸš€πŸš€πŸš€")
7
+ combined_str = [c.strip() for c in text_chunks if c.strip()]
8
+ combined_str = [f"[{index+1}] {c}" for index, c in enumerate(combined_str)]
9
+ combined_str = "\n\n".join(combined_str)
10
+ # resplit based on self.max_chunk_overlap
11
+ text_splitter = self.get_text_splitter_given_prompt(prompt, 1, padding=1)
12
+ return text_splitter.split_text(combined_str)