-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract registry to its sub dir.
- Loading branch information
Showing
6 changed files
with
67 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,24 @@ | ||
use anyhow::{anyhow, Result}; | ||
use async_trait::async_trait; | ||
|
||
use crate::Registry; | ||
|
||
#[derive(Default)] | ||
pub struct HuggingFaceRegistry {} | ||
|
||
#[async_trait] | ||
impl Registry for HuggingFaceRegistry { | ||
fn build_url(&self, model_id: &str, path: &str) -> String { | ||
format!("https://huggingface.co/{}/resolve/main/{}", model_id, path) | ||
} | ||
|
||
async fn build_cache_key(&self, url: &str) -> Result<String> { | ||
let res = reqwest::get(url).await?; | ||
let cache_key = res | ||
.headers() | ||
.get("etag") | ||
.ok_or(anyhow!("etag key missing"))? | ||
.to_str()?; | ||
Ok(cache_key.to_owned()) | ||
} | ||
} |
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,25 @@ | ||
mod huggingface; | ||
mod modelscope; | ||
|
||
use anyhow::Result; | ||
use async_trait::async_trait; | ||
use huggingface::HuggingFaceRegistry; | ||
|
||
use self::modelscope::ModelScopeRegistry; | ||
|
||
#[async_trait] | ||
pub trait Registry { | ||
fn build_url(&self, model_id: &str, path: &str) -> String; | ||
async fn build_cache_key(&self, url: &str) -> Result<String>; | ||
} | ||
|
||
pub fn create_registry() -> Box<dyn Registry> { | ||
let registry = std::env::var("TABBY_REGISTRY").unwrap_or("huggingface".to_owned()); | ||
if registry == "huggingface" { | ||
Box::<HuggingFaceRegistry>::default() | ||
} else if registry == "modelscope" { | ||
Box::<ModelScopeRegistry>::default() | ||
} else { | ||
panic!("Unsupported registry {}", registry); | ||
} | ||
} |
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