Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(ollama-example): implement example showcasing ollama #148

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(())
}
Loading