Skip to content

Commit

Permalink
fix(ollama-api-bindings): Fix model availability check (#2367)
Browse files Browse the repository at this point in the history
If model tag is unspecified the check will fail because /api/tags returns model name with `:latest` appended
  • Loading branch information
SpeedCrash100 authored Jun 7, 2024
1 parent 89014fc commit 676fc51
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions crates/ollama-api-bindings/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,18 @@ impl OllamaModelExt for Ollama {
async fn model_available(&self, name: impl AsRef<str> + Send) -> Result<bool> {
let name = name.as_ref();

let models_available = self.list_local_models().await?;

Ok(models_available.into_iter().any(|model| model.name == name))
let models_available = self.show_model_info(name.into()).await;

match models_available {
Ok(_) => Ok(true),
Err(err) => {
if err.to_string().contains("not found") {
Ok(false)
} else {
Err(err.into())
}
}
}
}

async fn get_first_available_model(&self) -> Result<Option<String>> {
Expand Down

0 comments on commit 676fc51

Please sign in to comment.