feat(localai-client): SetMaxTokens — per-completion generation cap - #68
Open
walcz-de wants to merge 1 commit into
Open
feat(localai-client): SetMaxTokens — per-completion generation cap#68walcz-de wants to merge 1 commit into
walcz-de wants to merge 1 commit into
Conversation
cogito never set max_tokens on any request, so an agent-loop completion with no server-side cap could run to full context (runaway narration/emoji loops that neither loop-detection nor iteration limits can stop). Add a maxTokens field + SetMaxTokens setter (parity with SetTemperature/SetReasoningEffort) and inject request.MaxTokens on both CreateChatCompletion and CreateChatCompletionStream when > 0. Zero leaves it unset (backend/YAML default applies). Gate test: TestLocalAIClientSetMaxTokens asserts max_tokens is sent when set and omitted when unset. Signed-off-by: stefanwalcz <stefan.walcz@walcz.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
SetMaxTokens(n int)setter onLocalAIClient(parity with the existingSetTemperature/SetReasoningEffort) and injectsrequest.MaxTokenson bothCreateChatCompletionandCreateChatCompletionStreamwhenn > 0. Zero leaves thefield unset (backend default applies).
Why
cogito never sets
max_tokenson any request. In an agent loop with no server-sidecap, a degenerate completion (narration/emoji loop) can run to full context — neither
loop-detection nor iteration limits bound a single completion; only a per-request
max_tokens(llama.cppn_predict) does. This gives callers a per-completion backstop.Test
TestLocalAIClientSetMaxTokensassertsmax_tokensis sent when set and omitted when unset.