-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.rs
More file actions
114 lines (106 loc) · 3.56 KB
/
Copy pathcreate.rs
File metadata and controls
114 lines (106 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use anyhow::{Context, Result};
use tama_core::config::Config;
use tama_core::models::ModelManager;
pub(super) async fn cmd_create(
config: &Config,
server_name_arg: Option<String>,
model_id_arg: &str,
quant_name: Option<String>,
profile_name_arg: Option<String>,
backend_arg: Option<String>,
) -> Result<()> {
// Resolve server name — prompt if not provided
let server_name = match server_name_arg {
Some(n) => n,
None => inquire::Text::new("Config name (e.g. gemma4-coding):")
.prompt()
.context("Config name input cancelled")?,
};
// Resolve DB
let db_dir = tama_core::config::Config::config_dir()?;
let mgr = ModelManager::open(&db_dir)?;
// Resolve backend
let resolved_backend_key = match backend_arg {
Some(b) => {
if !config.backends.contains_key(&b) {
let available: Vec<&str> = config.backends.keys().map(|s| s.as_str()).collect();
anyhow::bail!(
"Backend '{}' not found. Available: {}",
b,
available.join(", ")
);
}
b
}
None => {
let keys: Vec<String> = config.backends.keys().cloned().collect();
match keys.len() {
0 => anyhow::bail!("No backends configured. Add one first with `tama add`."),
1 => keys.into_iter().next().unwrap(),
_ => inquire::Select::new("Select a backend:", keys)
.prompt()
.context("Backend selection cancelled")?,
}
}
};
// Resolve profile
let resolved_profile: Option<tama_core::profiles::Profile> = match profile_name_arg {
Some(p) => Some(
p.parse::<tama_core::profiles::Profile>()
.map_err(|e| anyhow::anyhow!(e))?,
),
None => None,
};
let model_config = tama_core::config::ModelConfig {
backend: resolved_backend_key.clone(),
gpu_variant: None,
args: vec![],
profile: resolved_profile.map(|p| p.to_string()),
sampling: None,
model: Some(model_id_arg.to_string()),
quant: quant_name.clone(),
mmproj: None,
mtp_model: None,
port: None,
health_check: None,
enabled: true,
context_length: None,
api_name: None,
gpu_layers: None,
quants: std::collections::BTreeMap::new(),
modalities: None,
display_name: None,
num_parallel: None,
kv_unified: true,
cache_type_k: None,
cache_type_v: None,
hf_format: None,
hf_base_model: None,
hf_pipeline_tag: None,
hf_total_params: None,
hf_active_params: None,
hf_architecture_type: None,
hf_context_length: None,
hf_num_layers: None,
hf_last_modified: None,
db_id: None,
spec_decoding: Default::default(),
};
mgr.save_model_config(&server_name, &model_config)?;
println!("Created.");
println!();
println!(" Name: {}", server_name);
println!(" Model: {}", model_id_arg);
if let Some(ref q) = quant_name {
println!(" Quant: {}", q);
}
if let Some(sampling) = &model_config.sampling {
println!(" Profile: {}", sampling.preset_label());
} else if let Some(p) = &model_config.profile {
println!(" Profile: {}", p);
}
println!();
println!("Enable it: tama model enable {}", server_name);
println!("Start: tama serve");
Ok(())
}