DiTy commited on
Commit
ae42366
·
verified ·
1 Parent(s): 0d9a052

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +437 -1
README.md CHANGED
@@ -209,7 +209,7 @@ ChatCompletionMessage(
209
 
210
  ## Tool Planning Examples <a name="examples"></a>
211
 
212
- The model is using *grounded system prompt* for tool planning. <u>We do not recommend changing it too much, as this may cause hallucinations!</u>
213
 
214
  ```
215
  <|im_start|>system
@@ -251,28 +251,464 @@ Each tool is represented as a JSON object with fields like "name", "description"
251
  ```
252
  *For corrected display used [\ \`] instead of [\`]*
253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
  ### Simple Function
255
 
 
256
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  ```
259
 
260
  ### Multiple Function
261
 
 
262
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  ```
265
 
266
  ### Parallel Multiple Function
267
 
 
268
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  ```
271
 
272
  ### Tool Error Handling
273
 
 
274
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  ```
277
 
278
 
 
209
 
210
  ## Tool Planning Examples <a name="examples"></a>
211
 
212
+ The model is using ***grounded system prompt*** for tool planning. <u>We do not recommend changing it too much, as this may cause hallucinations!</u>
213
 
214
  ```
215
  <|im_start|>system
 
251
  ```
252
  *For corrected display used [\ \`] instead of [\`]*
253
 
254
+ **About the structure of prompt:**
255
+ - This model always will answer with new tokens: `<|start_response|>`...*text from model*...`<|end_response|>`. This content is the main one for user and it contains in `assistant` in `content` field.
256
+ - This model always starts <u>*thinking*</u> before tool calls with new tokens: `<|start_thinking|>`...*thinking*...<|end_thinking|>. It contains in `assistant` in `tool_plan` field.
257
+ - After <u>*thinking*</u> model starts generate tool calls (function calling) with Qwen2.5 tokens (it can be a multiple/parallel calling too):
258
+ ```
259
+ <tool_call>[
260
+ {"tool_call_id": "...", "tool_name": "...", "parameters": {...}},
261
+ {"tool_call_id": "...", "tool_name": "...", "parameters": {...}},
262
+ ...
263
+ ]</tool_call><|im_end|>
264
+ ```
265
+ `tool_call_id` is local tool id.
266
+ `tool_name` is name of tool(function) calling.
267
+ It contains in `assistant` in 'tool_calls' field.
268
+
269
+ - Responses from tools are located between `<tool_response>`...*all last locals tools*...`</tool_response>`. Every local tool contains separately in specific role `tool`:
270
+ ```python
271
+ {
272
+ "role": "tool",
273
+ "tool_call_id": "0", # MUST BE matches with the corresponding call above.
274
+ "content": { "tool_name_1_returns": ... } # MUST BE dict with key "tool_name" + "_returns"
275
+ },
276
+ {
277
+ "role": "tool",
278
+ "tool_call_id": "1", # MUST BE matches with the corresponding call above.
279
+ "content": { "tool_name_1_returns": ... }
280
+ },
281
+ {
282
+ "role": "tool",
283
+ "tool_call_id": "2", # MUST BE matches with the corresponding call above.
284
+ "content": { "tool_name_2_returns": ... },
285
+ "is_error_tool": True # You can add it if your tool is corrupted. But then you must provide error description in content.
286
+ }
287
+ ```
288
+ Local tool ids mean that ids must match only in one pair *tool call* and *tool response*, next *tool call* must reset the counter and start from 0 again.
289
+
290
  ### Simple Function
291
 
292
+ *history*
293
  ```python
294
+ messages = [
295
+ {"role": "user", "content": "Hey dude, what can you do?"},
296
+ {"role": "assistant", "content": "I can retrieve a list of unpaid invoices and process payments for specific invoices."},
297
+ {"role": "user", "content": "Okey, then retrieve a list for me"},
298
+ {
299
+ "role": "assistant",
300
+ "tool_plan": "I will retrieve a list of unpaid invoices.",
301
+ "tool_calls": [
302
+ {
303
+ "id": "0",
304
+ "type": "function",
305
+ "function": {
306
+ "name": "find_unpaid_invoices",
307
+ "arguments": {}
308
+ }
309
+ }
310
+ ]
311
+ },
312
+ {
313
+ "role": "tool",
314
+ "tool_call_id": "0",
315
+ "content": { "find_unpaid_invoices_returns": ["Utility Debts", "Housing and Utilities Arrears"]}
316
+ },
317
+ {"role": "assistant", "content": "Here is the list of unpaid invoices: Utility Debts and Housing and Utilities Arrears."},
318
+ {"role": "user", "content": "Ooh, I forget about this! Lets pay Utility Debts in the amount of $100 please"},
319
+ {
320
+ "role": "assistant",
321
+ "tool_plan": "I will process the payment for the Utility Debts invoice.",
322
+ "tool_calls": [
323
+ {
324
+ "id": "0",
325
+ "type": "function",
326
+ "function": {
327
+ "name": "pay_invoice",
328
+ "arguments": {"invoice_id": "Utility Debts", "amount": 100}
329
+ }
330
+ }
331
+ ]
332
+ },
333
+ {
334
+ "role": "tool",
335
+ "tool_call_id": "0",
336
+ "content": { "pay_invoice_returns": "Success"}
337
+ },
338
+ ]
339
+ ```
340
+
341
+ *prompt with generation*
342
+ ```
343
+ <|im_start|>system
344
+ ...grounded_system_prompt...
345
 
346
+ <|im_end|>
347
+ <|im_start|>user
348
+ Hey dude, what can you do?<|im_end|>
349
+ <|im_start|>assistant
350
+ <|start_response|>I can retrieve a list of unpaid invoices and process payments for specific invoices.<|end_response|><|im_end|>
351
+ <|im_start|>user
352
+ Okey, then retrieve a list for me<|im_end|>
353
+ <|im_start|>assistant
354
+ <|start_thinking|>I will retrieve a list of unpaid invoices.<|end_thinking|><tool_call>[
355
+ {"tool_call_id": "0", "tool_name": "find_unpaid_invoices", "parameters": {}}
356
+ ]</tool_call><|im_end|>
357
+ <|im_start|>system
358
+ <tool_response>[
359
+ {
360
+ "tool_call_id": "0",
361
+ "results": {
362
+ "0": {"find_unpaid_invoices_returns": ["Utility Debts", "Housing and Utilities Arrears"]}
363
+ },
364
+ "is_error_tool": False
365
+ }
366
+ ]</tool_response><|im_end|>
367
+ <|im_start|>assistant
368
+ <|start_response|>Here is the list of unpaid invoices: Utility Debts and Housing and Utilities Arrears.<|end_response|><|im_end|>
369
+ <|im_start|>user
370
+ Ooh, I forget about this! Lets pay Utility Debts in the amount of $100 please<|im_end|>
371
+ <|im_start|>assistant
372
+ <|start_thinking|>I will process the payment for the Utility Debts invoice.<|end_thinking|><tool_call>[
373
+ {"tool_call_id": "0", "tool_name": "pay_invoice", "parameters": {"invoice_id": "Utility Debts", "amount": 100}}
374
+ ]</tool_call><|im_end|>
375
+ <|im_start|>system
376
+ <tool_response>[
377
+ {
378
+ "tool_call_id": "0",
379
+ "results": {
380
+ "0": {"pay_invoice_returns": "Success"}
381
+ },
382
+ "is_error_tool": False
383
+ }
384
+ ]</tool_response><|im_end|>
385
+ <|im_start|>assistant
386
+ <|start_response|>The payment for the Utility Debts invoice has been processed successfully.<|end_response|><|im_end|>
387
  ```
388
 
389
  ### Multiple Function
390
 
391
+ *history*
392
  ```python
393
+ messages = [
394
+ {"role": "user", "content": "Hey dude, what can you do?"},
395
+ {"role": "assistant", "content": "I can provide weather information for a given city and also provide the sunrise and sunset times for a given city."},
396
+ {"role": "user", "content": "Thats great! Okey, can you provide weather in Krasnodar, Moscow and Krasnoyarsk for me please."},
397
+ {
398
+ "role": "assistant",
399
+ "tool_plan": "The user wants weather information for three cities: Krasnodar, Moscow, and Krasnoyarsk.",
400
+ "tool_calls": [
401
+ {
402
+ "id": "0",
403
+ "type": "function",
404
+ "function": {
405
+ "name": "get_weather",
406
+ "arguments": {
407
+ "city": "Krasnodar"
408
+ }
409
+ }
410
+ },
411
+ {
412
+ "id": "1",
413
+ "type": "function",
414
+ "function": {
415
+ "name": "get_weather",
416
+ "arguments": {
417
+ "city": "Moscow"
418
+ }
419
+ }
420
+ },
421
+ {
422
+ "id": "2",
423
+ "type": "function",
424
+ "function": {
425
+ "name": "get_weather",
426
+ "arguments": {
427
+ "city": "Krasnoyarsk"
428
+ }
429
+ }
430
+ },
431
+ ]
432
+ },
433
+ {
434
+ "role": "tool",
435
+ "tool_call_id": "0",
436
+ "content": { "get_weather_returns": "sunny" }
437
+ },
438
+ {
439
+ "role": "tool",
440
+ "tool_call_id": "1",
441
+ "content": { "get_weather_returns": "sunny" }
442
+ },
443
+ {
444
+ "role": "tool",
445
+ "tool_call_id": "2",
446
+ "content": { "get_weather_returns": "rainy" }
447
+ },
448
+ ]
449
+ ```
450
 
451
+ *prompt with generation*
452
+ ```
453
+ <|im_start|>system
454
+ ...grounded_system_prompt...
455
+
456
+ <|im_end|>
457
+ <|im_start|>user
458
+ Hey dude, what can you do?<|im_end|>
459
+ <|im_start|>assistant
460
+ <|start_response|>I can provide weather information for a given city and also provide the sunrise and sunset times for a given city.<|end_response|><|im_end|>
461
+ <|im_start|>user
462
+ Thats great! Okey, can you provide weather in Krasnodar, Moscow and Krasnoyarsk for me please.<|im_end|>
463
+ <|im_start|>assistant
464
+ <|start_thinking|>The user wants weather information for three cities: Krasnodar, Moscow, and Krasnoyarsk.<|end_thinking|><tool_call>[
465
+ {"tool_call_id": "0", "tool_name": "get_weather", "parameters": {"city": "Krasnodar"}},
466
+ {"tool_call_id": "1", "tool_name": "get_weather", "parameters": {"city": "Moscow"}},
467
+ {"tool_call_id": "2", "tool_name": "get_weather", "parameters": {"city": "Krasnoyarsk"}}
468
+ ]</tool_call><|im_end|>
469
+ <|im_start|>system
470
+ <tool_response>[
471
+ {
472
+ "tool_call_id": "0",
473
+ "results": {
474
+ "0": {"get_weather_returns": "sunny"}
475
+ },
476
+ "is_error_tool": False
477
+ },
478
+ {
479
+ "tool_call_id": "1",
480
+ "results": {
481
+ "0": {"get_weather_returns": "sunny"}
482
+ },
483
+ "is_error_tool": False
484
+ },
485
+ {
486
+ "tool_call_id": "2",
487
+ "results": {
488
+ "0": {"get_weather_returns": "rainy"}
489
+ },
490
+ "is_error_tool": False
491
+ }
492
+ ]</tool_response><|im_end|>
493
+ <|im_start|>assistant
494
+ <|start_response|>The weather in Krasnodar is sunny, the weather in Moscow is sunny, and the weather in Krasnoyarsk is rainy.<|end_response|><|im_end|>
495
  ```
496
 
497
  ### Parallel Multiple Function
498
 
499
+ *history*
500
  ```python
501
+ messages = [
502
+ {"role": "user", "content": "Hey dude, what can you do?"},
503
+ {"role": "assistant", "content": "I can provide weather information for a given city and also provide the sunrise and sunset times for a given city."},
504
+ {"role": "user", "content": "Thats great! Okey, can you provide weather in Krasnodar, Moscow and only the sunrise time in Krasnoyarsk for me please."},
505
+ {
506
+ "role": "assistant",
507
+ "tool_plan": "The user has requested weather information for three cities and only the sunrise time for one city. I will first retrieve the weather information for Krasnodar and Moscow, and then retrieve the sunrise time for Krasnoyarsk.",
508
+ "tool_calls": [
509
+ {
510
+ "id": "0",
511
+ "type": "function",
512
+ "function": {
513
+ "name": "get_weather",
514
+ "arguments": {
515
+ "city": "Krasnodar"
516
+ }
517
+ }
518
+ },
519
+ {
520
+ "id": "1",
521
+ "type": "function",
522
+ "function": {
523
+ "name": "get_weather",
524
+ "arguments": {
525
+ "city": "Moscow"
526
+ }
527
+ }
528
+ },
529
+ {
530
+ "id": "2",
531
+ "type": "function",
532
+ "function": {
533
+ "name": "get_sunrise_sunset_times",
534
+ "arguments": {
535
+ "city": "Krasnoyarsk"
536
+ }
537
+ }
538
+ },
539
+ ]
540
+ },
541
+ {
542
+ "role": "tool",
543
+ "tool_call_id": "0",
544
+ "content": { "get_weather_returns": "sunny" }
545
+ },
546
+ {
547
+ "role": "tool",
548
+ "tool_call_id": "1",
549
+ "content": { "get_weather_returns": "sunny" }
550
+ },
551
+ {
552
+ "role": "tool",
553
+ "tool_call_id": "2",
554
+ "content": { "get_sunrise_sunset_times_returns": ["6:00 AM", "6:00 PM"] }
555
+ },
556
+ ]
557
+ ```
558
 
559
+ *prompt with generation*
560
+ ```
561
+ <|im_start|>system
562
+ ...grounded_system_prompt...
563
+
564
+ <|im_end|>
565
+ <|im_start|>user
566
+ Hey dude, what can you do?<|im_end|>
567
+ <|im_start|>assistant
568
+ <|start_response|>I can provide weather information for a given city and also provide the sunrise and sunset times for a given city.<|end_response|><|im_end|>
569
+ <|im_start|>user
570
+ Thats great! Okey, can you provide weather in Krasnodar, Moscow and only the sunrise time in Krasnoyarsk for me please.<|im_end|>
571
+ <|im_start|>assistant
572
+ <|start_thinking|>The user has requested weather information for three cities and only the sunrise time for one city. I will first retrieve the weather information for Krasnodar and Moscow, and then retrieve the sunrise time for Krasnoyarsk.<|end_thinking|><tool_call>[
573
+ {"tool_call_id": "0", "tool_name": "get_weather", "parameters": {"city": "Krasnodar"}},
574
+ {"tool_call_id": "1", "tool_name": "get_weather", "parameters": {"city": "Moscow"}},
575
+ {"tool_call_id": "2", "tool_name": "get_sunrise_sunset_times", "parameters": {"city": "Krasnoyarsk"}}
576
+ ]</tool_call><|im_end|>
577
+ <|im_start|>system
578
+ <tool_response>[
579
+ {
580
+ "tool_call_id": "0",
581
+ "results": {
582
+ "0": {"get_weather_returns": "sunny"}
583
+ },
584
+ "is_error_tool": False
585
+ },
586
+ {
587
+ "tool_call_id": "1",
588
+ "results": {
589
+ "0": {"get_weather_returns": "sunny"}
590
+ },
591
+ "is_error_tool": False
592
+ },
593
+ {
594
+ "tool_call_id": "2",
595
+ "results": {
596
+ "0": {"get_sunrise_sunset_times_returns": ["6:00 AM", "6:00 PM"]}
597
+ },
598
+ "is_error_tool": False
599
+ }
600
+ ]</tool_response><|im_end|>
601
+ <|im_start|>assistant
602
+ <|start_response|>The weather in Krasnodar is sunny, the weather in Moscow is sunny, and the sunrise time in Krasnoyarsk is 6:00 AM.<|end_response|><|im_end|>
603
  ```
604
 
605
  ### Tool Error Handling
606
 
607
+ *history*
608
  ```python
609
+ messages = [
610
+ {"role": "user", "content": "Hey dude, what can you do?"},
611
+ {"role": "assistant", "content": "I can provide weather information for a given city and also provide the sunrise and sunset times for a given city."},
612
+ {"role": "user", "content": "Thats great! Okey, can you provide weather in Krasnodar, Moscow and only the sunrise time in Krasnoyarsk for me please."},
613
+ {
614
+ "role": "assistant",
615
+ "tool_plan": "The user has requested weather information for three cities and only the sunrise time for one city. I will first retrieve the weather information for Krasnodar and Moscow, and then retrieve the sunrise time for Krasnoyarsk.",
616
+ "tool_calls": [
617
+ {
618
+ "id": "0",
619
+ "type": "function",
620
+ "function": {
621
+ "name": "get_weather",
622
+ "arguments": {
623
+ "city": "Krasnodar"
624
+ }
625
+ }
626
+ },
627
+ {
628
+ "id": "1",
629
+ "type": "function",
630
+ "function": {
631
+ "name": "get_weather",
632
+ "arguments": {
633
+ "city": "Moscow"
634
+ }
635
+ }
636
+ },
637
+ {
638
+ "id": "2",
639
+ "type": "function",
640
+ "function": {
641
+ "name": "get_sunrise_sunset_times",
642
+ "arguments": {
643
+ "city": "Krasnoyarsk"
644
+ }
645
+ }
646
+ },
647
+ ]
648
+ },
649
+ {
650
+ "role": "tool",
651
+ "tool_call_id": "0",
652
+ "content": { "get_weather_returns": "sunny" }
653
+ },
654
+ {
655
+ "role": "tool",
656
+ "tool_call_id": "1",
657
+ "content": { "get_weather_returns": "sunny" }
658
+ },
659
+ {
660
+ "role": "tool",
661
+ "tool_call_id": "2",
662
+ "content": { "get_sunrise_sunset_times_returns": {"error": True, "message": "Server is unavailable now"} },
663
+ "is_error_tool": True
664
+ },
665
+ ]
666
+ ```
667
 
668
+ *prompt with generation*
669
+ ```
670
+ <|im_start|>system
671
+ ...grounded_system_prompt...
672
+
673
+ <|im_end|>
674
+ <|im_start|>user
675
+ Hey dude, what can you do?<|im_end|>
676
+ <|im_start|>assistant
677
+ <|start_response|>I can provide weather information for a given city and also provide the sunrise and sunset times for a given city.<|end_response|><|im_end|>
678
+ <|im_start|>user
679
+ Thats great! Okey, can you provide weather in Krasnodar, Moscow and only the sunrise time in Krasnoyarsk for me please.<|im_end|>
680
+ <|im_start|>assistant
681
+ <|start_thinking|>The user has requested weather information for three cities and only the sunrise time for one city. I will first retrieve the weather information for Krasnodar and Moscow, and then retrieve the sunrise time for Krasnoyarsk.<|end_thinking|><tool_call>[
682
+ {"tool_call_id": "0", "tool_name": "get_weather", "parameters": {"city": "Krasnodar"}},
683
+ {"tool_call_id": "1", "tool_name": "get_weather", "parameters": {"city": "Moscow"}},
684
+ {"tool_call_id": "2", "tool_name": "get_sunrise_sunset_times", "parameters": {"city": "Krasnoyarsk"}}
685
+ ]</tool_call><|im_end|>
686
+ <|im_start|>system
687
+ <tool_response>[
688
+ {
689
+ "tool_call_id": "0",
690
+ "results": {
691
+ "0": {"get_weather_returns": "sunny"}
692
+ },
693
+ "is_error_tool": False
694
+ },
695
+ {
696
+ "tool_call_id": "1",
697
+ "results": {
698
+ "0": {"get_weather_returns": "sunny"}
699
+ },
700
+ "is_error_tool": False
701
+ },
702
+ {
703
+ "tool_call_id": "2",
704
+ "results": {
705
+ "0": {"get_sunrise_sunset_times_returns": {"error": true, "message": "Server is unavailable now"}}
706
+ },
707
+ "is_error_tool": True
708
+ }
709
+ ]</tool_response><|im_end|>
710
+ <|im_start|>assistant
711
+ <|start_response|>The weather in Krasnodar and Moscow is sunny. Unfortunately, the server is currently unavailable, so I cannot provide the sunrise time for Krasnoyarsk.<|end_response|><|im_end|>
712
  ```
713
 
714