meetkai-functionary-medium-v3.1.jinja 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {# version=v3-llama3.1 #}{%- if not tools is defined -%}
  2. {%- set tools = none -%}
  3. {%- endif -%}
  4. {%- set has_code_interpreter = tools | selectattr("type", "equalto", "code_interpreter") | list | length > 0 -%}
  5. {%- if has_code_interpreter -%}
  6. {%- set tools = tools | rejectattr("type", "equalto", "code_interpreter") | list -%}
  7. {%- endif -%}
  8. {#- System message + builtin tools #}
  9. {{- bos_token + "<|start_header_id|>system<|end_header_id|>\n\n" }}
  10. {%- if has_code_interpreter %}
  11. {{- "Environment: ipython\n\n" }}
  12. {%- else -%}
  13. {{ "\n"}}
  14. {%- endif %}
  15. {{- "Cutting Knowledge Date: December 2023\n\n" }}
  16. {%- if tools %}
  17. {{- "\nYou have access to the following functions:\n\n" }}
  18. {%- for t in tools %}
  19. {%- if "type" in t -%}
  20. {{ "Use the function '"|safe + t["function"]["name"] + "' to '"|safe + t["function"]["description"] + "'\n"|safe + t["function"] | tojson() }}
  21. {%- else -%}
  22. {{ "Use the function '"|safe + t["name"] + "' to '"|safe + t["description"] + "'\n"|safe + t | tojson() }}
  23. {%- endif -%}
  24. {{- "\n\n" }}
  25. {%- endfor %}
  26. {{- '\nThink very carefully before calling functions.\nIf a you choose to call a function ONLY reply in the following format:\n<{start_tag}={function_name}>{parameters}{end_tag}\nwhere\n\nstart_tag => `<function`\nparameters => a JSON dict with the function argument name as key and function argument value as value.\nend_tag => `</function>`\n\nHere is an example,\n<function=example_function_name>{"example_name": "example_value"}</function>\n\nReminder:\n- If looking for real time information use relevant functions before falling back to brave_search\n- Function calls MUST follow the specified format, start with <function= and end with </function>\n- Required parameters MUST be specified\n- Only call one function at a time\n- Put the entire function call reply on one line\n\n' -}}
  27. {%- endif %}
  28. {{- "<|eot_id|>" -}}
  29. {%- for message in messages -%}
  30. {%- if message['role'] == 'user' or message['role'] == 'system' -%}
  31. {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
  32. {%- elif message['role'] == 'tool' -%}
  33. {{ '<|start_header_id|>ipython<|end_header_id|>\n\n' + message['content'] + '<|eot_id|>' }}
  34. {%- else -%}
  35. {{ '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'}}
  36. {%- if message['content'] -%}
  37. {{ message['content'] }}
  38. {%- endif -%}
  39. {%- if 'tool_calls' in message and message['tool_calls'] -%}
  40. {%- for tool_call in message['tool_calls'] -%}
  41. {%- if tool_call["function"]["name"] == "python" -%}
  42. {{ '<|python_tag|>' + tool_call['function']['arguments'] }}
  43. {%- else -%}
  44. {{ '<function=' + tool_call['function']['name'] + '>' + tool_call['function']['arguments'] + '</function>' }}
  45. {%- endif -%}
  46. {%- endfor -%}
  47. {{ '<|eom_id|>' }}
  48. {%- else -%}
  49. {{ '<|eot_id|>' }}
  50. {%- endif -%}
  51. {%- endif -%}
  52. {%- endfor -%}
  53. {%- if add_generation_prompt -%}
  54. {{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }}
  55. {%- endif -%}