Closed NightMachinery closed 1 year ago
@NightMachinery are you saying finish_reason
is None on the last message? That would be a bug, otherwise it's in line with the OpenAI API
@abetlen Yes, finish_reason
is None on the last message.
workaround: check if the content is empty and stuff in a finish_reason.
I encountered the same issue. I did some digging around the code base and I might have an explanation:
stream == True
this code is never executed because of this return
statement: https://github.com/abetlen/llama-cpp-python/blob/43dfe1e2abef2ef0d873732ed65986eb9c3e379f/llama_cpp/llama.py#L1282yield
statements that can provide the finish_reason
when stream == True
:
yield
statements are never reached if remaining_tokens
is empty, which I think is normal case (it seems to be the case when all tokens are decoded during the generation loop): https://github.com/abetlen/llama-cpp-python/blob/43dfe1e2abef2ef0d873732ed65986eb9c3e379f/llama_cpp/llama.py#L1176In summary: there is a return
statement that is reached when stream == True
and prevents the function from reaching the final yield
statement which contains the finish_reason
. There are two other yield
statements that can be reached when stream == True
and that could contain the finish_reason
, but they are not reached when remaining_tokens
is empty.
I think there are two possible solutions, but without a deeper understanding of the code base I can't know which (if either) is correct:
yields
from the remaining_tokens
loop so that the yield
is triggered even when remaining_tokens
is empty.I read over _create_completion
and it's clear that the return
statement is correct: the following code is already executed in the if stream
branch from which return
is called.
I opened a PR that implements the 2nd solution, it works for me. @NightMachinery you can use it if you still need the issue fixed.
Prerequisites
Please answer the following questions for yourself before submitting an issue.
Current Behavior
Environment and Context
Please provide detailed information about your computer setup. This is important in case the issue is not reproducible except for under certain specific conditions.
$ lscpu
$ uname -a