Skip to content

Commit 090a894

Browse files
Fix const parsing for dict inputs in chat schemas (#41824)
* Fix const parsing for dict inputs * make fixup
1 parent 4faf675 commit 090a894

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/transformers/utils/chat_parsing_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,12 @@ def recursive_parse(
173173
return parsed_schema
174174
elif isinstance(node_content, dict):
175175
for key, child_node in node_schema.get("properties", {}).items():
176-
if key in node_content:
176+
if "const" in child_node:
177+
parsed_schema[key] = child_node["const"]
178+
elif key in node_content:
177179
parsed_schema[key] = recursive_parse(node_content[key], child_node)
178180
elif "default" in child_node:
179181
parsed_schema[key] = child_node["default"]
180-
else:
181-
pass
182182
if "additionalProperties" in node_schema:
183183
for key, value in node_content.items():
184184
if key not in node_schema.get("properties", {}):

tests/utils/test_chat_schema_utils.py renamed to tests/utils/test_chat_parsing_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def test_smollm_template_thinking_and_tool_call(self):
281281
self.assertEqual(
282282
parsed_chat,
283283
{
284+
"role": "assistant",
284285
"thinking": 'Okay, the user said, "Hello! How are you?" I need to respond appropriately. Since this is the first message, I should greet them back and ask how I can assist. I should keep it friendly and open-ended. Let me make sure the response is welcoming and encourages them to share what they need help with. I\'ll avoid any technical jargon and keep it simple. Let me check for any typos and ensure the tone is positive.',
285286
"tool_calls": [
286287
{
@@ -302,9 +303,10 @@ def test_smollm_template_tool_call_no_thinking(self):
302303
self.assertEqual(
303304
parsed_chat,
304305
{
306+
"role": "assistant",
305307
"tool_calls": [
306308
{"type": "function", "function": {"name": "get_weather", "arguments": {"city": "Paris"}}}
307-
]
309+
],
308310
},
309311
)
310312

@@ -314,6 +316,7 @@ def test_smollm_template_thinking_no_tool_call(self):
314316
self.assertEqual(
315317
parsed_chat,
316318
{
319+
"role": "assistant",
317320
"content": "Some content about gravity goes here but I'm cutting it off to make this shorter!",
318321
"thinking": 'Okay, the user asked, "Hey! Can you tell me about gravity?" Let me start by breaking down what they might be looking for. They probably want a basic understanding of gravity, maybe for a school project or just personal curiosity. I should explain what gravity is, how it works, and maybe some examples.',
319322
},
@@ -325,6 +328,7 @@ def test_qwen3_tool_calls(self):
325328
self.assertEqual(
326329
parsed_chat,
327330
{
331+
"role": "assistant",
328332
"tool_calls": [
329333
{
330334
"type": "function",
@@ -336,6 +340,6 @@ def test_qwen3_tool_calls(self):
336340
},
337341
},
338342
}
339-
]
343+
],
340344
},
341345
)

0 commit comments

Comments
 (0)