feat(engine): add configurable reasoning model support in OpenAiEngine - #581
Conversation
|
Hello! |
|
@watashi-00 will take a look, thank you for the contribution |
|
Thanks for working on this — using I don’t think the PR is ready to merge yet because I found two blocking issues:
Please also add unit tests covering:
Finally, The overall approach looks useful, and I’d be happy to re-review after these changes. |
|
@watashi-00 you should also make master the base branch (not dev). i've just merged master to dev and your PR now got conflicts which also have to be resolved before the merge, please do a |
There was a problem hiding this comment.
An explicit override is useful, but the current default disables the existing automatic detection of reasoning models. The PR also conflicts with the current master and fails Prettier. After rebasing, please add regression tests for the default, true, and false cases.
| OCO_GITPUSH: true, // todo: deprecate | ||
| OCO_HOOK_AUTO_UNCOMMENT: false | ||
| OCO_HOOK_AUTO_UNCOMMENT: false, | ||
| OCO_REASONING: false |
There was a problem hiding this comment.
false is always copied into AiEngineConfig, so the typeof this.config.isReasoning === 'boolean' branch selects it and the o*/gpt-5 regex is never evaluated. Reasoning models therefore go back to receiving max_tokens and temperature by default. To preserve automatic detection, the default must be undefined or auto; false should represent only an explicit user override.
| ) | ||
| // TODO: create a env for reasoning tokens input? | ||
| const maxInputLimit = isReasoningModel | ||
| ? Math.max(this.config.maxTokensInput, reasoningTokens * 2) |
There was a problem hiding this comment.
Math.max(inputLimit, reasoningTokens * 2) artificially expands the configured or model input limit and can allow a request that does not fit the actual context window. The validation should respect the configured context budget and subtract the output/reasoning budget instead of increasing it.
|
Thanks for the detailed review and for pointing out those issues! I'm changing the base branch to master and resolving the merge conflicts right now. After that, I'll work on fixing the token logic, adding the tests, and correcting the formatting. I'll ping you once everything is updated and ready for another look. |
di-sukharev
left a comment
There was a problem hiding this comment.
Thanks for the update. The explicit auto mode and the silent input-limit increase are fixed, but the current head still has blocking issues:
-
The defaults make every auto-detected reasoning request fail before the API call.
OCO_TOKENS_MAX_INPUTandOCO_REASONING_MAX_TOKENSboth default to 4096, so the validation boundary becomes4096 - 4096 = 0; any non-empty prompt throwsTOO_MUCH_TOKENS. Please choose a safe default and keep diff chunking plus request validation on the same total budget. Add a test that uses the real default config and reaches the mocked client for ano*orgpt-5*model. -
OCO_REASONING_MAX_TOKENSis documented as a positive integer, but the validator only checks!isNaN(parseInt(value)). It currently accepts zero, negative values, fractions, and strings with numeric prefixes. Please require a positive integer and add rejection tests. -
The PR still targets
dev. Please retarget it tomaster, rebase on the newly updated master, and rebuild the tracked bundle once; the current PR shows a very large generated-bundle diff.
The earlier auto-detection and formatting concerns are otherwise addressed. Happy to re-review after these remaining changes.
|
Thanks for the detailed review! I’ll work on the remaining issues and make the necessary changes and tests. I’ll update the PR once everything is addressed. Thanks again |
|
Hi @di-sukharev, I’ve updated the PR to address the remaining feedback
I also noticed two potential improvements while working on this
Thanks again for the detailed review. Looking forward to your feedback |
…egers, and align diff chunking
f2264b6 to
b428744
Compare
di-sukharev
left a comment
There was a problem hiding this comment.
Maintainer fixes are applied and the updated implementation passes lint, build, and all 163 unit tests.
|
Thanks again for the contribution! I applied the remaining maintainer fixes directly to the branch: strict positive-integer parsing, restoration of split-diff one-line behavior, removal of the duplicated provider enum, a real default-config-to-engine regression test, a regenerated bundle, and documentation for the new options. Lint, build, and all 163 unit tests pass. I've merged the PR into master. |
|
Thanks again for the review and for the help with the final changes! I went through the changes and took a look at the adjustments you made. I really appreciate the feedback and the time you put into reviewing the PR. |
|
Everything is done and the PR is now merged. Thank you for the contribution! |
Description
This PR introduces configurable support for Reasoning Models in
OpenAiEngine(and derived engines likeGroqEngine), allowing users to explicitly enable reasoning mode and adjust token allocations for thinking models.Motivation
Providers like Groq now feature models with reasoning/thinking processes by default. Previously, using these models in
OpenAiEngineresulted in empty commits or failures because:max_tokenslimits.max_completion_tokensinstead of traditionaltemperature/top_p+max_tokens.<think>...</think>) that need to be stripped from the final message.Key Changes
New Config Keys (
src/commands/config.ts):OCO_REASONING: Boolean flag (true/false) allowing users to explicitly toggle reasoning mode for any model (oco config set OCO_REASONING=true).OCO_REASONING_MAX_TOKENS: Configurable token limit dedicated to reasoning/output (defaults toDEFAULT_TOKEN_LIMITS.DEFAULT_MAX_REASONING = 4096).Engine Logic (
src/engine/openAi.ts):this.config.isReasoningfirst; if not explicitly set, falls back to the existing regex (/^(o[1-9]|gpt-5)/).max_completion_tokens: reasoningTokens.Math.max(inputLimit, reasoningTokens * 2)) to avoid false-positivetooMuchTokenserrors under default limits.<think>tags from output viaremoveContentTags.Observations & Future Improvements
TODOleft for a potential dedicated reasoning input limit config.Closes #511
Closes #510