Update chat_template.jinja
Browse files- chat_template.jinja +30 -7
chat_template.jinja
CHANGED
|
@@ -1,16 +1,20 @@
|
|
| 1 |
{%- macro json_to_python_type(json_spec) -%}
|
| 2 |
{%- set basic_type_map = {"string": "str", "number": "float", "integer": "int", "boolean": "bool"} -%}
|
| 3 |
-
{%- if basic_type_map[json_spec.type] is defined -%}
|
| 4 |
{{- basic_type_map[json_spec.type] -}}
|
| 5 |
-
{%- elif json_spec.type == "array" -%}
|
|
|
|
| 6 |
{{- "list[" + json_to_python_type(json_spec.items) + "]" -}}
|
| 7 |
-
{%-
|
|
|
|
|
|
|
|
|
|
| 8 |
{%- if json_spec.additionalProperties is defined -%}
|
| 9 |
{{- "dict[str, " + json_to_python_type(json_spec.additionalProperties) + "]" -}}
|
| 10 |
{%- else -%}
|
| 11 |
{{- "dict" -}}
|
| 12 |
{%- endif -%}
|
| 13 |
-
{%- elif json_spec.type is iterable -%}
|
| 14 |
{{- "Union[" -}}
|
| 15 |
{%- for t in json_spec.type -%}
|
| 16 |
{{- json_to_python_type({"type": t}) -}}
|
|
@@ -30,24 +34,41 @@
|
|
| 30 |
{%- for tool in tools -%}
|
| 31 |
{%- set t = tool.function if tool.function is defined else tool -%}
|
| 32 |
{{- '{"type": "function", "function": {"name": "' + t.name + '", "description": "' + t.name + '(' -}}
|
|
|
|
| 33 |
{%- for param_name, param_fields in t.parameters.properties.items() -%}
|
| 34 |
{{- param_name + ": " + json_to_python_type(param_fields) -}}
|
| 35 |
{%- if not loop.last -%}, {%- endif -%}
|
| 36 |
{%- endfor -%}
|
|
|
|
| 37 |
{{- ")" -}}
|
| 38 |
{%- if t.return is defined -%}
|
| 39 |
{{- " -> " + json_to_python_type(t.return) -}}
|
| 40 |
{%- endif -%}
|
| 41 |
-
{{- " - "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
{%- for param_name, param_fields in t.parameters.properties.items() -%}
|
| 43 |
-
{{- " " + param_name + "(" + json_to_python_type(param_fields) + "): "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
{%- if not loop.last -%}\n{%- endif -%}
|
| 45 |
{%- endfor -%}
|
|
|
|
|
|
|
|
|
|
| 46 |
{%- if t.return is defined and t.return.description is defined -%}
|
| 47 |
{{- "\n Returns:\n " + t.return.description -}}
|
| 48 |
{%- endif -%}
|
| 49 |
{{- '", "parameters": ' -}}
|
| 50 |
-
{%- if t.parameters.properties|length > 0 -%}
|
| 51 |
{{- t.parameters|tojson -}}
|
| 52 |
{%- else -%}
|
| 53 |
{{- "{}" -}}
|
|
@@ -67,6 +88,7 @@
|
|
| 67 |
{{- '<|start_header_id|>' + message.role + '<|end_header_id|>\n\n' + message.content + '<|eot_id|>' -}}
|
| 68 |
{%- elif message.role == "assistant" -%}
|
| 69 |
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
|
|
|
|
| 70 |
{%- for tool_call in message.tool_calls -%}
|
| 71 |
{%- set tc = tool_call.function if tool_call.function is defined else tool_call -%}
|
| 72 |
{{- '<tool_call>\n{"name": "' + tc.name + '", "arguments": ' -}}
|
|
@@ -77,6 +99,7 @@
|
|
| 77 |
{%- endif -%}
|
| 78 |
{{- '}\n</tool_call>' -}}
|
| 79 |
{%- endfor -%}
|
|
|
|
| 80 |
{{- '<|eot_id|>' -}}
|
| 81 |
{%- elif message.role == "tool" -%}
|
| 82 |
{%- if loop.previtem and loop.previtem.role != "tool" -%}
|
|
|
|
| 1 |
{%- macro json_to_python_type(json_spec) -%}
|
| 2 |
{%- set basic_type_map = {"string": "str", "number": "float", "integer": "int", "boolean": "bool"} -%}
|
| 3 |
+
{%- if json_spec.type is defined and basic_type_map[json_spec.type] is defined -%}
|
| 4 |
{{- basic_type_map[json_spec.type] -}}
|
| 5 |
+
{%- elif json_spec.type is defined and json_spec.type == "array" -%}
|
| 6 |
+
{%- if json_spec.items is defined -%}
|
| 7 |
{{- "list[" + json_to_python_type(json_spec.items) + "]" -}}
|
| 8 |
+
{%- else -%}
|
| 9 |
+
{{- "list" -}}
|
| 10 |
+
{%- endif -%}
|
| 11 |
+
{%- elif json_spec.type is defined and json_spec.type == "object" -%}
|
| 12 |
{%- if json_spec.additionalProperties is defined -%}
|
| 13 |
{{- "dict[str, " + json_to_python_type(json_spec.additionalProperties) + "]" -}}
|
| 14 |
{%- else -%}
|
| 15 |
{{- "dict" -}}
|
| 16 |
{%- endif -%}
|
| 17 |
+
{%- elif json_spec.type is defined and json_spec.type is iterable and json_spec.type is not string -%}
|
| 18 |
{{- "Union[" -}}
|
| 19 |
{%- for t in json_spec.type -%}
|
| 20 |
{{- json_to_python_type({"type": t}) -}}
|
|
|
|
| 34 |
{%- for tool in tools -%}
|
| 35 |
{%- set t = tool.function if tool.function is defined else tool -%}
|
| 36 |
{{- '{"type": "function", "function": {"name": "' + t.name + '", "description": "' + t.name + '(' -}}
|
| 37 |
+
{%- if t.parameters is defined and t.parameters.properties is defined -%}
|
| 38 |
{%- for param_name, param_fields in t.parameters.properties.items() -%}
|
| 39 |
{{- param_name + ": " + json_to_python_type(param_fields) -}}
|
| 40 |
{%- if not loop.last -%}, {%- endif -%}
|
| 41 |
{%- endfor -%}
|
| 42 |
+
{%- endif -%}
|
| 43 |
{{- ")" -}}
|
| 44 |
{%- if t.return is defined -%}
|
| 45 |
{{- " -> " + json_to_python_type(t.return) -}}
|
| 46 |
{%- endif -%}
|
| 47 |
+
{{- " - " -}}
|
| 48 |
+
{%- if t.description is defined -%}
|
| 49 |
+
{{- t.description -}}
|
| 50 |
+
{%- else -%}
|
| 51 |
+
{{- "No description available" -}}
|
| 52 |
+
{%- endif -%}
|
| 53 |
+
{{- "\n\n Args:\n" -}}
|
| 54 |
+
{%- if t.parameters is defined and t.parameters.properties is defined -%}
|
| 55 |
{%- for param_name, param_fields in t.parameters.properties.items() -%}
|
| 56 |
+
{{- " " + param_name + "(" + json_to_python_type(param_fields) + "): " -}}
|
| 57 |
+
{%- if param_fields.description is defined -%}
|
| 58 |
+
{{- param_fields.description -}}
|
| 59 |
+
{%- else -%}
|
| 60 |
+
{{- "No description available" -}}
|
| 61 |
+
{%- endif -%}
|
| 62 |
{%- if not loop.last -%}\n{%- endif -%}
|
| 63 |
{%- endfor -%}
|
| 64 |
+
{%- else -%}
|
| 65 |
+
{{- " No parameters" -}}
|
| 66 |
+
{%- endif -%}
|
| 67 |
{%- if t.return is defined and t.return.description is defined -%}
|
| 68 |
{{- "\n Returns:\n " + t.return.description -}}
|
| 69 |
{%- endif -%}
|
| 70 |
{{- '", "parameters": ' -}}
|
| 71 |
+
{%- if t.parameters is defined and t.parameters.properties is defined and t.parameters.properties|length > 0 -%}
|
| 72 |
{{- t.parameters|tojson -}}
|
| 73 |
{%- else -%}
|
| 74 |
{{- "{}" -}}
|
|
|
|
| 88 |
{{- '<|start_header_id|>' + message.role + '<|end_header_id|>\n\n' + message.content + '<|eot_id|>' -}}
|
| 89 |
{%- elif message.role == "assistant" -%}
|
| 90 |
{{- '<|start_header_id|>assistant<|end_header_id|>\n\n' -}}
|
| 91 |
+
{%- if message.tool_calls is defined -%}
|
| 92 |
{%- for tool_call in message.tool_calls -%}
|
| 93 |
{%- set tc = tool_call.function if tool_call.function is defined else tool_call -%}
|
| 94 |
{{- '<tool_call>\n{"name": "' + tc.name + '", "arguments": ' -}}
|
|
|
|
| 99 |
{%- endif -%}
|
| 100 |
{{- '}\n</tool_call>' -}}
|
| 101 |
{%- endfor -%}
|
| 102 |
+
{%- endif -%}
|
| 103 |
{{- '<|eot_id|>' -}}
|
| 104 |
{%- elif message.role == "tool" -%}
|
| 105 |
{%- if loop.previtem and loop.previtem.role != "tool" -%}
|