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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
def convert_dataset_example_to_api_format(item: Dict[str, Any]) -> Dict[str, Any]:
|
| 246 |
"""Convert dataset example to API format"""
|
| 247 |
# Convert tools format
|
|
@@ -348,39 +603,9 @@ async def get_examples():
|
|
| 348 |
continue
|
| 349 |
print(f"Generated {len(examples)} random examples from dataset")
|
| 350 |
else:
|
| 351 |
-
# Fallback to hardcoded examples if dataset not available
|
| 352 |
-
print("Using hardcoded fallback examples")
|
| 353 |
-
examples =
|
| 354 |
-
{
|
| 355 |
-
"name": "Correct Example",
|
| 356 |
-
"description": "A properly formed tool call",
|
| 357 |
-
"expected_output": "Correct",
|
| 358 |
-
"data": {
|
| 359 |
-
"query": "What's the weather in New York?",
|
| 360 |
-
"enabled_tools": [
|
| 361 |
-
{
|
| 362 |
-
"name": "get_weather",
|
| 363 |
-
"description": "Get current weather for a location",
|
| 364 |
-
"parameters": {
|
| 365 |
-
"type": "object",
|
| 366 |
-
"properties": {
|
| 367 |
-
"location": {"type": "string"},
|
| 368 |
-
"units": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
| 369 |
-
},
|
| 370 |
-
"required": ["location"]
|
| 371 |
-
}
|
| 372 |
-
}
|
| 373 |
-
],
|
| 374 |
-
"tool_calling": {
|
| 375 |
-
"name": "get_weather",
|
| 376 |
-
"arguments": {
|
| 377 |
-
"location": "New York",
|
| 378 |
-
"units": "fahrenheit"
|
| 379 |
-
}
|
| 380 |
-
}
|
| 381 |
-
}
|
| 382 |
-
}
|
| 383 |
-
]
|
| 384 |
|
| 385 |
# Shuffle examples to randomize order
|
| 386 |
random.shuffle(examples)
|
|
|
|
| 242 |
return None
|
| 243 |
|
| 244 |
|
| 245 |
+
def get_fallback_examples() -> List[Dict[str, Any]]:
|
| 246 |
+
"""Return hardcoded examples for all label types"""
|
| 247 |
+
return [
|
| 248 |
+
{
|
| 249 |
+
"name": "Correct Example",
|
| 250 |
+
"description": "A properly formed tool call",
|
| 251 |
+
"expected_output": "Correct",
|
| 252 |
+
"data": {
|
| 253 |
+
"query": "What's the weather in New York?",
|
| 254 |
+
"enabled_tools": [
|
| 255 |
+
{
|
| 256 |
+
"name": "get_weather",
|
| 257 |
+
"description": "Get current weather for a location",
|
| 258 |
+
"parameters": {
|
| 259 |
+
"type": "object",
|
| 260 |
+
"properties": {
|
| 261 |
+
"location": {"type": "string"},
|
| 262 |
+
"units": {"type": "string", "enum": ["celsius", "fahrenheit"]}
|
| 263 |
+
},
|
| 264 |
+
"required": ["location"]
|
| 265 |
+
}
|
| 266 |
+
}
|
| 267 |
+
],
|
| 268 |
+
"tool_calling": {
|
| 269 |
+
"name": "get_weather",
|
| 270 |
+
"arguments": {
|
| 271 |
+
"location": "New York",
|
| 272 |
+
"units": "fahrenheit"
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
}
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"name": "Incorrect Function Name Example",
|
| 279 |
+
"description": "Tool call uses incorrect function name",
|
| 280 |
+
"expected_output": "Incorrect_Function_Name",
|
| 281 |
+
"data": {
|
| 282 |
+
"query": "Calculate 25 * 4",
|
| 283 |
+
"enabled_tools": [
|
| 284 |
+
{
|
| 285 |
+
"name": "calculator",
|
| 286 |
+
"description": "Perform calculations",
|
| 287 |
+
"parameters": {
|
| 288 |
+
"type": "object",
|
| 289 |
+
"properties": {
|
| 290 |
+
"expression": {"type": "string"}
|
| 291 |
+
},
|
| 292 |
+
"required": ["expression"]
|
| 293 |
+
}
|
| 294 |
+
}
|
| 295 |
+
],
|
| 296 |
+
"tool_calling": {
|
| 297 |
+
"name": "calculate", # Wrong name!
|
| 298 |
+
"arguments": {
|
| 299 |
+
"expression": "25 * 4"
|
| 300 |
+
}
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
},
|
| 304 |
+
{
|
| 305 |
+
"name": "Incorrect Argument Type Example",
|
| 306 |
+
"description": "Argument has wrong data type",
|
| 307 |
+
"expected_output": "Incorrect_Argument_Type",
|
| 308 |
+
"data": {
|
| 309 |
+
"query": "Set a reminder for 3pm",
|
| 310 |
+
"enabled_tools": [
|
| 311 |
+
{
|
| 312 |
+
"name": "set_reminder",
|
| 313 |
+
"description": "Create a reminder",
|
| 314 |
+
"parameters": {
|
| 315 |
+
"type": "object",
|
| 316 |
+
"properties": {
|
| 317 |
+
"time": {"type": "string"},
|
| 318 |
+
"message": {"type": "string"}
|
| 319 |
+
},
|
| 320 |
+
"required": ["time", "message"]
|
| 321 |
+
}
|
| 322 |
+
}
|
| 323 |
+
],
|
| 324 |
+
"tool_calling": {
|
| 325 |
+
"name": "set_reminder",
|
| 326 |
+
"arguments": {
|
| 327 |
+
"time": 1500, # Should be string!
|
| 328 |
+
"message": "Meeting"
|
| 329 |
+
}
|
| 330 |
+
}
|
| 331 |
+
}
|
| 332 |
+
},
|
| 333 |
+
{
|
| 334 |
+
"name": "Incorrect Argument Name Example",
|
| 335 |
+
"description": "Argument name doesn't match tool parameters",
|
| 336 |
+
"expected_output": "Incorrect_Argument_Name",
|
| 337 |
+
"data": {
|
| 338 |
+
"query": "Send an email to john@example.com",
|
| 339 |
+
"enabled_tools": [
|
| 340 |
+
{
|
| 341 |
+
"name": "send_email",
|
| 342 |
+
"description": "Send an email message",
|
| 343 |
+
"parameters": {
|
| 344 |
+
"type": "object",
|
| 345 |
+
"properties": {
|
| 346 |
+
"recipient": {"type": "string"},
|
| 347 |
+
"subject": {"type": "string"},
|
| 348 |
+
"body": {"type": "string"}
|
| 349 |
+
},
|
| 350 |
+
"required": ["recipient", "subject"]
|
| 351 |
+
}
|
| 352 |
+
}
|
| 353 |
+
],
|
| 354 |
+
"tool_calling": {
|
| 355 |
+
"name": "send_email",
|
| 356 |
+
"arguments": {
|
| 357 |
+
"to": "john@example.com", # Wrong name! Should be "recipient"
|
| 358 |
+
"subject": "Hello",
|
| 359 |
+
"body": "Test message"
|
| 360 |
+
}
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
},
|
| 364 |
+
{
|
| 365 |
+
"name": "Incorrect Argument Value Example",
|
| 366 |
+
"description": "Argument value doesn't match expected format",
|
| 367 |
+
"expected_output": "Incorrect_Argument_Value",
|
| 368 |
+
"data": {
|
| 369 |
+
"query": "Get weather in Celsius",
|
| 370 |
+
"enabled_tools": [
|
| 371 |
+
{
|
| 372 |
+
"name": "get_weather",
|
| 373 |
+
"description": "Get current weather for a location",
|
| 374 |
+
"parameters": {
|
| 375 |
+
"type": "object",
|
| 376 |
+
"properties": {
|
| 377 |
+
"location": {"type": "string"},
|
| 378 |
+
"units": {"type": "string", "enum": ["celsius", "fahrenheit", "kelvin"]}
|
| 379 |
+
},
|
| 380 |
+
"required": ["location"]
|
| 381 |
+
}
|
| 382 |
+
}
|
| 383 |
+
],
|
| 384 |
+
"tool_calling": {
|
| 385 |
+
"name": "get_weather",
|
| 386 |
+
"arguments": {
|
| 387 |
+
"location": "London",
|
| 388 |
+
"units": "centigrade" # Wrong value! Not in enum
|
| 389 |
+
}
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
},
|
| 393 |
+
{
|
| 394 |
+
"name": "Wrong Tool Example",
|
| 395 |
+
"description": "Wrong tool selected for the task",
|
| 396 |
+
"expected_output": "Wrong_Tool",
|
| 397 |
+
"data": {
|
| 398 |
+
"query": "What's the weather in Paris?",
|
| 399 |
+
"enabled_tools": [
|
| 400 |
+
{
|
| 401 |
+
"name": "get_weather",
|
| 402 |
+
"description": "Get current weather for a location",
|
| 403 |
+
"parameters": {
|
| 404 |
+
"type": "object",
|
| 405 |
+
"properties": {
|
| 406 |
+
"location": {"type": "string"}
|
| 407 |
+
},
|
| 408 |
+
"required": ["location"]
|
| 409 |
+
}
|
| 410 |
+
},
|
| 411 |
+
{
|
| 412 |
+
"name": "search_web",
|
| 413 |
+
"description": "Search the web for information",
|
| 414 |
+
"parameters": {
|
| 415 |
+
"type": "object",
|
| 416 |
+
"properties": {
|
| 417 |
+
"query": {"type": "string"}
|
| 418 |
+
},
|
| 419 |
+
"required": ["query"]
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
],
|
| 423 |
+
"tool_calling": {
|
| 424 |
+
"name": "search_web", # Wrong tool! Should use get_weather
|
| 425 |
+
"arguments": {
|
| 426 |
+
"query": "weather in Paris"
|
| 427 |
+
}
|
| 428 |
+
}
|
| 429 |
+
}
|
| 430 |
+
},
|
| 431 |
+
{
|
| 432 |
+
"name": "Wrong Syntax Example",
|
| 433 |
+
"description": "Tool call syntax is malformed",
|
| 434 |
+
"expected_output": "Wrong_Syntax",
|
| 435 |
+
"data": {
|
| 436 |
+
"query": "Calculate 10 + 5",
|
| 437 |
+
"enabled_tools": [
|
| 438 |
+
{
|
| 439 |
+
"name": "calculator",
|
| 440 |
+
"description": "Perform mathematical calculations",
|
| 441 |
+
"parameters": {
|
| 442 |
+
"type": "object",
|
| 443 |
+
"properties": {
|
| 444 |
+
"expression": {"type": "string"}
|
| 445 |
+
},
|
| 446 |
+
"required": ["expression"]
|
| 447 |
+
}
|
| 448 |
+
}
|
| 449 |
+
],
|
| 450 |
+
"tool_calling": {
|
| 451 |
+
"name": "calculator",
|
| 452 |
+
"arguments": {
|
| 453 |
+
"expression": ["10", "+", "5"] # Wrong type! Should be string
|
| 454 |
+
}
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
},
|
| 458 |
+
{
|
| 459 |
+
"name": "No Tool Available Example",
|
| 460 |
+
"description": "No matching tool exists for the request",
|
| 461 |
+
"expected_output": "No_Tool_Available",
|
| 462 |
+
"data": {
|
| 463 |
+
"query": "Translate 'Hello' to Spanish",
|
| 464 |
+
"enabled_tools": [
|
| 465 |
+
{
|
| 466 |
+
"name": "get_weather",
|
| 467 |
+
"description": "Get current weather for a location",
|
| 468 |
+
"parameters": {
|
| 469 |
+
"type": "object",
|
| 470 |
+
"properties": {
|
| 471 |
+
"location": {"type": "string"}
|
| 472 |
+
},
|
| 473 |
+
"required": ["location"]
|
| 474 |
+
}
|
| 475 |
+
},
|
| 476 |
+
{
|
| 477 |
+
"name": "calculator",
|
| 478 |
+
"description": "Perform mathematical calculations",
|
| 479 |
+
"parameters": {
|
| 480 |
+
"type": "object",
|
| 481 |
+
"properties": {
|
| 482 |
+
"expression": {"type": "string"}
|
| 483 |
+
},
|
| 484 |
+
"required": ["expression"]
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
],
|
| 488 |
+
"tool_calling": {
|
| 489 |
+
"name": "translate", # Tool doesn't exist in enabled_tools!
|
| 490 |
+
"arguments": {
|
| 491 |
+
"text": "Hello",
|
| 492 |
+
"target_language": "Spanish"
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
}
|
| 496 |
+
}
|
| 497 |
+
]
|
| 498 |
+
|
| 499 |
+
|
| 500 |
def convert_dataset_example_to_api_format(item: Dict[str, Any]) -> Dict[str, Any]:
|
| 501 |
"""Convert dataset example to API format"""
|
| 502 |
# Convert tools format
|
|
|
|
| 603 |
continue
|
| 604 |
print(f"Generated {len(examples)} random examples from dataset")
|
| 605 |
else:
|
| 606 |
+
# Fallback to hardcoded examples for ALL labels if dataset not available
|
| 607 |
+
print("Using hardcoded fallback examples for all labels")
|
| 608 |
+
examples = get_fallback_examples()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 609 |
|
| 610 |
# Shuffle examples to randomize order
|
| 611 |
random.shuffle(examples)
|