🤖

Building AI Agents with Llama 3

Jul 10, 2024

Building AI Agents with Llama 3

Introduction

  • Presenter: David Andre
  • Focus: Building AI agents using Llama 3 model, even with low-end hardware and no programming knowledge.
  • Tools Used: AMA, VS Code, Gro for performance.

Tools and Setup

AMA

  • Purpose: Run models locally.
  • Download: Go to ama.com and download.

VS Code

  • Purpose: Write the code.
  • Download: Go to code.visualstudio.com and download.

Llama 3 Model

  • Recommendations: Use the 8 billion model for a good balance of performance and capability.
  • Download Command: Copy the command from the Llama site and use it in the terminal within VS Code.
  • Model Size: Smaller model (4.7 GB) takes ~20 mins to download; larger (40 GB) takes ~3 hours.
  • Tip: Use SL bu to end the terminal session without killing it.

Running the Models

  • Initial Setup: Download the model once before using it.
  • Chat with LLM: Basic functionality, can be run locally in the terminal.

Building AI Agents

Project Setup

  • File Creation: Create a new file in VS Code named main.py.
  • Import Libraries: Import necessary libraries from Lang Chain Community and Crew AI. from lang_chain_community.llms import Llama from crew_ai import Agent, Task, Crew, Process
  • Installation: pip install crew_ai to get necessary packages.

Define the Model

  • Model Name: Use Llama 3 or specify the version like Llama 3 8B.
  • Agent Definition:
    • Agent 1: Classifier
      • Role: Email classifier.
      • Goal: Accurately classify emails (important, casual, spam).
      • Settings: verbose=True, allow_delegation=False, assign the LLM model.
    • Agent 2: Responder
      • Role: Email responder.
      • Goal: Write a concise response based on the classification.
      • Settings: Same as classifier.

Task Definition

  • Task 1: Classify Email
    • Description: Use F-string to embed the email variable.
    • Agent: Assign to classifier.
    • Expected Output: Either Important, Casual, or Spam.
  • Task 2: Respond to Email
    • Description: Generate a response based on email classification.
    • Agent: Assign to responder.

Crew Setup

  • Define Crew: Create and configure crew, assign agents, and tasks. crew = Crew(agents=[classifier, responder], tasks=[task1, task2], verbose=2, process=Process.SEQUENTIAL) output = crew.kickoff() print(output)

Running the Agents

  • Memory Usage: Observed 3-6 GB of RAM usage, indicating most systems can run it.
  • Issues: Some issues observed when running through Crew AI; model works perfectly in the terminal.

Using Gro API for Improved Performance

API Setup

  • API Creation: Create an API key on the Gro site.
  • Variables: Assign necessary API variables (API base, model name, API key).
  • Run: Incorporate these in the script for improved performance.
  • Outcome: Faster performance observed with Gro API.

Community and Resources

  • Workshop: Step-by-step workshop available inside the David Andre community.
  • Join the Community: Link provided for joining the community and accessing the workshop and resources.

Conclusion

  • AI Revolution: Emphasized the importance of getting involved in AI development.
  • Community Benefits: Learn and stay ahead by engaging with a community focused on AI innovation.