Skip to content

Commit

Permalink
updated ai-agent files
Browse files Browse the repository at this point in the history
  • Loading branch information
jc2409 committed Feb 17, 2025
1 parent 98568da commit 9c118fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
```
```
{{% notice Note %}}
If it takes too long to process, try to terminate the application and try again.
{{% /notice %}}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 9c118fb

Please sign in to comment.