use kalosm_common::FileSource;
use kalosm_language_model::ChatMarkers;
pub struct PhiSource {
pub(crate) model: FileSource,
pub(crate) tokenizer: FileSource,
pub(crate) phi_config: crate::Config,
pub(crate) phi2: bool,
pub(crate) chat_markers: Option<ChatMarkers>,
}
impl PhiSource {
pub fn new(model: FileSource, tokenizer: FileSource, phi_config: crate::Config) -> Self {
Self {
model,
tokenizer,
phi_config,
phi2: false,
chat_markers: Default::default(),
}
}
pub fn v1() -> Self {
Self::new(
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"model-v1-q4k.gguf".to_string(),
),
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"tokenizer.json".to_string(),
),
crate::Config::v1(),
)
}
pub fn v1_5() -> Self {
Self::new(
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"model-q4k.gguf".to_string(),
),
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"tokenizer.json".to_string(),
),
crate::Config::v1_5(),
)
}
pub fn v2() -> Self {
let mut myself = Self::new(
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"model-v2-q4k.gguf".to_string(),
),
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"tokenizer.json".to_string(),
),
crate::Config::v2(),
);
myself.phi2 = true;
myself
}
pub fn puffin_phi_v2() -> Self {
Self::new(
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"model-puffin-phi-v2-q4k.gguf".to_string(),
),
FileSource::huggingface(
"lmz/candle-quantized-phi".to_string(),
"main".to_string(),
"tokenizer-puffin-phi-v2.json".to_string(),
),
crate::Config::puffin_phi_v2(),
)
}
pub fn dolphin_phi_v2() -> Self {
let mut myself = Self::new(
FileSource::huggingface(
"Demonthos/dolphin-2_6-phi-2-candle".to_string(),
"main".to_string(),
"model-q4k.gguf".to_string(),
),
FileSource::huggingface(
"Demonthos/dolphin-2_6-phi-2-candle".to_string(),
"main".to_string(),
"tokenizer.json".to_string(),
),
crate::Config::v2(),
)
.with_chat_markers(ChatMarkers {
user_marker: "<|im_start|>user",
end_user_marker: "<|im_end|>",
assistant_marker: "<|im_start|>assistant",
end_assistant_marker: "<|im_end|>",
system_prompt_marker: "<|im_start|>system",
end_system_prompt_marker: "<|im_end|>",
});
myself.phi2 = true;
myself
}
pub fn with_phi_config(mut self, phi_config: crate::Config) -> Self {
self.phi_config = phi_config;
self
}
pub fn with_chat_markers(mut self, chat_markers: ChatMarkers) -> Self {
self.chat_markers = Some(chat_markers);
self
}
}
impl Default for PhiSource {
fn default() -> Self {
Self::v1_5()
}
}