Skip to content

Commit

Permalink
docs(ollama-example): implement example showcasing ollama (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMochan authored Dec 13, 2024
1 parent 2b6d571 commit 38d8a76
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rig-core/examples/agent_with_ollama.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// 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");

// Create agent with a single context prompt
let comedian_agent = client
.agent("llama3.2:latest")
.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(())
}

0 comments on commit 38d8a76

Please sign in to comment.