From 9c118fb91ac1c8557bc575ad96e792f1d98cb30b Mon Sep 17 00:00:00 2001 From: Andrew Choi Date: Mon, 17 Feb 2025 15:14:03 +0000 Subject: [PATCH] updated ai-agent files --- .../ai-agent-on-cpu/ai-agent-backend.md | 24 ++++++++++++------- .../ai-agent-on-cpu/set-up.md | 11 ++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md b/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md index c5d4b987d..477758a8b 100644 --- a/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md +++ b/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/ai-agent-backend.md @@ -12,18 +12,19 @@ Once you set up the environment, create a Python script which will execute the A ### Option A - Clone the repository ```bash +cd ~ git clone https://github.com/jc2409/ai-agent.git ``` ### Option B - Creat a Python file: ```bash +cd ~ touch agent.py ``` - Copy and paste the following code: ```bash -import os from enum import Enum from typing import Union from pydantic import BaseModel, Field @@ -36,16 +37,17 @@ from llama_cpp_agent import MessagesFormatterType from llama_cpp_agent import LlamaCppAgent from llama_cpp_agent.providers import LlamaCppPythonProvider from llama_cpp import Llama -# from langchain_community.tools import TavilySearchResults // Uncomment this to enable search function -from dotenv import load_dotenv +# import os +# from dotenv import load_dotenv +# from langchain_community.tools import TavilySearchResults # Uncomment this to enable search function -load_dotenv() +# load_dotenv() -os.environ.get("TAVILY_API_KEY") +# os.environ.get("TAVILY_API_KEY") llama_model = Llama( - model_path="./models/llama3.1-8b-instruct.Q4_0_arm.gguf", // make sure you use the correct path for the quantized model + model_path="./models/llama3.1-8b-instruct.Q4_0_arm.gguf", # make sure you use the correct path for the quantized model n_batch=2048, n_ctx=10000, n_threads=64, @@ -112,7 +114,7 @@ def calculator( else: raise ValueError("Unknown operation.") -// Uncomment the following function to enable web search functionality (You will need to install langchain-community) +# Uncomment the following function to enable web search functionality (You will need to install langchain-community) # def search_from_the_web(content: str): # """ # Search useful information from the web to answer User's question @@ -174,4 +176,10 @@ if __name__ == '__main__': You are now ready to test the AI Agent. Use the following command in a terminal to start the application: ```bash python3 agent.py -``` \ No newline at end of file +``` + +{{% notice Note %}} + +If it takes too long to process, try to terminate the application and try again. + +{{% /notice %}} diff --git a/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/set-up.md b/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/set-up.md index 86d215655..540d1287c 100644 --- a/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/set-up.md +++ b/content/learning-paths/servers-and-cloud-computing/ai-agent-on-cpu/set-up.md @@ -1,6 +1,6 @@ --- title: Set up the Environment to Run an AI Application Locally -weight: 2 +weight: 3 ### FIXED, DO NOT MODIFY layout: learningpathall @@ -16,6 +16,15 @@ In this Learning Path, you learn how to build an AI Agent application using llam ## Installation +Set up the virtual environment and install dependencies: +```bash +sudo apt-get update +sudo apt-get upgrade +sudo apt install python3-pip python3-venv cmake -y +python3 -m venv ai-agent +source ai-agent/bin/activate +``` + Install the `llama-cpp-python` package using pip: ```bash