autogen/website/docs/topics/handling_long_contexts/compressing_text_w_llmligua.md
Example 1: Compressing AutoGen Research Paper using LLMLingua  We will look at how we can use `TextMessageCompressor` to compress an AutoGen research paper using `LLMLingua`. Here's how you can initialize `TextMessageCompressor` with LLMLingua, a text compressor that adheres to the `TextCompressor` protocol.  ```python import tempfile  import fitz  # PyMuPDF import requests  from autogen.agentchat.contrib.capabilities.text_compressors import LLMLingua from autogen.agentchat.contrib.capabilities.transforms import TextMessageCompressor  AUTOGEN_PAPER = "https://arxiv.org/pdf/2308.08155"   def extract_text_from_pdf():     # Download the PDF     response = requests.get(AUTOGEN_PAPER)     response.raise_for_status()  # Ensure the download was successful      text = ""     # Save the PDF to a temporary file     with tempfile.TemporaryDirectory() as temp_dir:         with open(temp_dir + "temp.pdf", "wb") as f:             f.write(response.content)          # Open the PDF         with fitz.open(temp_dir + "temp.pdf") as doc:             # Read and extract text from each page             for page in doc:                 text += page.get_text()      return text   # Example usage pdf_text = extract_text_from_pdf()  llm_lingua = LLMLingua() text_compressor = TextMessageCompressor(text_compressor=llm_lingua) compressed_text = text_compressor.apply_transform([{"content": pdf_text}])  print(text_compressor.get_logs([], [])) ```  ```console ('19765 tokens saved with text compression.', True) ``` 