PhD With Me 🔬

New post

Crew AI & Ollama Project Setup Guide

This guide will walk you through setting up a Crew AI project with an Ollama model, integrating a PDF as a Knowledge Base for Retrieval Augmented Generation (RAG), and configuring Agent Ops for monitoring.


1. Set Up Your Project Folder

cd /path/to/our_project_folder

2. Create and Activate a Python Virtual Environment
Create a virtual environment and activate it:

python -m venv .venv source .venv/bin/activate

3. Install and Verify Crew AI CLI

Install the Crew AI CLI and verify its installation:

pip install crewai crewai --version

4. Scaffold a New Crew AI Project

Create a new Crew AI project and open it:

crewai create crew cd rag_assistant code .

5. Explore the Project Structure

Review configuration: Check the Source/config folder. Agents Configuration: Typically, two agents are configured (researcher and analyst). Default Topic: Defined in the run function. 6. Switch the LLM Model (Optional) Pull a new model using Ollama:

ollama pull <model_ID>

## 7. Integrate a PDF as a Knowledge Base for RAG
Add the PDF: Place your PDF file into the project's knowledge folder.
Configure the PDF Search tool:
Point to the PDF.
Configure the embeddings model as needed.

8. Customize Agent Prompts
Update agent prompt configurations in the appropriate config files to tailor the behavior of your agents.

9. Test the Crew AI Application
Run the application to test its functionality:

crewai run

  1. Set Up Agent Ops for Monitoring Sign Up: Create an account at app.agentops. Copy your API key. Set the environment variable:
export AGENT_OPSCORE_API_KEY=<your_api_key>
Install Agent Ops:

pip install agent-ops Initialize Agent Ops in your main script: python Copy import os import agent_ops

agent_ops.initialize() 11. Final Test Run the application one more time to ensure everything is set up correctly:

crewai run How to Use Your RAG Application Customize Content Update PDF: Replace or update the PDF in the knowledge folder. Adjust Prompts: Modify agent prompt configurations as needed. Download/Update LLM Model Pull the latest or required LLM model with Ollama:

bash Copy ollama pull Activate Virtual Environment Before running your application, ensure the virtual environment is active:

bash Copy source .venv/bin/activate Run Application Start the application with:

crewai run Monitor and Debug Console Output: Monitor the console for logs and errors. Adjust Configurations: Tweak settings as necessary. Iterate: Continue customizing and testing until you achieve the desired setup