meta-llama-Llama-3.2-3B-Instruct.jinja 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {{- bos_token }}
  2. {%- if custom_tools is defined %}
  3. {%- set tools = custom_tools %}
  4. {%- endif %}
  5. {%- if not tools_in_user_message is defined %}
  6. {%- set tools_in_user_message = true %}
  7. {%- endif %}
  8. {%- if not date_string is defined %}
  9. {%- if strftime_now is defined %}
  10. {%- set date_string = strftime_now("%d %b %Y") %}
  11. {%- else %}
  12. {%- set date_string = "26 Jul 2024" %}
  13. {%- endif %}
  14. {%- endif %}
  15. {%- if not tools is defined %}
  16. {%- set tools = none %}
  17. {%- endif %}
  18. {#- This block extracts the system message, so we can slot it into the right place. #}
  19. {%- if messages[0]['role'] == 'system' %}
  20. {%- set system_message = messages[0]['content']|trim %}
  21. {%- set messages = messages[1:] %}
  22. {%- else %}
  23. {%- set system_message = "" %}
  24. {%- endif %}
  25. {#- System message #}
  26. {{- "<|start_header_id|>system<|end_header_id|>\n\n" }}
  27. {%- if tools is not none %}
  28. {{- "Environment: ipython\n" }}
  29. {%- endif %}
  30. {{- "Cutting Knowledge Date: December 2023\n" }}
  31. {{- "Today Date: " + date_string + "\n\n" }}
  32. {%- if tools is not none and not tools_in_user_message %}
  33. {{- "You have access to the following functions. To call a function, please respond with JSON for a function call." }}
  34. {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
  35. {{- "Do not use variables.\n\n" }}
  36. {%- for t in tools %}
  37. {{- t | tojson(indent=4) }}
  38. {{- "\n\n" }}
  39. {%- endfor %}
  40. {%- endif %}
  41. {{- system_message }}
  42. {{- "<|eot_id|>" }}
  43. {#- Custom tools are passed in a user message with some extra guidance #}
  44. {%- if tools_in_user_message and not tools is none %}
  45. {#- Extract the first user message so we can plug it in here #}
  46. {%- if messages | length != 0 %}
  47. {%- set first_user_message = messages[0]['content']|trim %}
  48. {%- set messages = messages[1:] %}
  49. {%- else %}
  50. {{- raise_exception("Cannot put tools in the first user message when there's no first user message!") }}
  51. {%- endif %}
  52. {{- '<|start_header_id|>user<|end_header_id|>\n\n' -}}
  53. {{- "Given the following functions, please respond with a JSON for a function call " }}
  54. {{- "with its proper arguments that best answers the given prompt.\n\n" }}
  55. {{- 'Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.' }}
  56. {{- "Do not use variables.\n\n" }}
  57. {%- for t in tools %}
  58. {{- t | tojson(indent=4) }}
  59. {{- "\n\n" }}
  60. {%- endfor %}
  61. {{- first_user_message + "<|eot_id|>"}}
  62. {%- endif %}
  63. {%- for message in messages %}
  64. {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}
  65. {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' }}
  66. {%- elif 'tool_calls' in message %}
  67. {%- if not message.tool_calls|length == 1 %}
  68. {{- raise_exception("This model only supports single tool-calls at once!") }}
  69. {%- endif %}
  70. {%- set tool_call = message.tool_calls[0].function %}
  71. {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
  72. {{- '{"name": "' + tool_call.name + '", ' }}
  73. {{- '"parameters": ' }}
  74. {{- tool_call.arguments | tojson }}
  75. {{- "}" }}
  76. {{- "<|eot_id|>" }}
  77. {%- elif message.role == "tool" or message.role == "ipython" %}
  78. {{- "<|start_header_id|>ipython<|end_header_id|>\n\n" }}
  79. {%- if message.content is mapping or message.content is iterable %}
  80. {{- message.content | tojson }}
  81. {%- else %}
  82. {{- message.content }}
  83. {%- endif %}
  84. {{- "<|eot_id|>" }}
  85. {%- endif %}
  86. {%- endfor %}
  87. {%- if add_generation_prompt %}
  88. {{- '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
  89. {%- endif %}