[model-gateway] Fix logging module name, parse endpoint context, and tokenizer factory (#15782)

This commit is contained in:
Simo Lin
2025-12-24 10:54:48 -08:00
committed by GitHub
parent 186a56f6e2
commit 643aeefe6d
6 changed files with 23 additions and 45 deletions
+16 -3
View File
@@ -254,14 +254,27 @@ pub async fn create_tokenizer_async_with_chat_template(
}
// Check if it's a GPT model name that should use Tiktoken
if model_name_or_path.contains("gpt-")
// Only match specific OpenAI model patterns to avoid catching HuggingFace models like "openai/gpt-oss-20b"
if model_name_or_path.contains("gpt-4")
|| model_name_or_path.contains("gpt-3.5")
|| model_name_or_path.contains("gpt-3")
|| model_name_or_path.contains("turbo")
|| model_name_or_path.contains("davinci")
|| model_name_or_path.contains("curie")
|| model_name_or_path.contains("babbage")
|| model_name_or_path.contains("ada")
|| model_name_or_path.contains("codex")
{
let tokenizer = TiktokenTokenizer::from_model_name(model_name_or_path)?;
return Ok(Arc::new(tokenizer));
// Try tiktoken first, but fall back to HuggingFace if it fails
match TiktokenTokenizer::from_model_name(model_name_or_path) {
Ok(tokenizer) => return Ok(Arc::new(tokenizer)),
Err(e) => {
debug!(
"Tiktoken failed for '{}': {}, falling back to HuggingFace",
model_name_or_path, e
);
}
}
}
// Try to download tokenizer files from HuggingFace