Skip to content

Commit caec4ef

Browse files
committed
improve gguf-function-calling parser
1 parent c3112c7 commit caec4ef

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4295,15 +4295,17 @@ def gguf_function_calling(
42954295
)
42964296
initial_gbnf_tool_grammar = (
42974297
(
4298-
'root ::= message_only | message_with_functions | functions_only\n'
4299-
'message_only ::= "message:" text\n'
4300-
'message_with_functions ::= "message:" text "<function_calls>\\n" functions\n'
4301-
'functions_only ::= "<function_calls>\\n" functions\n'
4298+
'root ::= message_only | message_with_functions | functions_only\n'
4299+
'message_only ::= "message:" ws text\n'
4300+
'message_with_functions ::= "message:" ws text ws "<function_calls>" nl functions\n'
4301+
'functions_only ::= "<function_calls>" nl functions\n'
43024302
'text ::= [^<]+\n'
4303+
'ws ::= [ \t\n]*\n'
4304+
'nl ::= "\\n"\n'
43034305
f"functions ::= {function_names}\n"
43044306
)
43054307
if tool_choice == "auto"
4306-
else f'root ::= "<function_calls>" "\\n" functions\nfunctions ::= {function_names}\n'
4308+
else f'root ::= "<function_calls>" nl functions\nfunctions ::= {function_names}\n'
43074309
)
43084310
completion = cast(
43094311
llama_types.CreateCompletionResponse,

0 commit comments

Comments
 (0)