feat: detect template family from aliases
This commit is contained in:
1 parent
9bf79ff68c
commit
9b1e973e4e
1 file changed
+29
-16
@@ -418,23 +418,36 @@ pub fn tool_calls_to_delta(tool_calls: &[ToolCall]) -> Vec<DeltaToolCall> {
|
||||
}
|
||||
|
||||
fn select_chat_template(req: &ChatCompletionRequest, config: &ServerConfig) -> ChatTemplate {
|
||||
let model_id = config
|
||||
.resolve_model(&req.model)
|
||||
.map(|model| model.root.as_str())
|
||||
.unwrap_or(req.model.as_str());
|
||||
let normalized = model_id.to_ascii_lowercase();
|
||||
|
||||
if normalized.contains("qwen") {
|
||||
ChatTemplate::Qwen
|
||||
} else if normalized.contains("gemma") {
|
||||
ChatTemplate::Gemma
|
||||
} else if normalized.contains("llama") {
|
||||
ChatTemplate::Llama
|
||||
} else if normalized.contains("kimi") {
|
||||
ChatTemplate::Kimi
|
||||
} else {
|
||||
ChatTemplate::Generic
|
||||
let mut candidates = vec![req.model.as_str()];
|
||||
if let Some(model) = config.resolve_model(&req.model) {
|
||||
if !model.id.eq_ignore_ascii_case(req.model.as_str()) {
|
||||
candidates.push(model.id.as_str());
|
||||
}
|
||||
if !model.root.eq_ignore_ascii_case(req.model.as_str())
|
||||
&& !model.root.eq_ignore_ascii_case(model.id.as_str())
|
||||
{
|
||||
candidates.push(model.root.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
for candidate in candidates {
|
||||
let normalized = candidate.to_ascii_lowercase();
|
||||
|
||||
if normalized.contains("qwen") {
|
||||
return ChatTemplate::Qwen;
|
||||
}
|
||||
if normalized.contains("gemma") {
|
||||
return ChatTemplate::Gemma;
|
||||
}
|
||||
if normalized.contains("llama") {
|
||||
return ChatTemplate::Llama;
|
||||
}
|
||||
if normalized.contains("kimi") {
|
||||
return ChatTemplate::Kimi;
|
||||
}
|
||||
}
|
||||
|
||||
ChatTemplate::Generic
|
||||
}
|
||||
|
||||
fn append_response_format_instruction(messages: &mut Vec<PromptMessage>, format: &ResponseFormat) {
|
||||
|
||||
Reference in new issue
Block a user