Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: tell Gemma 4 with Think off and GLM today's date (#14013)
Nilay254b253514f8
diff --git a/studio/backend/tests/test_current_date_prompt_settings.py b/studio/backend/tests/test_current_date_prompt_settings.pyindex da4faab67b9..d2672069796 100644--- a/studio/backend/tests/test_current_date_prompt_settings.py+++ b/studio/backend/tests/test_current_date_prompt_settings.py@@ -418,6 +418,17 @@ _GEMMA_LIKE = ("{% if loop.first %}{{ first }}{% endif %}{{ m['content'] }}<end_of_turn>\n{% endfor %}")+_GEMMA4_LIKE = (+ "{{ bos_token }}{% set loop_messages = messages %}"+ "{% set system = messages and messages[0]['role'] == 'system' %}"+ "{% if enable_thinking or system %}<|turn>system\n"+ "{% if enable_thinking %}<|think|>\n{% endif %}{% if system %}"+ "{{ messages[0]['content'] }}{% set loop_messages = messages[1:] %}{% endif %}<turn|>\n"+ "{% endif %}{% for m in loop_messages %}<|turn>{{ m['role'] }}\n{{ m['content'] }}<turn|>\n"+ "{% endfor %}"+)+_GLM_LIKE = "[gMASK]<sop>{% for m in messages %}<|{{ m['role'] }}|>{{ m['content'] }}{% endfor %}"+_REFUSES_SYSTEM = ("{% if messages[0]['role'] == 'system' %}{{ raise_exception('no system') }}{% endif %}"@@ -451,6 +462,11 @@ class TestTemplateSystemTurn:def test_templates_without_a_default_return_nothing(self, template):assert _turn(template) == (True, "")+ @pytest.mark.parametrize("template", ["{{ bos_token }}" + _CHATML, _GLM_LIKE, _GEMMA4_LIKE])+ @pytest.mark.parametrize("thinking", [False, True])+ def test_a_fixed_prefix_is_not_a_default(self, template, thinking):+ assert _turn(template, controls = (("enable_thinking", thinking),)) == (True, "")+def test_a_default_that_dates_itself_is_dated_for_the_given_day(self):dated = _QWEN25_LIKE.replace("You are Qwen, a helpful assistant.",@@ -748,6 +764,26 @@ class TestDateStaysInTheSystemTurn:out = self.inference._prepend_current_date_to_messages(history, object())assert out == [{"role": "system", "content": "The current date is 2026-10-04."}, *history]+ def test_a_fixed_prefix_template_without_thinking_gets_the_date(self, monkeypatch):+ from types import SimpleNamespace++ line = self.inference.current_date_prompt_line+ monkeypatch.undo()+ monkeypatch.setattr(self.inference, "current_date_prompt_line", line)+ monkeypatch.setattr(self.inference, "_request_has_api_key", lambda _request: False)+ llama = SimpleNamespace(+ is_loaded = True,+ chat_template = _GEMMA4_LIKE,+ chat_template_override = None,+ extra_args = [],+ )+ monkeypatch.setattr(self.inference, "get_llama_cpp_backend", lambda: llama)+ controls = (("enable_thinking", False),)+ assert (+ self.inference._apply_current_date_prompt("", object(), controls = controls)+ == "The current date is 2026-10-04."+ )+def test_a_disabled_setting_adds_nothing(self, monkeypatch):monkeypatch.setattr(self.inference, "current_date_prompt_line", lambda **_kwargs: "")assert self.inference._apply_current_date_prompt("", object()) == ""diff --git a/studio/backend/utils/current_date_prompt_settings.py b/studio/backend/utils/current_date_prompt_settings.pyindex 0540391095d..4b77a393785 100644--- a/studio/backend/utils/current_date_prompt_settings.py+++ b/studio/backend/utils/current_date_prompt_settings.py@@ -217,6 +217,7 @@ def template_system_turn(catalog = PROBE_TOOLS if tools else Nonekwargs = dict(controls)renders_chat = False+ prefix = None# some templates read message text only from content parts, as a vision processor sends it.for content in (lambda text: text, lambda text: [{"type": "text", "text": text}]):user = {"role": "user", "content": content(_PROBE_USER)}@@ -240,6 +241,15 @@ def template_system_turn(without_system = head + tailif _is_whitespace_normalized_substring(bare, without_system):return True, ""+ if prefix is None:+ try:+ prefix = _render_probe(chat_template, [], today, catalog, kwargs)+ except Exception:+ prefix = ""+ # what the template writes before any message, like BOS or GLM's [gMASK]<sop>, is no turn.+ fixed = len(prefix) if bare.startswith(prefix) and head.startswith(prefix) else 0+ if fixed and _is_whitespace_normalized_substring(bare[fixed:], without_system[fixed:]):+ return True, ""if len(bare) <= len(without_system) or not bare.startswith(head) or not bare.endswith(tail):# The explicit-system branch changes more than inserting the supplied text. Treat its# native default as non-replayable instead of silently replacing it with the date.