2023-06-05 21:17:07 +00:00
|
|
|
use std::{cell::Cell, env, path::PathBuf, sync::Mutex};
|
2023-05-30 06:39:02 +00:00
|
|
|
|
2023-05-30 22:44:29 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
2023-06-05 03:08:43 +00:00
|
|
|
static ref TABBY_ROOT: Mutex<Cell<PathBuf>> = {
|
|
|
|
|
Mutex::new(Cell::new(match env::var("TABBY_ROOT") {
|
2023-05-30 22:44:29 +00:00
|
|
|
Ok(x) => PathBuf::from(x),
|
|
|
|
|
Err(_) => PathBuf::from(env::var("HOME").unwrap()).join(".tabby"),
|
2023-06-05 03:08:43 +00:00
|
|
|
}))
|
2023-05-30 22:44:29 +00:00
|
|
|
};
|
2023-06-05 03:08:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "testutils")]
|
|
|
|
|
pub fn set_tabby_root(path: PathBuf) {
|
|
|
|
|
println!("SET TABBY ROOT: '{}'", path.display());
|
|
|
|
|
let cell = TABBY_ROOT.lock().unwrap();
|
|
|
|
|
cell.replace(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn tabby_root() -> PathBuf {
|
|
|
|
|
let mut cell = TABBY_ROOT.lock().unwrap();
|
|
|
|
|
cell.get_mut().clone()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn config_file() -> PathBuf {
|
|
|
|
|
tabby_root().join("config.toml")
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-09 07:31:13 +00:00
|
|
|
pub fn usage_id_file() -> PathBuf {
|
|
|
|
|
tabby_root().join("usage_anonymous_id")
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 03:08:43 +00:00
|
|
|
pub fn repositories_dir() -> PathBuf {
|
|
|
|
|
tabby_root().join("repositories")
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 22:18:10 +00:00
|
|
|
pub fn index_dir() -> PathBuf {
|
|
|
|
|
tabby_root().join("index")
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 15:19:43 +00:00
|
|
|
pub fn dataset_dir() -> PathBuf {
|
|
|
|
|
tabby_root().join("dataset")
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 03:08:43 +00:00
|
|
|
pub fn models_dir() -> PathBuf {
|
|
|
|
|
tabby_root().join("models")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn events_dir() -> PathBuf {
|
|
|
|
|
tabby_root().join("events")
|
2023-05-30 06:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ModelDir(PathBuf);
|
|
|
|
|
|
|
|
|
|
impl ModelDir {
|
|
|
|
|
pub fn new(model: &str) -> Self {
|
2023-06-05 03:08:43 +00:00
|
|
|
Self(models_dir().join(model))
|
2023-05-30 06:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn from(path: &str) -> Self {
|
|
|
|
|
Self(PathBuf::from(path))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn path(&self) -> &PathBuf {
|
|
|
|
|
&self.0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn path_string(&self, name: &str) -> String {
|
|
|
|
|
self.0.join(name).display().to_string()
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 23:47:48 +00:00
|
|
|
pub fn cache_info_file(&self) -> String {
|
|
|
|
|
self.path_string(".cache_info.json")
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-30 06:39:02 +00:00
|
|
|
pub fn metadata_file(&self) -> String {
|
2023-06-02 23:47:48 +00:00
|
|
|
self.path_string("tabby.json")
|
2023-05-30 06:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn tokenizer_file(&self) -> String {
|
2023-06-02 00:23:05 +00:00
|
|
|
self.path_string("tokenizer.json")
|
2023-05-30 06:39:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn ctranslate2_dir(&self) -> String {
|
|
|
|
|
self.path_string("ctranslate2")
|
|
|
|
|
}
|
2023-09-03 01:59:07 +00:00
|
|
|
|
2023-09-06 17:12:29 +00:00
|
|
|
pub fn ggml_q8_0_file(&self) -> String {
|
|
|
|
|
self.path_string("ggml/q8_0.gguf")
|
2023-09-03 01:59:07 +00:00
|
|
|
}
|
2023-05-30 06:39:02 +00:00
|
|
|
}
|