Skip to content

Commit 9dc010e

Browse files
committed
improve gguf-function-calling parser
1 parent 066638c commit 9dc010e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4292,14 +4292,13 @@ def gguf_function_calling(
42924292
prompt = template_renderer.render(
42934293
messages=messages, tools=tools, tool_calls=True, add_generation_prompt=True
42944294
)
4295-
initial_gbnf_tool_grammar = (
4296-
(
4297-
'root ::= "<function_calls>" "\\n" functions | "message:"\n'
4298-
f"functions ::= {function_names}\n"
4299-
)
4300-
if tool_choice == "auto"
4301-
else f'root ::= "<function_calls>" "\\n" functions\nfunctions ::= {function_names}\n'
4302-
)
4295+
# Decide initial grammar: message only, functions only, or message+functions
4296+
initial_gbnf_tool_grammar = """
4297+
root ::= message | function_calls | message_then_functions
4298+
message ::= "message:"
4299+
function_calls ::= "<function_calls>\n"
4300+
message_then_functions ::= "message:" "<function_calls>\n"
4301+
"""
43034302
completion = cast(
43044303
llama_types.CreateCompletionResponse,
43054304
llama.create_completion(

0 commit comments

Comments
 (0)