Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Sep 29, 2024
1 parent 0a553be commit 34f5195
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 75 deletions.
8 changes: 2 additions & 6 deletions crates/aim-downloader/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ use crate::{
address::ParsedAddress,
bar::WrappedBar,
consts::*,
error::{DownloadError, ValidateError,HTTPHeaderError},
error::{DownloadError, HTTPHeaderError, ValidateError},
hash::HashChecker,
io,
};

pub struct HTTPSHandler;
impl HTTPSHandler {

pub async fn head(input: &str) -> Result<HeaderMap, HTTPHeaderError> {
let parsed_address = ParsedAddress::parse_address(input, true);
let res = Client::new()
Expand Down Expand Up @@ -157,8 +156,6 @@ impl HTTPSHandler {
name: input.into(),
code: e.to_string(),
})?;



let total_size = downloaded + res.content_length().unwrap_or(0);

Expand Down Expand Up @@ -295,10 +292,9 @@ async fn get_links_works_when_typical() {
assert_eq!(result[0], expected);
}


#[ignore]
#[tokio::test]
async fn head_works() {
let result = HTTPSHandler::head("https://github.com/XAMPPRocky/tokei/releases/download/v12.0.4/tokei-x86_64-unknown-linux-gnu.tar.gz").await;
assert!(result.is_ok());
}
}
2 changes: 1 addition & 1 deletion crates/tabby-common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pub fn get_huggingface_mirror_host() -> Option<String> {
// for debug only
pub fn use_local_model_json() -> bool {
std::env::var("TABBY_USE_LOCAL_MODEL_JSON").is_ok()
}
}
2 changes: 1 addition & 1 deletion crates/tabby-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pub mod api;
pub mod axum;
pub mod config;
pub mod constants;
pub mod env;
pub mod index;
pub mod languages;
pub mod path;
pub mod registry;
pub mod terminal;
pub mod usage;
pub mod env;
23 changes: 7 additions & 16 deletions crates/tabby-common/src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{fs, path::PathBuf};

use anyhow::{Context, Result};
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};

use crate::{env::use_local_model_json, path::models_dir};
Expand All @@ -11,7 +10,6 @@ fn default_entrypoint() -> String {
"model.gguf".to_string()
}


#[derive(Serialize, Deserialize)]
pub struct ModelInfo {
pub name: String,
Expand Down Expand Up @@ -64,7 +62,6 @@ pub struct ModelRegistry {
pub models: Vec<ModelInfo>,
}


// model registry tree structure

// root: ~/.tabby/models/TABBYML
Expand All @@ -75,20 +72,19 @@ pub struct ModelRegistry {

// fn get_model_path(model_name)
// for single model file
// -> {root}/{model_name}/ggml/model.gguf
// -> {root}/{model_name}/ggml/model.gguf
// for multiple model files
// -> {root}/{model_name}/ggml/{entrypoint}

impl ModelRegistry {
pub async fn new(registry: &str) -> Self {

if use_local_model_json() {
return Self {
Self {
name: registry.to_owned(),
models: load_local_registry(registry).unwrap_or_else(|_| {
panic!("Failed to fetch model organization <{}>", registry)
}),
};
}
} else {
Self {
name: registry.to_owned(),
Expand All @@ -102,8 +98,6 @@ impl ModelRegistry {
}),
}
}


}

// get_model_store_dir returns {root}/{name}/ggml, e.g.. ~/.tabby/models/TABBYML/StarCoder-1B/ggml
Expand All @@ -117,7 +111,7 @@ impl ModelRegistry {
}

// get_legacy_model_path returns {root}/{name}/q8_0.v2.gguf, e.g. ~/.tabby/models/TABBYML/StarCoder-1B/q8_0.v2.gguf
fn get_legacy_model_path(&self, name:&str) ->PathBuf {
fn get_legacy_model_path(&self, name: &str) -> PathBuf {
self.get_model_store_dir(name).join("q8_0.v2.gguf")
}

Expand All @@ -126,7 +120,8 @@ impl ModelRegistry {
// for multiple model files, it returns {root}/{name}/ggml/{entrypoint}
pub fn get_model_entry_path(&self, name: &str) -> PathBuf {
let model_info = self.get_model_info(name);
self.get_model_store_dir(name).join(model_info.entrypoint.clone())
self.get_model_store_dir(name)
.join(model_info.entrypoint.clone())
}

pub fn migrate_model_path(&self, name: &str) -> Result<(), std::io::Error> {
Expand All @@ -143,8 +138,6 @@ impl ModelRegistry {
Ok(())
}



pub fn save_model_info(&self, name: &str) {
let model_info = self.get_model_info(name);
let path = self.get_model_dir(name).join("tabby.json");
Expand All @@ -171,13 +164,11 @@ pub fn parse_model_id(model_id: &str) -> (&str, &str) {
}
}



#[cfg(test)]
mod tests {
use temp_testdir::TempDir;

use super::{ModelRegistry, *};
use super::ModelRegistry;
use crate::path::set_tabby_root;

#[tokio::test]
Expand Down
Loading

0 comments on commit 34f5195

Please sign in to comment.