Create AI Agents that work with your PDFs using Chunkr, CAMEL-AI & Mistral AI
Step-by-step guide of digesting your PDFs within CAMEL framework
Step-by-step guide of digesting your PDFs within CAMEL framework
In 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.
1. 🧑🏻💻 Introduction
2. ⚡️ Step-by-step Guide of Digesting PDFs with Chunkr
3. 💫 Quick Demo with CAMEL Agent
4. 🧑🏻💻 Conclusion
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.
2. Advanced OCR (Optical Character Recognition) Capabilities:
3. Semantic Layout Analysis:
* Optimized for AI: Simplifies preparing data for LLMs and other AI models.
* Multi-Format Compatibility: Processes PDFs, DOCX, PPTX, XLSX, and more.
* Scalable Deployment: Use locally for small projects or deploy at scale with Kubernetes. Also, it is open-source!
In this blog, we will focus on the capability of digesting PDF file with Chunkr.
First, install the CAMEL package with all its dependencies.
pip install "camel-ai[all]==0.2.11"
Step 1: Set up your chunkr API key. If you don't have a chunkr API key, you can obtain one by following these steps:
import os
from getpass import getpass
# Prompt for the Chunkr API key securely
chunkr_api_key = getpass('Enter your API key: ')
os.environ["CHUNKR_API_KEY"] = chunkr_api_key
Step 2: Let's load the example PDF file from https://arxiv.org/pdf/2303.17760.pdf. This will be our local example data.
import os
import requests
os.makedirs('local_data', exist_ok=True)
url = "https://arxiv.org/pdf/2303.17760.pdf"
response = requests.get(url)
with open('local_data/camel_paper.pdf', 'wb') as file:
file.write(response.content)
Step 3: Sumbit one task.
# Importing the ChunkrReader class from the camel.loaders module
# This class handles document processing using Chunkr's capabilities
from camel.loaders import ChunkrReader
# Initializing an instance of ChunkrReader
# This object will be used to submit tasks and manage document processing
chunkr_reader = ChunkrReader()
# Submitting a document processing task
# Replace "local_data/example.pdf" with the path to your target document
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:
# Retrieving the output of a previously submitted task
# The "max_retries" parameter determines the number of times to retry if the task output is not immediately available
chunkr_output = chunkr_reader.get_task_output(task_id="902e686a-d6f5-413d-8a8d-241a3f43d35b", max_retries=10)
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:
For more details, you can also check the Mistral documentation: https://docs.mistral.ai/getting-started/quickstart/
import os
from getpass import getpass
mistral_api_key = getpass('Enter your API key')
os.environ["MISTRAL_API_KEY"] = mistral_api_key
from camel.configs import MistralConfig
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
mistral_model = ModelFactory.create(
model_platform=ModelPlatformType.MISTRAL,
model_type=ModelType.MISTRAL_LARGE,
model_config_dict=MistralConfig(temperature=0.0).as_dict(),
)
# Use Mistral model
model = mistral_model
from camel.agents import ChatAgent
# Initialize a ChatAgent
agent = 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 output
response = 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 answer
print(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.
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:
1. 🐫 Creating Your First CAMEL Agent free Colab.
2. Graph RAG Cookbook free Colab.
3. 🧑⚖️ Create A Hackathon Judge Committee with Workforce free Colab.
4. 🔥 3 ways to ingest data from websites with Firecrawl & CAMEL free colab.
5. 🦥 Agentic SFT Data Generation with CAMEL and Mistral Models, Fine-Tuned with Unsloth free Colab.
Thanks from everyone at 🐫 CAMEL-AI!