Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 345215a

Browse filesBrowse files
committed
fix: more chatml-function-calling fixes
1 parent b1637c2 commit 345215a
Copy full SHA for 345215a

File tree

Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed

‎llama_cpp/llama_chat_format.py

Copy file name to clipboardExpand all lines: llama_cpp/llama_chat_format.py
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,12 +2061,12 @@ def chatml_function_calling(
20612061
"\nfunctions.<function_name>:"
20622062
'\n{ "arg1": "value1", "arg2": "value2" }'
20632063
"{% endif %}"
2064-
"\n<|im_end|>\n"
2064+
"<|im_end|>\n"
20652065
"{% endif %}"
20662066
# User message
20672067
"{% if message.role == 'user' %}"
20682068
"{{ message.content }}"
2069-
"\n<|im_end|>\n"
2069+
"<|im_end|>\n"
20702070
"{% endif %}"
20712071
# Assistant message
20722072
"{% if message.role == 'assistant' %}"
@@ -2076,19 +2076,19 @@ def chatml_function_calling(
20762076
"message:\n"
20772077
"{% endif %}"
20782078
"{{ message.content }}"
2079-
"\n<|im_end|>\n"
2079+
"<|im_end|>\n"
20802080
"{% endif %}"
20812081
## Function calls
20822082
"{% if 'tool_calls' in message %}"
20832083
"{% for tool_call in message.tool_calls %}"
20842084
"functions.{{ tool_call.function.name }}:\n"
20852085
"{{ tool_call.function.arguments }}"
20862086
"{% endfor %}"
2087-
"\n<|im_end|>\n"
2087+
"<|im_end|>\n"
20882088
"{% endif %}"
20892089
"{% endif %}"
20902090
"{% endfor %}"
2091-
"{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}"
2091+
"{% if add_generation_prompt %}<|im_start|>assistant\n{% endif %}"
20922092
)
20932093
template_renderer = jinja2.Environment(
20942094
loader=jinja2.BaseLoader(),
@@ -2120,6 +2120,8 @@ def chatml_function_calling(
21202120
},
21212121
}
21222122

2123+
stop = [stop, "<|im_end|>"] if isinstance(stop, str) else stop + ["<|im_end|>"] if stop else ["<|im_end|>"]
2124+
21232125
# Case 1: No tool choice by user
21242126
if (
21252127
tool_choice is None

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.