There's apparently known issue where sometimes the LLM sends junk whitespaces when mode is set to JSON with Ollama.
How this is related to langchaingo ?
I was trying the nice example to add function calls to Ollama models. The example itself works fine, but when I added an own function to be called, I started getting this:
I added some logs and saw that there was indeed correct JSON format and actually correct function call with valid input out from the LLM, but a lot of junk whitespaces.
But there were so many whitespaces that the response done field was false.
After I found that here there's an assumption that if stream is false then the response will be "done" everytime and the resp.Message is not populated which is later tried to reference in here.
I fixed this by changing the clause to:
if *req.Stream == false || response.Done {
Which will catch the unfortunate scenario.
There are some open PRs to fix this on Ollama side, but adding this small change wouldn't make a lot of harm IMO and would make it so that expanding from the nicely written example will not turn into an hour debug session and sanity checking for some JSON string format incompatabilities :D
Hello team,
There's apparently known issue where sometimes the LLM sends junk whitespaces when mode is set to JSON with Ollama.
How this is related to langchaingo ? I was trying the nice example to add function calls to Ollama models. The example itself works fine, but when I added an own function to be called, I started getting this:
I added some logs and saw that there was indeed correct JSON format and actually correct function call with valid input out from the LLM, but a lot of junk whitespaces. But there were so many whitespaces that the response
done
field was false.After I found that here there's an assumption that if stream is false then the response will be "done" everytime and the
resp.Message
is not populated which is later tried to reference in here.I fixed this by changing the clause to:
Which will catch the unfortunate scenario.
There are some open PRs to fix this on Ollama side, but adding this small change wouldn't make a lot of harm IMO and would make it so that expanding from the nicely written example will not turn into an hour debug session and sanity checking for some JSON string format incompatabilities :D