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

feat: Add an example to show how to load GenerationOptions from a json string #30

Merged
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
30 changes: 30 additions & 0 deletions examples/options_from_json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use ollama_rs::{
generation::{completion::request::GenerationRequest, options::GenerationOptions},
Ollama,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ollama = Ollama::default();
let model = "llama2:latest".to_string();
let prompt = "Why is the sky blue?".to_string();

// Fetch the configuration from a file or from user request
// let options_str = fs::read_to_string("options.json").expect("The option file should be available") ;
let options_str = r#"{
"temperature": 0.2,
"repeat_penalty": 1.5,
"top_k": 25,
"top_p": 0.25
}"#;
let options: GenerationOptions =
serde_json::from_str(options_str).expect("JSON was not well-formatted");
let res = ollama
.generate(GenerationRequest::new(model, prompt).options(options))
.await;

if let Ok(res) = res {
println!("{}", res.response);
}
Ok(())
}
Loading