[Mirror] server : refactor oai_parser_opt, move it to server_chat_params#83
[Mirror] server : refactor oai_parser_opt, move it to server_chat_params#83
Conversation
📝 WalkthroughWalkthroughThe PR refactors chat template handling by converting Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@tools/server/server-common.h`:
- Around line 277-286: The struct server_chat_params currently relies on
external aggregate initialization; add in-class value defaults to make it
resilient by initializing POD members and containers directly in the struct
definition: set booleans like use_jinja, prefill_assistant, allow_image,
allow_audio to false, initialize enable_thinking = true (preserve current),
initialize media_path to an empty string, default-construct chat_template_kwargs
(std::map) and tmpls (common_chat_templates_ptr) and give a sensible default or
zero-init for reasoning_format; update the declaration of server_chat_params so
these defaults exist inline to ensure deterministic values even if init() is not
called.
🧹 Nitpick comments (2)
tools/server/server-context.h (1)
23-25: Consider makingchat_paramsa const reference.
server_context_metais described as read-only; using a non-const reference permits accidental mutation through meta. A const reference would enforce intent.🔧 Suggested change
- server_chat_params & chat_params; + const server_chat_params & chat_params;tools/server/server-context.cpp (1)
3184-3186: Unusual but intentional variable shadowing pattern.This pattern of declaring
bool ctx_serverto shadow the member variable is an unconventional way to prevent accidental usage during sleeping state. The comment "do NOT delete this line" makes the intent clear.While this works, it's a bit fragile - if someone adds
(void)ctx_server;or usesthis->ctx_server, the protection is bypassed.Consider a more robust approach like extracting these sleep-safe handlers to a separate class or using a static helper, but this is low priority given the clear warning comment.
| struct server_chat_params { | ||
| bool use_jinja; | ||
| bool prefill_assistant; | ||
| common_reasoning_format reasoning_format; | ||
| std::map<std::string,std::string> chat_template_kwargs; | ||
| common_chat_templates * tmpls; | ||
| std::map<std::string, std::string> chat_template_kwargs; // mapping key --> json value | ||
| common_chat_templates_ptr tmpls; | ||
| bool allow_image; | ||
| bool allow_audio; | ||
| bool enable_thinking = true; | ||
| std::string media_path; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
rg -n -C3 '\bserver_chat_params\b' --type-list | head -20Repository: ngxson/llama.cpp
Length of output: 449
🏁 Script executed:
rg -n -C5 '\bserver_chat_params\b' -t cpp -t hRepository: ngxson/llama.cpp
Length of output: 3512
🏁 Script executed:
rg -n -C10 'server_chat_params chat_params' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 774
🏁 Script executed:
rg -n 'chat_params\s*=' -A2 -B2 tools/server/server-context.cpp | head -40Repository: ngxson/llama.cpp
Length of output: 336
🏁 Script executed:
sed -n '895,925p' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 1403
🏁 Script executed:
rg -n 'chat_params' tools/server/server-context.cpp | head -30Repository: ngxson/llama.cpp
Length of output: 1122
🏁 Script executed:
sed -n '880,920p' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 2147
🏁 Script executed:
rg -n 'struct server_context_impl' tools/server/server-context.cpp -A30 | head -50Repository: ngxson/llama.cpp
Length of output: 1092
🏁 Script executed:
sed -n '850,880p' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 1021
🏁 Script executed:
rg -n 'void.*init\|bool.*init' tools/server/server-context.cpp | head -15Repository: ngxson/llama.cpp
Length of output: 42
🏁 Script executed:
sed -n '820,860p' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 1566
🏁 Script executed:
grep -n "populate chat template params" tools/server/server-context.cpp -B30 | head -40Repository: ngxson/llama.cpp
Length of output: 1174
🏁 Script executed:
sed -n '847,950p' tools/server/server-context.cppRepository: ngxson/llama.cpp
Length of output: 4167
Consider in-class value-initialization for server_chat_params fields.
While the struct is properly initialized via aggregate initialization in init() before any use, relying on this pattern is fragile. Adding in-class defaults (e.g., bool use_jinja = false;) would make the struct more resilient and ensure deterministic values even if initialization paths change. Currently, POD types have indeterminate values from line 538 until the assignment at line 900, and the code depends on init() always being called.
🤖 Prompt for AI Agents
In `@tools/server/server-common.h` around lines 277 - 286, The struct
server_chat_params currently relies on external aggregate initialization; add
in-class value defaults to make it resilient by initializing POD members and
containers directly in the struct definition: set booleans like use_jinja,
prefill_assistant, allow_image, allow_audio to false, initialize enable_thinking
= true (preserve current), initialize media_path to an empty string,
default-construct chat_template_kwargs (std::map) and tmpls
(common_chat_templates_ptr) and give a sensible default or zero-init for
reasoning_format; update the declaration of server_chat_params so these defaults
exist inline to ensure deterministic values even if init() is not called.
Mirror from upstream PR: ggml-org#18937
Note: @coderabbitai use my 'Mirror PR' preset for reviewing this.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.