10000 up · themrzmaster/llama-cpp-python@f7569e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7569e0

Browse files
committed
up
1 parent c2407e6 commit f7569e0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,6 +2464,11 @@ def base_function_calling(
24642464
f"""root ::= functions | "</done>"\n"""
24652465
f"""functions ::= {function_names}\n"""
24662466
)
2467+
msg_gbnf_grammar = (
2468+
"""root ::= message | functions\n"""
2469+
"""message ::= "message: " [^\n]* "\n"\n"""
2470+
f"""functions ::= {function_names}\n"""
2471+
)
24672472

24682473

24692474
prompt = template_renderer.render(
@@ -2499,9 +2504,9 @@ def base_function_calling(
24992504
completion: llama_types.CreateCompletionResponse = completion_or_chunks # type: ignore
25002505
text = completion["choices"][0]["text"]
25012506
print(text)
2502-
if "message" in text:
2507+
if "message:" in text:
25032508
message_output = llama.create_completion(
2504-
prompt=prompt + "message:\n",
2509+
prompt=prompt,
25052510
temperature=temperature,
25062511
top_p=top_p,
25072512
top_k=top_k,
@@ -2520,13 +2525,13 @@ def base_function_calling(
25202525
mirostat_eta=mirostat_eta,
25212526
model=model,
25222527
logits_processor=logits_processor,
2523-
# grammar=llama_grammar.LlamaGrammar.from_string(
2524-
# follow_up_gbnf_tool_grammar, verbose=llama.verbose
2525-
# ),
2528+
grammar=llama_grammar.LlamaGrammar.from_string(
2529+
msg_gbnf_grammar, verbose=llama.verbose
2530+
),
25262531
)
2527-
text: llama_types.CreateCompletionResponse = message_output # type: ignore
2532+
text: llama_types.CreateCompletionResponse = message_output["choices"][0]["text"] # type: ignore
25282533
# fallback
2529-
if not text["choices"][0]["text"].startswith("functions."):
2534+
if not text.startswith("functions."):
25302535
return _convert_completion_to_chat(message_output,stream=stream)
25312536

25322537
# One or more function calls

0 commit comments

Comments
 (0)
0