JacobLinCool commited on
Commit
6adc01c
·
verified ·
1 Parent(s): fde8303

fix: normalize minicpm xml tool fragments

Browse files
Files changed (1) hide show
  1. hackathon_advisor/model_runtime.py +11 -1
hackathon_advisor/model_runtime.py CHANGED
@@ -165,7 +165,8 @@ class MiniCPMTransformersPlanner:
165
  do_sample=False,
166
  )
167
  new_tokens = generated[:, inputs["input_ids"].shape[-1] :]
168
- return self._tokenizer.decode(new_tokens[0], skip_special_tokens=True).strip()
 
169
 
170
 
171
  def create_tool_planner() -> ToolPlanner:
@@ -229,6 +230,15 @@ def _strip_unused_generation_inputs(inputs: dict[str, Any]) -> None:
229
  inputs.pop("token_type_ids", None)
230
 
231
 
 
 
 
 
 
 
 
 
 
232
  def _json_string(value: str) -> str:
233
  import json
234
 
 
165
  do_sample=False,
166
  )
167
  new_tokens = generated[:, inputs["input_ids"].shape[-1] :]
168
+ decoded = self._tokenizer.decode(new_tokens[0], skip_special_tokens=True).strip()
169
+ return _normalize_xml_tool_output(decoded)
170
 
171
 
172
  def create_tool_planner() -> ToolPlanner:
 
230
  inputs.pop("token_type_ids", None)
231
 
232
 
233
+ def _normalize_xml_tool_output(output: str) -> str:
234
+ stripped = output.strip()
235
+ if stripped.startswith('name="'):
236
+ stripped = f"<function {stripped}"
237
+ if stripped.startswith("<function ") and not stripped.endswith("</function>"):
238
+ stripped = f"{stripped}</function>"
239
+ return stripped
240
+
241
+
242
  def _json_string(value: str) -> str:
243
  import json
244