Skip to content

Commit

Permalink
Merge pull request #30 from AlexisTM/feat/example_load_GenerationOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pepperoni21 authored Feb 26, 2024
2 parents 5d6cd76 + f38f89f commit f38634d
Showing 1 changed file with 30 additions and 0 deletions.
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(())
}

0 comments on commit f38634d

Please sign in to comment.