@@ -3453,7 +3453,7 @@ def _stream_tool_calls(
3453
3453
completions : List [llama_types .CreateCompletionResponse ] = []
3454
3454
completions_tool_name : List [str ] = []
3455
3455
finish_reason_chat_chunk = None
3456
- while tool is not None :
3456
+ while tool is not None and len ( completions ) <= 16 :
3457
3457
# Generate the parameter values for the selected tool
3458
3458
prompt += f"functions.{ tool_name } :\n "
3459
3459
try :
@@ -3628,11 +3628,11 @@ def chatml_function_calling(
3628
3628
# Collect the llama.create_completion keyword arguments so we don't have to repeat these with
3629
3629
# each completion call
3630
3630
stop = (
3631
- [stop , "<|im_end|>" ]
3631
+ [stop , "<|im_end|>" , "|im_end|>" ]
3632
3632
if isinstance (stop , str )
3633
- else [* stop , "<|im_end|>" ]
3633
+ else [* stop , "<|im_end|>" , "|im_end|>" ]
3634
3634
if stop
3635
- else ["<|im_end|>" ]
3635
+ else ["<|im_end|>" , "|im_end|>" ]
3636
3636
)
3637
3637
grammar = ( # It is assumed the grammar applies to messages only, not tool calls
3638
3638
grammar
@@ -3726,9 +3726,12 @@ def chatml_function_calling(
3726
3726
3727
3727
# Case 2 step 2A: Respond with a message
3728
3728
if tool_name is None :
3729
+ prompt = template_renderer .render (
3730
+ messages = messages , tools = [], tool_calls = None , add_generation_prompt = True
3731
+ )
3729
3732
return _convert_completion_to_chat (
3730
3733
llama .create_completion (
3731
- prompt = prompt + "message: \n " ,
3734
+ prompt = prompt ,
3732
3735
** completion_kwargs , # type: ignore[arg-type]
3733
3736
logprobs = top_logprobs if logprobs else None ,
3734
3737
),
@@ -3748,7 +3751,7 @@ def chatml_function_calling(
3748
3751
tool = next ((tool for tool in tools if tool ["function" ]["name" ] == tool_name ), None )
3749
3752
completions : List [llama_types .CreateCompletionResponse ] = []
3750
3753
completions_tool_name : List [str ] = []
3751
- while tool is not None :
3754
+ while tool is not None and len ( completions ) <= 16 :
3752
3755
# Generate the parameter values for the selected tool
3753
3756
prompt += f"functions.{ tool_name } :\n "
3754
3757
try :
0 commit comments