From c3bfc6bb81c2b7f7a9b2bda0f4d958c383f80b04 Mon Sep 17 00:00:00 2001 From: Daehee Kim <76981513+DayNice@users.noreply.github.com> Date: Thu, 6 Nov 2025 19:21:31 +0900 Subject: [PATCH] Change `Api::new()` into `ApiBuilder::from_env().build()` --- rust/src/embeddings/local/clip.rs | 2 +- rust/src/embeddings/local/colbert.rs | 4 ++-- rust/src/embeddings/local/colpali.rs | 2 +- rust/src/embeddings/local/colpali_ort.rs | 2 +- rust/src/embeddings/local/colsmol.rs | 2 +- rust/src/embeddings/local/ort_bert.rs | 6 +++--- rust/src/embeddings/local/ort_colsmol.rs | 2 +- rust/src/embeddings/local/ort_jina.rs | 4 ++-- rust/src/file_processor/audio/audio_processor.rs | 4 ++-- rust/src/models/idefics3/array_processing.rs | 8 ++++---- rust/src/models/idefics3/tensor_processing.rs | 6 +++--- rust/src/reranker/model.rs | 4 ++-- 12 files changed, 23 insertions(+), 23 deletions(-) diff --git a/rust/src/embeddings/local/clip.rs b/rust/src/embeddings/local/clip.rs index b1e5357c..8dad792a 100644 --- a/rust/src/embeddings/local/clip.rs +++ b/rust/src/embeddings/local/clip.rs @@ -203,7 +203,7 @@ impl ClipEmbedder { ) -> anyhow::Result { let tokenizer = match tokenizer { None => { - let api = hf_hub::api::sync::Api::new()?; + let api = hf_hub::api::sync::ApiBuilder::from_env().build()?; let api = match revision { Some(rev) => api.repo(hf_hub::Repo::with_revision( model_id, diff --git a/rust/src/embeddings/local/colbert.rs b/rust/src/embeddings/local/colbert.rs index 77d99794..85f8de37 100644 --- a/rust/src/embeddings/local/colbert.rs +++ b/rust/src/embeddings/local/colbert.rs @@ -7,7 +7,7 @@ extern crate accelerate_src; use std::{ops::Mul, sync::RwLock}; use anyhow::{Error as E, Result}; -use hf_hub::{api::sync::Api, Repo}; +use hf_hub::{api::sync::ApiBuilder, Repo}; use ndarray::{Array2, Axis}; use ort::{ execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider}, @@ -52,7 +52,7 @@ impl OrtColbertEmbedder { }; let (_, tokenizer_filename, weights_filename, tokenizer_config_filename, data_filename) = { - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let api = match revision { Some(rev) => api.repo(Repo::with_revision( hf_model_id.to_string(), diff --git a/rust/src/embeddings/local/colpali.rs b/rust/src/embeddings/local/colpali.rs index 4f6d40e0..4157ec09 100644 --- a/rust/src/embeddings/local/colpali.rs +++ b/rust/src/embeddings/local/colpali.rs @@ -43,7 +43,7 @@ pub struct ColPaliEmbedder { impl ColPaliEmbedder { pub fn new(model_id: &str, revision: Option<&str>) -> Result { - let api = hf_hub::api::sync::Api::new()?; + let api = hf_hub::api::sync::ApiBuilder::from_env().build()?; let repo: hf_hub::api::sync::ApiRepo = match revision { Some(rev) => api.repo(hf_hub::Repo::with_revision( model_id.to_string(), diff --git a/rust/src/embeddings/local/colpali_ort.rs b/rust/src/embeddings/local/colpali_ort.rs index 04bcd579..29c6f4de 100644 --- a/rust/src/embeddings/local/colpali_ort.rs +++ b/rust/src/embeddings/local/colpali_ort.rs @@ -31,7 +31,7 @@ impl OrtColPaliEmbedder { revision: Option<&str>, path_in_repo: Option<&str>, ) -> Result { - let api = hf_hub::api::sync::Api::new()?; + let api = hf_hub::api::sync::ApiBuilder::from_env().build()?; let repo: hf_hub::api::sync::ApiRepo = match revision { Some(rev) => api.repo(hf_hub::Repo::with_revision( model_id.to_string(), diff --git a/rust/src/embeddings/local/colsmol.rs b/rust/src/embeddings/local/colsmol.rs index d6795803..0399f0d1 100644 --- a/rust/src/embeddings/local/colsmol.rs +++ b/rust/src/embeddings/local/colsmol.rs @@ -21,7 +21,7 @@ pub struct ColSmolEmbedder { impl ColSmolEmbedder { pub fn new(model_id: &str, revision: Option<&str>) -> Result { - let api = hf_hub::api::sync::Api::new()?; + let api = hf_hub::api::sync::ApiBuilder::from_env().build()?; let repo: hf_hub::api::sync::ApiRepo = match revision { Some(rev) => api.repo(hf_hub::Repo::with_revision( model_id.to_string(), diff --git a/rust/src/embeddings/local/ort_bert.rs b/rust/src/embeddings/local/ort_bert.rs index e6b0845a..95454a4c 100644 --- a/rust/src/embeddings/local/ort_bert.rs +++ b/rust/src/embeddings/local/ort_bert.rs @@ -9,7 +9,7 @@ use crate::embeddings::utils::{get_type_ids_ndarray, tokenize_batch_ndarray}; use crate::Dtype; use anyhow::Error as E; -use hf_hub::api::sync::Api; +use hf_hub::api::sync::ApiBuilder; use hf_hub::Repo; use ndarray::prelude::*; use ort::execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider}; @@ -62,7 +62,7 @@ impl OrtBertEmbedder { }; let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = { - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let api = match revision { Some(rev) => api.repo(Repo::with_revision( hf_model_id.to_string(), @@ -418,7 +418,7 @@ impl OrtSparseBertEmbedder { }; let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = { - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let api = match revision { Some(rev) => api.repo(Repo::with_revision( hf_model_id.to_string(), diff --git a/rust/src/embeddings/local/ort_colsmol.rs b/rust/src/embeddings/local/ort_colsmol.rs index 9d938a4c..97b977fb 100644 --- a/rust/src/embeddings/local/ort_colsmol.rs +++ b/rust/src/embeddings/local/ort_colsmol.rs @@ -34,7 +34,7 @@ impl OrtColSmolEmbedder { revision: Option<&str>, path_in_repo: Option<&str>, ) -> Result { - let api = hf_hub::api::sync::Api::new()?; + let api = hf_hub::api::sync::ApiBuilder::from_env().build()?; let repo: hf_hub::api::sync::ApiRepo = match revision { Some(rev) => api.repo(hf_hub::Repo::with_revision( model_id.to_string(), diff --git a/rust/src/embeddings/local/ort_jina.rs b/rust/src/embeddings/local/ort_jina.rs index 95608619..3baae084 100644 --- a/rust/src/embeddings/local/ort_jina.rs +++ b/rust/src/embeddings/local/ort_jina.rs @@ -6,7 +6,7 @@ use crate::embeddings::embed::EmbeddingResult; use crate::embeddings::utils::tokenize_batch_ndarray; use crate::Dtype; use anyhow::Error as E; -use hf_hub::api::sync::Api; +use hf_hub::api::sync::ApiBuilder; use hf_hub::Repo; use ndarray::prelude::*; use std::sync::RwLock; @@ -63,7 +63,7 @@ impl OrtJinaEmbedder { }; let (_, tokenizer_filename, weights_filename, tokenizer_config_filename) = { - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let api = match revision { Some(rev) => api.repo(Repo::with_revision( hf_model_id.to_string(), diff --git a/rust/src/file_processor/audio/audio_processor.rs b/rust/src/file_processor/audio/audio_processor.rs index f9328820..e7cef00f 100644 --- a/rust/src/file_processor/audio/audio_processor.rs +++ b/rust/src/file_processor/audio/audio_processor.rs @@ -9,7 +9,7 @@ use std::path::PathBuf; use anyhow::{Error as E, Result}; use candle_core::{Device, IndexOp, Tensor}; use candle_nn::{ops::softmax, VarBuilder}; -use hf_hub::{api::sync::Api, Repo, RepoType}; +use hf_hub::{api::sync::ApiBuilder, Repo, RepoType}; use rand::{ distr::{weighted::WeightedIndex, Distribution}, SeedableRng, @@ -458,7 +458,7 @@ pub fn build_model( (None, None) => (default_model, default_revision), }; - let api = Api::new()?; + let api = ApiBuilder::from_env().build()?; let repo = api.repo(Repo::with_revision( model_id.to_string(), RepoType::Model, diff --git a/rust/src/models/idefics3/array_processing.rs b/rust/src/models/idefics3/array_processing.rs index ef80dc45..de4fdcba 100644 --- a/rust/src/models/idefics3/array_processing.rs +++ b/rust/src/models/idefics3/array_processing.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use anyhow::{Error, Ok}; -use hf_hub::{api::sync::Api, Repo, RepoType}; +use hf_hub::{api::sync::ApiBuilder, Repo, RepoType}; use image::{imageops::FilterType, DynamicImage, GenericImageView, RgbImage}; use ndarray::{s, Array2}; use regex::Regex; @@ -65,7 +65,7 @@ impl Idefics3ImageProcessor { } pub fn from_pretrained(model_id: &str) -> Result { - let api = Api::new()?; + let api = ApiBuilder::from_env().build()?; let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model)); let config_file = repo.get("preprocessor_config.json").unwrap(); let processor: Idefics3ImageProcessor = @@ -692,7 +692,7 @@ fn normalize( #[cfg(test)] mod tests { use super::*; - use hf_hub::api::sync::Api; + use hf_hub::api::sync::ApiBuilder; use hf_hub::{Repo, RepoType}; use image::RgbImage; @@ -701,7 +701,7 @@ mod tests { let image = image::open("/home/akshay/projects/EmbedAnything/test.jpg").unwrap(); let image_array = image.to_rgb8().into_raw(); - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let repo = api.repo(Repo::new( "onnx-community/colSmol-256M-ONNX".to_string(), RepoType::Model, diff --git a/rust/src/models/idefics3/tensor_processing.rs b/rust/src/models/idefics3/tensor_processing.rs index df200c3e..4281468a 100644 --- a/rust/src/models/idefics3/tensor_processing.rs +++ b/rust/src/models/idefics3/tensor_processing.rs @@ -1,5 +1,5 @@ use candle_core::{DType, Device, Tensor}; -use hf_hub::{api::sync::Api, Repo, RepoType}; +use hf_hub::{api::sync::ApiBuilder, Repo, RepoType}; use image::{imageops::FilterType, DynamicImage, GenericImageView, RgbImage}; use serde::Deserialize; use std::collections::HashMap; @@ -503,7 +503,7 @@ impl Idefics3ImageProcessor { } pub fn from_pretrained(model_id: &str) -> Result { - let api = Api::new()?; + let api = ApiBuilder::from_env().build()?; let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model)); let config_file = repo.get("preprocessor_config.json")?; let processor: Idefics3ImageProcessor = @@ -525,7 +525,7 @@ pub struct Idefics3Processor { impl Idefics3Processor { pub fn from_pretrained(model_id: &str) -> anyhow::Result { let image_processor = Idefics3ImageProcessor::from_pretrained(model_id)?; - let api = Api::new()?; + let api = ApiBuilder::from_env().build()?; let repo = api.repo(Repo::new(model_id.to_string(), RepoType::Model)); let processor_config_file = repo.get("processor_config.json")?; diff --git a/rust/src/reranker/model.rs b/rust/src/reranker/model.rs index d6a4e731..9e30f828 100644 --- a/rust/src/reranker/model.rs +++ b/rust/src/reranker/model.rs @@ -2,7 +2,7 @@ use std::sync::RwLock; use anyhow::{Error as E, Result}; use candle_core::{Device, Tensor}; -use hf_hub::{api::sync::Api, Repo}; +use hf_hub::{api::sync::ApiBuilder, Repo}; use ndarray::Array2; use ort::{ execution_providers::{CUDAExecutionProvider, CoreMLExecutionProvider, ExecutionProvider}, @@ -41,7 +41,7 @@ impl Reranker { path_in_repo: Option<&str>, ) -> Result { let (config_filename, tokenizer_filename, weights_filename, tokenizer_config_filename) = { - let api = Api::new().unwrap(); + let api = ApiBuilder::from_env().build().unwrap(); let api = match revision { Some(rev) => api.repo(Repo::with_revision( model_id.to_string(),