Skip to content

Commit b6dcf8a

Browse files
authored
Merge pull request #36 from tokk-nv/feat/reasoning-user-prompt
feat: append reasoning prompt to user message instead of system prompt
2 parents 4cc4e38 + 7aa092b commit b6dcf8a

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/multi_modal_ai_studio/backends/llm/openai.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,22 @@ async def generate_stream(
481481
if self.config.minimal_output:
482482
suffix = " Answer with only a number or minimal tokens. No reasoning or explanation."
483483
sys_prompt = (sys_prompt or "") + suffix
484-
elif getattr(self.config, "enable_reasoning", False):
485-
reasoning_fmt = getattr(self.config, "reasoning_prompt", "") or ""
486-
if reasoning_fmt:
487-
sys_prompt = (sys_prompt or "") + reasoning_fmt
488484
if sys_prompt:
489485
messages.append({"role": "system", "content": sys_prompt})
490486

491487
# Add history
492488
if history:
493489
messages.extend(history)
494490

491+
# Append reasoning prompt to user message when enabled
492+
if (
493+
not self.config.minimal_output
494+
and getattr(self.config, "enable_reasoning", False)
495+
):
496+
reasoning_fmt = getattr(self.config, "reasoning_prompt", "") or ""
497+
if reasoning_fmt:
498+
prompt = prompt + reasoning_fmt
499+
495500
if image_data_urls and len(image_data_urls) > 0:
496501
user_content = self._build_vision_content(
497502
image_data_urls, prompt, speech_duration,

src/multi_modal_ai_studio/config/schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class LLMConfig:
161161
vision_buffer_fps: float = 3.0 # Ring buffer capture rate (fps)
162162
vision_api_format: Literal["openai", "tensorrt_edge"] = "openai"
163163
vision_video_encode: bool = False # True for models with video input (e.g. Cosmos-Reason)
164-
enable_reasoning: bool = False # True to allow <think> chain-of-thought; filtered from TTS
164+
enable_reasoning: bool = False # Append reasoning prompt to every user message; <think> output filtered from TTS
165165
reasoning_prompt: str = (
166166
"\n\nThink step-by-step inside <think> tags, then write your final answer "
167167
"immediately after </think>. The final answer MUST be exactly one descriptive "

src/multi_modal_ai_studio/webui/static/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,14 +1443,14 @@ function renderLLMConfig(config, readonly = false) {
14431443
<label class="checkbox-label">
14441444
<input type="checkbox" ${disabled} id="llm-enable-reasoning" ${config.enable_reasoning ? 'checked' : ''}
14451445
onchange="updateConfig('llm', 'enable_reasoning', this.checked); var grp = document.getElementById('reasoning-prompt-group'); grp.style.display = this.checked ? 'block' : 'none'; if (this.checked &amp;&amp; !currentConfig.llm.reasoning_prompt) { var ta = document.getElementById('llm-reasoning-prompt'); if (ta) updateConfig('llm', 'reasoning_prompt', ta.value); }">
1446-
Enable reasoning (chain-of-thought) through system prompt
1446+
Enable reasoning (chain-of-thought) through user prompt
14471447
</label>
1448-
${!readonly ? '<span class="input-hint">Appends the reasoning prompt below to the system prompt. Reasoning text is stripped before TTS.</span>' : ''}
1448+
${!readonly ? '<span class="input-hint">Appends the reasoning prompt below to every user message. Reasoning text is stripped before TTS.</span>' : ''}
14491449
<div id="reasoning-prompt-group" style="display: ${config.enable_reasoning ? 'block' : 'none'}; margin-top: 8px;">
14501450
<label>Reasoning Prompt</label>
14511451
<textarea id="llm-reasoning-prompt" ${disabled} rows="4" style="font-family: var(--font-mono); font-size: 0.85rem;" placeholder="e.g. Think step-by-step in <think>...</think> then your final answer."
14521452
onchange="updateConfig('llm', 'reasoning_prompt', this.value)">${escapeHtml(config.reasoning_prompt ?? defaultConfig.llm.reasoning_prompt ?? '')}</textarea>
1453-
${!readonly ? '<span class="input-hint">Appended to system prompt when reasoning is enabled. Customise for your model\'s format.</span>' : ''}
1453+
${!readonly ? '<span class="input-hint">Appended to every user message when reasoning is enabled. Customise for your model\'s format.</span>' : ''}
14541454
</div>
14551455
</div>
14561456

0 commit comments

Comments
 (0)