fix: support local model path (#165)

add-prefix-suffix
Meng Zhang 2023-05-29 17:40:16 -07:00 committed by GitHub
parent 418558c05d
commit 8956056120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -67,9 +67,7 @@ pub struct CompletionState {
impl CompletionState {
pub fn new(args: &crate::serve::ServeArgs) -> Self {
let home = std::env::var("HOME").unwrap();
let tabby_root = format!("{}/.tabby", home);
let model_dir = Path::new(&tabby_root).join("models").join(&args.model);
let model_dir = get_model_dir(&args.model);
let metadata = read_metadata(&model_dir);
let device = format!("{}", args.device);
@ -87,6 +85,16 @@ impl CompletionState {
}
}
fn get_model_dir(model: &str) -> std::path::PathBuf {
if Path::new(model).exists() {
Path::new(model).to_path_buf()
} else {
let home = std::env::var("HOME").unwrap();
let tabby_root = format!("{}/.tabby", home);
Path::new(&tabby_root).join("models").join(model)
}
}
fn timestamp() -> u64 {
use std::time::{SystemTime, UNIX_EPOCH};
let start = SystemTime::now();