Adds version method
This commit is contained in:
14
examples/version.rs
Normal file
14
examples/version.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::{env, error::Error};
|
||||
|
||||
use ollama_rs::OllamaClient;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
tracing_subscriber::fmt().init();
|
||||
let _ = dotenvy::dotenv();
|
||||
let server_address = env::var("OLLAMA_SERVER")?;
|
||||
let ollama_client = OllamaClient::new(server_address);
|
||||
let version_response = ollama_client.version().await?;
|
||||
println!("{}", version_response.version);
|
||||
Ok(())
|
||||
}
|
||||
10
src/lib.rs
10
src/lib.rs
@@ -16,6 +16,7 @@ use crate::{
|
||||
ps::RunningModel,
|
||||
pull::{PullRequest, PullResponse},
|
||||
tags::Model,
|
||||
version::VersionResponse,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -33,6 +34,15 @@ impl OllamaClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn version(&self) -> OllamaResult<VersionResponse> {
|
||||
let request_address = format!("{}/api/version", self.server_address);
|
||||
Ok(reqwest::get(request_address)
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// Fetch a list of models and their details
|
||||
pub async fn tags(&self) -> OllamaResult<Vec<Model>> {
|
||||
let request_address = format!("{}/api/tags", self.server_address);
|
||||
|
||||
@@ -4,3 +4,4 @@ pub mod generate;
|
||||
pub mod ps;
|
||||
pub mod pull;
|
||||
pub mod tags;
|
||||
pub mod version;
|
||||
|
||||
6
src/types/version.rs
Normal file
6
src/types/version.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct VersionResponse {
|
||||
pub version: String,
|
||||
}
|
||||
Reference in New Issue
Block a user