-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(ollama-example): implement example showcasing ollama (#148)
- Loading branch information
Showing
1 changed file
with
21 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |