Skip to content

fix(llm): pass the configured max tokens to Ollama models as num_predict - #711

Open
pcbeingused333 wants to merge 1 commit into
coze-dev:mainfrom
pcbeingused333:fix/ollama-max-tokens
Open

pcbeingused333 wants to merge 1 commit into
coze-dev:mainfrom
pcbeingused333:fix/ollama-max-tokens

Conversation

@pcbeingused333

Copy link
Copy Markdown

get_ollama_response copies max_tokens and max_completion_tokens into the Ollama options dict under those names. Ollama only reads num_predict for the output limit, so the limit a caller passes is ignored and the model generates until it stops by itself, with the matching cost and latency.

Both keys are now sent as options["num_predict"] instead (max_completion_tokens wins if both are given, and a None value is skipped). The other pass-through options (temperature, top_p, top_k, …) are unchanged.

tests/test_ollama_num_predict.py replaces ollama.Client with a fake that records the options of the chat call: each key arrives as num_predict and is not forwarded under its own name, other options are untouched, and None adds nothing. The two translation cases fail on main (no num_predict) and pass with this change. It was not run against a live Ollama server, and the existing live tests in tests/test_response.py were not run.

This change was made with Claude Code.

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant