make empty block conditional

This commit is contained in:
Devon Rifkin
2026-04-15 15:35:25 -07:00
parent e585ecd11f
commit 9e3618d663
2 changed files with 8 additions and 1 deletions

View File

@@ -125,7 +125,7 @@ func (r *Gemma4Renderer) Render(messages []api.Message, tools []api.Tool, thinkV
// Generation prompt. // Generation prompt.
if prevMessageType != "tool_response" && prevMessageType != "tool_call" { if prevMessageType != "tool_response" && prevMessageType != "tool_call" {
sb.WriteString("<|turn>model\n") sb.WriteString("<|turn>model\n")
if r.emptyBlockOnNothink { if r.emptyBlockOnNothink && !hasThink {
sb.WriteString("<|channel>thought\n<channel|>") sb.WriteString("<|channel>thought\n<channel|>")
} }
} }

View File

@@ -1508,6 +1508,13 @@ func TestGemma4RendererVariantsMatchExpectedGenerationPrompt(t *testing.T) {
} }
} }
func TestGemma4LargeRendererOmitsEmptyThoughtBlockWhenThinkingEnabled(t *testing.T) {
got, err := RenderWithRenderer("gemma4-large", []api.Message{{Role: "user", Content: "Hello"}}, nil, thinkTrue())
assert.NoError(t, err)
assert.Equal(t, "<bos><|turn>system\n<|think|>\n<turn|>\n<|turn>user\nHello<turn|>\n<|turn>model\n", got)
assert.NotContains(t, got, "<|channel>thought\n<channel|>")
}
func TestGemma4RendererMatchesJinja2ExpandedParity(t *testing.T) { func TestGemma4RendererMatchesJinja2ExpandedParity(t *testing.T) {
if os.Getenv("VERIFY_JINJA2") == "" { if os.Getenv("VERIFY_JINJA2") == "" {
t.Skip("set VERIFY_JINJA2=1 to run expanded Jinja2 parity checks") t.Skip("set VERIFY_JINJA2=1 to run expanded Jinja2 parity checks")