-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from AlexisTM/feat/example_load_GenerationOptions
- Loading branch information
Showing
1 changed file
with
30 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,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(()) | ||
} |