akseljoonas HF Staff commited on
Commit
f6a5c51
·
1 Parent(s): f6b02f3

Fix example message selection and show as JSON with all keys

Browse files
Files changed (1) hide show
  1. agent/tools/dataset_tools.py +15 -20
agent/tools/dataset_tools.py CHANGED
@@ -289,40 +289,35 @@ def _format_messages_structure(messages_data: Any) -> str | None:
289
  # Show example message structure
290
  # Priority: 1) message with tool_calls, 2) first assistant message, 3) first non-system message
291
  example = None
 
292
  for msg in messages_data:
293
  if not isinstance(msg, dict):
294
  continue
295
  role = msg.get("role", "")
296
- if "tool_calls" in msg or "function_call" in msg:
 
297
  example = msg
298
  break
299
  if role == "assistant" and example is None:
300
  example = msg
301
- if role != "system" and example is None:
302
- example = msg
 
 
303
 
304
  if example:
305
  lines.append("")
306
  lines.append("**Example message structure:**")
 
 
307
  for key, val in example.items():
308
- if key == "content":
309
- val_preview = (
310
- str(val)[:100] + "..." if len(str(val)) > 100 else str(val)
311
- )
312
- lines.append(f" - {key}: {val_preview}")
313
- elif key == "tool_calls" and isinstance(val, list) and val:
314
- lines.append(f" - {key}: [{len(val)} tool call(s)]")
315
- # Show first tool call structure
316
- if isinstance(val[0], dict):
317
- tc = val[0]
318
- lines.append(f" - type: {tc.get('type', 'function')}")
319
- if "function" in tc:
320
- lines.append(
321
- f" - function.name: {tc['function'].get('name', '?')}"
322
- )
323
- lines.append(" - function.arguments: <json string>")
324
  else:
325
- lines.append(f" - {key}: {val}")
 
 
 
326
 
327
  return "\n".join(lines)
328
 
 
289
  # Show example message structure
290
  # Priority: 1) message with tool_calls, 2) first assistant message, 3) first non-system message
291
  example = None
292
+ fallback = None
293
  for msg in messages_data:
294
  if not isinstance(msg, dict):
295
  continue
296
  role = msg.get("role", "")
297
+ # Check for actual tool_calls/function_call values (not None)
298
+ if msg.get("tool_calls") or msg.get("function_call"):
299
  example = msg
300
  break
301
  if role == "assistant" and example is None:
302
  example = msg
303
+ elif role != "system" and fallback is None:
304
+ fallback = msg
305
+ if example is None:
306
+ example = fallback
307
 
308
  if example:
309
  lines.append("")
310
  lines.append("**Example message structure:**")
311
+ # Build a copy with truncated content but keep all keys
312
+ example_clean = {}
313
  for key, val in example.items():
314
+ if key == "content" and isinstance(val, str) and len(val) > 100:
315
+ example_clean[key] = val[:100] + "..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  else:
317
+ example_clean[key] = val
318
+ lines.append("```json")
319
+ lines.append(json.dumps(example_clean, indent=2, ensure_ascii=False))
320
+ lines.append("```")
321
 
322
  return "\n".join(lines)
323