Skip to content

Commit d900341

Browse files
committed
improve gguf-function-calling parser
1 parent 6b23d05 commit d900341

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,12 +4293,15 @@ def gguf_function_calling(
42934293
messages=messages, tools=tools, tool_calls=True, add_generation_prompt=True
42944294
)
42954295
# 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>"
4300-
message_then_functions ::= "message:" "<function_calls>"
4301-
"""
4296+
initial_gbnf_tool_grammar = (
4297+
"""root ::= message | function_calls | message_then_functions
4298+
message ::= "message:"
4299+
function_calls ::= "<function_calls>"
4300+
message_then_functions ::= "message:" "<function_calls>"
4301+
"""
4302+
if tool_choice == "auto"
4303+
else f'root ::= "<function_calls>" functions\nfunctions ::= {function_names}\n'
4304+
)
43024305
completion = cast(
43034306
llama_types.CreateCompletionResponse,
43044307
llama.create_completion(

0 commit comments

Comments
 (0)