I can corroborate this.
Just happened to me several times with gpt 3.5 and gpt-4o.
One piece of important information, it seems to happen when you say a tool choice is required, ie:
"tool_choice" : "required"
That’s really not good though.
In that circumstance it should still have a ‘tool_calls’ finish_reason.
If however, I force a specific function the issue is not present.
This looks like a bug! ![]()
It is certainly not desirable and definitely inconsistent and needs to be handled with messy code!
I going to have to put a horrible workaround in code for the time being ![]()
ie something like this:
(saving you from messy destructuring code!)
if (['stop','length'].include?(finish_reason) && tools_calls.nil?
and something like:
elsif finish_reason == 'tool_calls' || !tools_calls.nil?
instead of just checking the finish reason only - yuk!