Refactor llm_chat_template_from_str to avoid throwing exceptions
This commit is contained in:
parent
070ff4d535
commit
cc9732e2af
|
|
@ -76,14 +76,15 @@ static const std::map<std::string, llm_chat_template> LLM_CHAT_TEMPLATES = {
|
||||||
};
|
};
|
||||||
|
|
||||||
llm_chat_template llm_chat_template_from_str(const std::string & name) {
|
llm_chat_template llm_chat_template_from_str(const std::string & name) {
|
||||||
return LLM_CHAT_TEMPLATES.at(name);
|
if (auto it = LLM_CHAT_TEMPLATES.find(name); it != LLM_CHAT_TEMPLATES.end()) {
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
return LLM_CHAT_TEMPLATE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
|
llm_chat_template llm_chat_detect_template(const std::string & tmpl) {
|
||||||
try {
|
if (auto t = llm_chat_template_from_str(tmpl); t != LLM_CHAT_TEMPLATE_UNKNOWN) {
|
||||||
return llm_chat_template_from_str(tmpl);
|
return t;
|
||||||
} catch (const std::out_of_range &) {
|
|
||||||
// ignore
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tmpl_contains = [&tmpl](const char * haystack) -> bool {
|
auto tmpl_contains = [&tmpl](const char * haystack) -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue