Walee's Blog

A blog to discuss all things Ai Agent Frameworks and Platforms


Assumptions

You already have git, cargo, and rust installed
For git: Find instructions here
For rust and cargo: Find instructions here

Check out my GitHub repository for the source code Rig Hello World

Open a command line terminal and run the following commands

Install Rust

If you haven’t installed Rust yet, install it using rustup

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Create a new Rust project

cargo new rig_hello_world

Change to the newly created project directory

cd rig_hello_world

Add rig-core, tokio, and anyhow dependency to Project

cargo add rig-core
cargo add tokio --features full
cargo add anyhow

Download and install Ollama for your OS

Ollama Website

Pull down the llama3.2:1b model

ollama run llama3.2:1b

Confirm Ollama is running in a browser

Open Local Ollama

Replace the content of src/main.rs with below

/// This example requires that you have the [`ollama`](https://ollama.com) server running locally.
use rig::{completion::Prompt, providers};

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
    // Create an OpenAI client with a custom base url, a local ollama endpoint
    // The API Key is unnecessary for most local endpoints
    let client = providers::openai::Client::from_url("ollama", "http://localhost:11434/v1");

    // Create agent with a single context prompt
    let comedian_agent = client
        .agent("llama3.2:1b")
        .preamble("You are a comedian here to entertain the user using humour and jokes.")
        .build();



    // Prompt the agent and print the response
    let response = comedian_agent.prompt("Entertain me!").await?;
    println!("{}", response);

    Ok(())
}

Run the Rig agent

cargo run

This completes your hello world Rig introduction
Congratulations you have successful run your first Rig Ai Agent


Project maintained by wale-e Hosted on GitHub Pages — Theme by mattgraham