Create AI Agents that work with your PDFs using Chunkr & Mistral AI
You can also check this cookbook in colab hereIn this blog, we’ll introduce Chunkr, a cutting-edge document processing API designed for seamless and scalable data extraction and preparation, ideal for Retrieval-Augmented Generation (RAG) workflows and large language models (LLMs). Chunkr has been integrated with CAMEL. We’ll explore its three core capabilities—Segment, OCR, and Structure—each optimized to enhance document understanding and make data integration effortless. Finally, we’ll wrap up with a conclusion and a call to action.Key tools utilized in this notebook include:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
Chunkr: A powerful document processing API built for efficient and scalable data extraction and preparation, perfect for Retrieval-Augmented Generation (RAG) workflows and large language models (LLMs).
Chunkr is a versatile API designed to revolutionize how documents are processed and made ready for advanced AI applications like RAG and LLMs. From extracting text to structuring complex layouts, Chunkr simplifies the workflow of transforming raw documents into actionable data.
Once logged in, navigate to the API section of your account dashboard to find your API key. A new API key will be generated. Copy this key and store it securely.
Copy
import osfrom getpass import getpass# Prompt for the Chunkr API key securelychunkr_api_key = getpass('Enter your API key: ')os.environ["CHUNKR_API_KEY"] = chunkr_api_key
Alternatively, if running on Colab, you could save your API keys and tokens as Colab Secrets, and use them across notebooks.To do so, comment out the above manual API key prompt code block(s), and uncomment the following codeblock.⚠️ Don’t forget granting access to the API key you would be using to the current notebook.
Copy
# import os# from google.colab import userdata# os.environ["CHUNKR_API_KEY"] = userdata.get("CHUNKR_API_KEY")
# Importing the ChunkrReader class from the camel.loaders module# This class handles document processing using Chunkr's capabilitiesfrom camel.loaders import ChunkrReaderimport nest_asyncionest_asyncio.apply() # Initializing an instance of ChunkrReader# This object will be used to submit tasks and manage document processingchunkr_reader = ChunkrReader()# Submitting a document processing task# Replace "local_data/example.pdf" with the path to your target documentawait chunkr_reader.submit_task(file_path="local_data/camel_paper.pdf")
Step 4: Input the task id above and then we can obtain the task output.The output of Chunkr is structured text and metadata from documents, including:
Formatted Content: Text in structured formats like JSON, HTML, or Markdown.
Semantic Tags: Identifies headers, paragraphs, tables, and other elements.
Bounding Box Data: Spatial positions of text (x, y coordinates) for OCR-processed documents.
Metadata: Information like page numbers, file type, and document properties.
Copy
# Retrieving the output of a previously submitted taskchunkr_output = await chunkr_reader.get_task_output(task_id="902e686a-d6f5-413d-8a8d-241a3f43d35b")print(chunkr_output)
Here we choose Mistral model for our demo. If you’d like to explore different models or tools to suit your needs, feel free to visit the CAMEL documentation page, where you’ll find guides and tutorials.If you don’t have a Mistral API key, you can obtain one by following these steps:
from camel.agents import ChatAgent# Initialize a ChatAgentagent = ChatAgent( system_message="You're a helpful assistant", # Define the agent's role or purpose message_window_size=10, # [Optional] Specifies the chat memory length model=model)# Use the ChatAgent to generate a response based on the chunkr outputresponse = agent.step(f"based on {chunkr_output[:4000]}, give me a conclusion of the content")# Print the content of the first message in the response, which contains the assistant's answerprint(response.msgs[0].content)
For advanced usage of RAG capabilities with large files, please refer to our RAG cookbook.
In conclusion, integrating Chunkr within CAMEL-AI revolutionizes the process of document data extraction and preparation, enhancing your capabilities for AI-driven applications. With Chunkr’s robust features like Segment, OCR, and Structure, you can seamlessly process complex documents into structured, machine-readable formats optimized for LLMs, directly feeding into CAMEL-AI’s multi-agent workflows. This integration not only simplifies data preparation but also empowers intelligent and accurate analytics. With these tools at your disposal, you’re equipped to transform raw document data into actionable insights, unlocking new possibilities in automation and AI-powered decision-making.Key tools utilized in this notebook include:
CAMEL: A powerful multi-agent framework that enables Retrieval-Augmented Generation and multi-agent role-playing scenarios, allowing for sophisticated AI-driven tasks.
Chunkr: An advanced document processing API built for efficient and scalable data extraction and preparation, perfect for Retrieval-Augmented Generation (RAG) workflows and large language models (LLMs).
That’s everything: Got questions about 🐫 CAMEL-AI? Join us on Discord! Whether you want to share feedback, explore the latest in multi-agent systems, get support, or connect with others on exciting projects, we’d love to have you in the community! 🤝Check out some of our other work: