Skip to content

Commit f8a2078

Browse files
committed
Inital Hermes 3 Just in time system version - and fix to not inlcude tool prompt unless tools are provided
1 parent 5c17421 commit f8a2078

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ templates/*
197197
templates/tool_calls/*
198198
!templates/tool_calls
199199
!templates/tool_calls/chatml_with_headers.jinja
200+
!templates/tool_calls/hermes3_jitsys.jinja
200201

201202
# Sampler overrides folder
202203
sampler_overrides/*

templates/tool_calls/chatml_with_headers.jinja

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ Argument Types: Use correct data types for arguments (e.g., strings in quotes, n
5858
{%- set content = message['content'] | default('', true) | trim -%}
5959
{%- if loop.first -%}
6060
{{ bos_token }}{{ start_header }}{{ role }}{{ end_header }}
61-
{{ inital_system_prompt }}
61+
{%- if 'tools_json' in message and message['tools_json'] -%}
62+
{{ inital_system_prompt }}
63+
{%- endif -%}
6264

6365
{{ content }}{{ eos_token }}
6466
{%- endif -%}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{# Metadata #}
2+
{% set stop_strings = ["<|im_start|>", "<|im_end|>"] %}
3+
{% set message_roles = ['system', 'user', 'assistant', 'tool'] %}
4+
{% set tool_start = "<tool_call>" %}
5+
{% set tool_end = "</tool_call>" %}
6+
{% set response_start = "<tool_response>" %}
7+
{% set response_end = "</tool_response>" %}
8+
{% set sys_prompt = "" %}
9+
10+
11+
{%- set inital_system_prompt -%}
12+
You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {{ tools_json }} </tools> Use the following pydantic model json schema for each tool call you will make: {"properties": {"arguments": {"title": "Arguments", "type": "object"}, "name": {"title": "Name", "type": "string"}}, "required": ["arguments", "name"], "title": "FunctionCall", "type": "object"} For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
13+
{{ tool_start }}
14+
{"name": <function-name>, "arguments": <args-dict>}
15+
{{ tool_end }}{{ eos_token }}
16+
{%- endset -%}
17+
18+
{%- set tool_reminder -%}Available Tools:
19+
{{ tools_json }}
20+
21+
Tool Call Format Example:
22+
{{ tool_start }}{{ example_tool_call }}
23+
24+
Prefix & Suffix: Begin tool calls with {{ tool_start }} and end with {{ tool_end }}.
25+
Argument Types: Use correct data types for arguments (e.g., strings in quotes, numbers without).
26+
{%- endset -%}
27+
28+
{# Template #}
29+
30+
{%- for message in messages -%}
31+
{%- set role = message['role'] | lower -%}
32+
{%- if role not in message_roles -%}
33+
{{ raise_exception('Invalid role ' + message['role'] + '. Only ' + message_roles | join(', ') + ' are supported.') }}
34+
{%- endif -%}
35+
{%- set content = message['content'] | default('', true) | trim -%}
36+
{%- if loop.first and role == "system" -%}
37+
{%- set sys_prompt = content -%}
38+
{%- endif -%}
39+
{%- if not loop.first -%}
40+
{%- if role == 'tool' -%}
41+
{{ role }}
42+
{{ response_start}}
43+
{{ content }}
44+
{{ response_end}}
45+
{%- else -%}
46+
{{ role }}
47+
{{ content }}
48+
{%- endif -%}
49+
{%- endif -%}
50+
{%- if 'tool_calls_json' in message and message['tool_calls_json'] -%}
51+
{{ tool_start }}
52+
{{ message['tool_calls_json']}}
53+
{{ tool_end }}
54+
{%- endif -%}
55+
{{ eos_token }}
56+
{%- endfor -%}
57+
58+
{{ role }}
59+
{{ inital_system_prompt }}
60+
61+
{{ sys_prompt }}{{ eos_token }}
62+
63+
{%- if tool_precursor -%}
64+
assistant
65+
{{ tool_precursor }}{{ tool_start }}
66+
{%- else -%}
67+
assistant
68+
{%- endif -%}

0 commit comments

Comments
 (0)