Use clap for command-line arguments in pull example
Some checks failed
CI / Check (push) Has been cancelled
CI / Test (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Format (push) Has been cancelled

This commit is contained in:
2026-04-06 16:49:34 +01:00
parent 1b37c8dafe
commit 21e062fae7
2 changed files with 23 additions and 6 deletions

View File

@@ -13,6 +13,7 @@ futures-util = "0.3"
async-stream = "0.3"
[dev-dependencies]
clap = { version = "4.5", features = ["derive", "env"] }
dialoguer = "0.12.0"
dotenvy = "0.15.7"
tokio = { version = "1.49.0", features = ["full"] }

View File

@@ -1,21 +1,37 @@
use std::{env, error::Error, io::Write};
use std::{error::Error, io::Write};
use clap::Parser;
use futures_util::StreamExt;
use ollama_rs::{OllamaClient, types::pull::PullRequest};
const MODEL: &str = "functiongemma";
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// The model to pull
#[arg(short, long)]
model: String,
/// The Ollama server address
#[arg(
short,
long,
env = "OLLAMA_SERVER",
default_value = "http://localhost:11434"
)]
server_address: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let _ = dotenvy::dotenv();
let server_address = env::var("OLLAMA_SERVER")?;
let ollama_client = OllamaClient::new(server_address);
let args = Args::parse();
let ollama_client = OllamaClient::new(args.server_address);
let request = PullRequest::builder(MODEL).stream(true).build();
let request = PullRequest::builder(&args.model).stream(true).build();
let mut stream = ollama_client.pull(request);
while let Some(response) = stream.next().await {
let response = response?;
println!("{:?}", response);
println!("{}", response.status);
std::io::stdout().flush()?;
}
Ok(())