Refactor OpenAI serving modules for improved functionality and organization

- Reintroduced the load_chat_template import in api_server.py for better template handling.
- Updated the logic in serving_chat.py to streamline the resolution of chat template content formats, enhancing clarity and functionality.
- Adjusted the application of chat templates to ensure proper handling of tools and chat templates.

Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
tzhouam committed 2026-01-30 02:44:13 +00:00
1 parent 104e105c93
commit 62dbf07fb6
1 file changed
+19 -9
+19 -9
View File
@@ -351,13 +351,18 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
model_config = self.model_config
tokenizer = renderer.get_tokenizer() if renderer is not None else None
resolved_content_format = resolve_chat_template_content_format(
chat_template,
tool_dicts,
chat_template_content_format,
tokenizer,
model_config=model_config,
)
if tokenizer is None or isinstance(tokenizer, MistralTokenizer):
resolved_content_format = (
chat_template_content_format if chat_template_content_format != "auto" else "string"
)
else:
resolved_content_format = resolve_chat_template_content_format(
chat_template,
tool_dicts,
chat_template_content_format,
tokenizer,
model_config=model_config,
)
conversation, mm_data_future, mm_uuids = parse_chat_messages_futures(
messages,
model_config,
@@ -392,12 +397,17 @@ class OmniOpenAIServingChat(OpenAIServingChat, AudioMixin):
**_chat_template_kwargs,
)
else:
hf_chat_template_kwargs = dict(_chat_template_kwargs)
hf_chat_template_kwargs.pop("tools", None)
hf_chat_template_kwargs.pop("chat_template", None)
request_prompt = apply_hf_chat_template(
model_config=model_config,
tokenizer=tokenizer,
conversation=conversation,
model_config=model_config,
tools=tool_dicts,
chat_template=chat_template,
tokenize=False,
**_chat_template_kwargs,
**hf_chat_template_kwargs,
)
mm_data = await mm_data_future