fix: respect GenerationConfig on cloud LLM path#27
Merged
Conversation
The cloud OpenAI-compatible branch in `generateWithMessages` hardcoded `temperature: 0.3, max_tokens: 1024` and ignored the `config` parameter, unlike the MLX and Anthropic branches which honour it. Cloud responses (OpenRouter, LM Studio, Ollama, custom) were therefore truncated mid sentence on long rewrites and on any thinking-enabled model whose hidden reasoning tokens share the same budget as visible output. Forward `config.temperature` and `config.maxTokens` to the request, raise the per-action ceiling for `.custom` and `.proofread` from 1024/800 to 16384 to give rewrite-style actions room on thinking models (Gemini 2.5 Flash, o-series, DeepSeek R1, etc.), and bump the request timeout from 30s to 60s to match the Anthropic branch since slower OpenRouter-routed models can exceed 30s on long outputs. Refs cai-layer#26.
soyasis
approved these changes
May 20, 2026
soyasis
left a comment
Collaborator
There was a problem hiding this comment.
Approving. Tested locally on OpenRouter + Gemini 2.5 Flash with a 1010-word input. Proofread and a custom shortcut both completed without truncation, temperature and maxTokens now visibly reaching ChatRequest.
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.
Fixes #26.
Summary
The cloud OpenAI-compatible branch in
LLMService.generateWithMessageshardcodedtemperature: 0.3, max_tokens: 1024and ignored theconfig: GenerationConfigparameter that the caller passes in. The MLX branch and the Anthropic branch (line 685) honourconfig.maxTokenscorrectly — this was the only orphan path, so OpenRouter, LM Studio, Ollama and custom-URL providers always got the same hardcoded cap regardless of action.Effect for users: long rewrites (custom shortcuts like "AI Polish", built-in Proofread on multi-paragraph input, Ask AI) were truncated mid sentence. Worst on reasoning / thinking models (Gemini 2.5 Flash, OpenAI o-series, DeepSeek R1, GPT-5-thinking, Anthropic extended thinking), where hidden reasoning tokens share the same
max_tokensbudget as visible output and can eat the entire 1024 before the model writes anything visible.Changes
config.temperatureandconfig.maxTokensinto theChatRequestinstead of hardcoding..custom(1024 → 16384) and.proofread(800 → 16384) so rewrite-style actions have room on thinking models. Cloud providers bill on actual output tokens, so a high ceiling has no cost unless the model fills it.The streaming wrapper
generateStreamingWithMessagesfalls back throughgenerateWithMessagesfor external providers, so it picks up the same fix without further change.Out of scope (left for follow-up)
max_tokensentirely on cloud providers and letting the provider default kick in (cleaner but loses the defensive ceiling).reasoningparam.Discussed in the issue thread; happy to follow up if maintainers want either of these in the same PR.
Test plan
LLMService.swifttouched, no behaviour change to MLX / Anthropic / Apple paths.LLMServicetests still pass (xcodebuild -scheme Cai -configuration Debug test).