Skip to content

Auto parser detect / auto input-workaround detection#4312

Open
dkalinowski wants to merge 23 commits into
mainfrom
detect
Open

Auto parser detect / auto input-workaround detection#4312
dkalinowski wants to merge 23 commits into
mainfrom
detect

Conversation

@dkalinowski

Copy link
Copy Markdown
Collaborator

No description provided.

@dkalinowski dkalinowski requested a review from mzegla June 22, 2026 13:41
Base automatically changed from vlm-python-jinja to main June 23, 2026 10:07
Copilot AI review requested due to automatic review settings June 23, 2026 11:27
@dkalinowski dkalinowski added the WIP Do not merge until resolved label Jun 23, 2026
@dkalinowski dkalinowski changed the title [integration-branch] Auto parser detect / auto input-workaround detection Auto parser detect / auto input-workaround detection Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds chat-template capability detection plus request “input workarounds” so OVMS can (a) auto-pick tool/reasoning parsers from the template and (b) normalize incoming requests to match template expectations (e.g., Gemma4 object arguments, Llama3 non-null content) across both Python/Jinja and GenAI C++ paths.

Changes:

  • Introduces ChatTemplateAnalyzer + ChatTemplateCaps and wires analysis into servable initialization for auto-detecting model family/tool parser/reasoning parser.
  • Adds input_workarounds module and applies it before chat template rendering (JSON for Jinja; ChatHistory for GenAI).
  • Adds unit tests + Bazel targets for analyzer/workaround behavior, and updates example templates/docs.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/test/llm/input_workarounds_test.cpp New unit tests for JSON-path workarounds (object args, non-null content, applyToJson).
src/test/llm/chat_template_analyzer_test.cpp New unit tests for template-family detection and inferred caps/parsers.
src/llm/visual_language_model/legacy/servable.cpp Applies input workarounds to Jinja JSON path and GenAI ChatHistory path in VLM legacy flow.
src/llm/visual_language_model/legacy/servable_initializer.cpp Updates chat-template mode selection (but currently duplicated).
src/llm/visual_language_model/continuous_batching/servable.cpp Applies input workarounds to both Jinja JSON and GenAI ChatHistory paths in VLM CB flow.
src/llm/servable.hpp Stores analyzed template caps + detected model family in GenAiServableProperties.
src/llm/servable.cpp Applies workarounds before template application on both Jinja and GenAI paths.
src/llm/servable_initializer.cpp Runs chat template analysis at init and auto-selects tool/reasoning parser when not explicitly configured.
src/llm/llm_calculator.proto Removes an outdated TODO comment for chat template mode.
src/llm/language_model/legacy/servable_initializer.cpp Updates chat-template mode selection (but currently duplicated).
src/llm/language_model/continuous_batching/servable_initializer.cpp Updates chat-template mode selection (but currently duplicated).
src/llm/input_workarounds.hpp Declares JSON + ChatHistory workaround APIs and aggregate apply functions.
src/llm/input_workarounds.cpp Implements workarounds for JSON and ChatHistory paths (but ChatHistory mutation currently broken).
src/llm/chat_template_caps.hpp New capability struct describing template requirements/support.
src/llm/chat_template_analyzer.hpp Declares analyzer result + analyzer entrypoint.
src/llm/chat_template_analyzer.cpp Implements Tier-1 pattern matching for family/caps/parser detection.
src/llm/BUILD Adds Bazel libraries for analyzer + workarounds and links them into genai servables.
src/BUILD Adds a new test library for analyzer/workaround tests into the main test target.
extras/chat_template_examples/chat_template_qwen36.jinja Updates example template to from_json tool-call arguments before iterating.
extras/chat_template_examples/chat_template_qwen35.jinja Adds a new example template variant with the same from_json workaround.
docs/plan_chat_template_input_workarounds.md Adds a design/plan document describing detection/workaround strategy and roadmap.

Comment on lines +91 to +96
auto message = chatHistory[msgIdx];
if (!message.contains("tool_calls")) {
continue;
}
auto toolCalls = message["tool_calls"];
if (!toolCalls.is_array()) {
Comment on lines +100 to +105
auto toolCall = toolCalls[i];
if (!toolCall.is_object() || !toolCall.contains("function")) {
continue;
}
auto function = toolCall["function"];
if (!function.is_object() || !function.contains("arguments")) {
Comment on lines +108 to +112
auto args = function["arguments"];
if (!args.is_string()) {
continue;
}
std::string argsStr = args.get_string();

void ensureNonNullContentHistory(ov::genai::ChatHistory& chatHistory) {
for (size_t msgIdx = 0; msgIdx < chatHistory.size(); ++msgIdx) {
auto message = chatHistory[msgIdx];
Comment on lines +49 to +51
if (argsDoc.HasParseError()) {
continue;
}
Comment on lines +63 to +65
if (!message.IsObject() || !message.HasMember("tool_calls")) {
continue;
}
Comment on lines +89 to +90
void funcArgsToObjectHistory(ov::genai::ChatHistory& chatHistory) {
for (size_t msgIdx = 0; msgIdx < chatHistory.size(); ++msgIdx) {
Comment thread src/llm/servable.cpp
Comment on lines +188 to +192
// Apply input workarounds based on detected chat template capabilities.
// This modifies the request JSON before chat template application.
// Currently effective only on the Python Jinja path; GenAI C++ path workarounds
// will be added during the pre-processing refactoring.
auto applyInputWorkarounds = [this](const std::string& jsonBody) -> std::string {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP Do not merge until resolved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants