Update chat_template.jinja
#28
by
mahmoudhas9
- opened
- chat_template.jinja +46 -32
chat_template.jinja
CHANGED
|
@@ -1,12 +1,17 @@
|
|
| 1 |
-
{% macro
|
| 2 |
-
{%- if
|
| 3 |
-
{%-
|
| 4 |
-
{
|
| 5 |
-
{
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
{%- endif %}
|
| 11 |
{% endmacro %}
|
| 12 |
|
|
@@ -29,37 +34,46 @@
|
|
| 29 |
{%- endif %}
|
| 30 |
{%- endif %}
|
| 31 |
{%- if tools is iterable and tools | length > 0 %}
|
| 32 |
-
{{- "\n\
|
| 33 |
{{- "<tools>" }}
|
| 34 |
{%- for tool in tools %}
|
| 35 |
{%- if tool.function is defined %}
|
| 36 |
{%- set tool = tool.function %}
|
| 37 |
{%- endif %}
|
| 38 |
{{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
|
| 39 |
-
{
|
| 40 |
-
{{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
|
| 41 |
-
{%- endif %}
|
| 42 |
{{- '\n<parameters>' }}
|
| 43 |
-
{%-
|
| 44 |
-
{
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
{
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
{
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
{%- endif %}
|
| 53 |
-
{%- set handled_keys = ['name', 'type', 'description'] %}
|
| 54 |
-
{{- render_extra_keys(param_fields, handled_keys) }}
|
| 55 |
-
{{- '\n</parameter>' }}
|
| 56 |
{%- endfor %}
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
{
|
|
|
|
| 60 |
{{- '\n</parameters>' }}
|
| 61 |
-
{%-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
{{- '\n</function>' }}
|
| 64 |
{%- endfor %}
|
| 65 |
{{- "\n</tools>" }}
|
|
@@ -86,7 +100,7 @@
|
|
| 86 |
{%- if tool_call.arguments is defined %}
|
| 87 |
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 88 |
{{- '<parameter=' + args_name + '>\n' }}
|
| 89 |
-
{%- set args_value = args_value
|
| 90 |
{{- args_value }}
|
| 91 |
{{- '\n</parameter>\n' }}
|
| 92 |
{%- endfor %}
|
|
@@ -114,4 +128,4 @@
|
|
| 114 |
{%- endfor %}
|
| 115 |
{%- if add_generation_prompt %}
|
| 116 |
{{- '<|im_start|>assistant\n' }}
|
| 117 |
-
{%- endif %}
|
|
|
|
| 1 |
+
{% macro render_item_list(item_list, tag_name='required') %}
|
| 2 |
+
{%- if item_list is defined and item_list is iterable and item_list | length > 0 %}
|
| 3 |
+
{%- if tag_name %}{{- '\n<' ~ tag_name ~ '>' -}}{% endif %}
|
| 4 |
+
{{- '[' }}
|
| 5 |
+
{%- for item in item_list -%}
|
| 6 |
+
{%- if loop.index > 1 %}{{- ", "}}{% endif -%}
|
| 7 |
+
{%- if item is string -%}
|
| 8 |
+
{{ "`" ~ item ~ "`" }}
|
| 9 |
+
{%- else -%}
|
| 10 |
+
{{ item }}
|
| 11 |
+
{%- endif -%}
|
| 12 |
+
{%- endfor -%}
|
| 13 |
+
{{- ']' }}
|
| 14 |
+
{%- if tag_name %}{{- '</' ~ tag_name ~ '>' -}}{% endif %}
|
| 15 |
{%- endif %}
|
| 16 |
{% endmacro %}
|
| 17 |
|
|
|
|
| 34 |
{%- endif %}
|
| 35 |
{%- endif %}
|
| 36 |
{%- if tools is iterable and tools | length > 0 %}
|
| 37 |
+
{{- "\n\nYou have access to the following functions:\n\n" }}
|
| 38 |
{{- "<tools>" }}
|
| 39 |
{%- for tool in tools %}
|
| 40 |
{%- if tool.function is defined %}
|
| 41 |
{%- set tool = tool.function %}
|
| 42 |
{%- endif %}
|
| 43 |
{{- "\n<function>\n<name>" ~ tool.name ~ "</name>" }}
|
| 44 |
+
{{- '\n<description>' ~ (tool.description | trim) ~ '</description>' }}
|
|
|
|
|
|
|
| 45 |
{{- '\n<parameters>' }}
|
| 46 |
+
{%- for param_name, param_fields in tool.parameters.properties|items %}
|
| 47 |
+
{{- '\n<parameter>' }}
|
| 48 |
+
{{- '\n<name>' ~ param_name ~ '</name>' }}
|
| 49 |
+
{%- if param_fields.type is defined %}
|
| 50 |
+
{{- '\n<type>' ~ (param_fields.type | string) ~ '</type>' }}
|
| 51 |
+
{%- endif %}
|
| 52 |
+
{%- if param_fields.description is defined %}
|
| 53 |
+
{{- '\n<description>' ~ (param_fields.description | trim) ~ '</description>' }}
|
| 54 |
+
{%- endif %}
|
| 55 |
+
{{- render_item_list(param_fields.enum, 'enum') }}
|
| 56 |
+
{%- set handled_keys = ['type', 'description', 'enum', 'required'] %}
|
| 57 |
+
{%- for json_key in param_fields.keys() | reject("in", handled_keys) %}
|
| 58 |
+
{%- set normed_json_key = json_key | replace("-", "_") | replace(" ", "_") | replace("$", "") %}
|
| 59 |
+
{%- if param_fields[json_key] is mapping %}
|
| 60 |
+
{{- '\n<' ~ normed_json_key ~ '>' ~ (param_fields[json_key] | tojson | safe) ~ '</' ~ normed_json_key ~ '>' }}
|
| 61 |
+
{%- else %}
|
| 62 |
+
{{-'\n<' ~ normed_json_key ~ '>' ~ (param_fields[json_key] | string) ~ '</' ~ normed_json_key ~ '>' }}
|
| 63 |
{%- endif %}
|
|
|
|
|
|
|
|
|
|
| 64 |
{%- endfor %}
|
| 65 |
+
{{- render_item_list(param_fields.required, 'required') }}
|
| 66 |
+
{{- '\n</parameter>' }}
|
| 67 |
+
{%- endfor %}
|
| 68 |
+
{{- render_item_list(tool.parameters.required, 'required') }}
|
| 69 |
{{- '\n</parameters>' }}
|
| 70 |
+
{%- if tool.return is defined %}
|
| 71 |
+
{%- if tool.return is mapping %}
|
| 72 |
+
{{- '\n<return>' ~ (tool.return | tojson | safe) ~ '</return>' }}
|
| 73 |
+
{%- else %}
|
| 74 |
+
{{- '\n<return>' ~ (tool.return | string) ~ '</return>' }}
|
| 75 |
+
{%- endif %}
|
| 76 |
+
{%- endif %}
|
| 77 |
{{- '\n</function>' }}
|
| 78 |
{%- endfor %}
|
| 79 |
{{- "\n</tools>" }}
|
|
|
|
| 100 |
{%- if tool_call.arguments is defined %}
|
| 101 |
{%- for args_name, args_value in tool_call.arguments|items %}
|
| 102 |
{{- '<parameter=' + args_name + '>\n' }}
|
| 103 |
+
{%- set args_value = args_value if args_value is string else args_value | string %}
|
| 104 |
{{- args_value }}
|
| 105 |
{{- '\n</parameter>\n' }}
|
| 106 |
{%- endfor %}
|
|
|
|
| 128 |
{%- endfor %}
|
| 129 |
{%- if add_generation_prompt %}
|
| 130 |
{{- '<|im_start|>assistant\n' }}
|
| 131 |
+
{%- endif %}
|