Skip to content

feat/1584 set reasoning effort - #1585

Closed
rakotomandimby wants to merge 7 commits into
CopilotC-Nvim:mainfrom
rakotomandimby:feat/1584-set-reasoning-effort
Closed

rakotomandimby wants to merge 7 commits into
CopilotC-Nvim:mainfrom
rakotomandimby:feat/1584-set-reasoning-effort

Conversation

@rakotomandimby

Copy link
Copy Markdown
Contributor

attempt to resolve #1584

github-actions Bot and others added 5 commits October 8, 2026 18:16
Updates input preparation functions (`prepare_chat_input` and `prepare_responses_input`) to include reasoning configuration blocks when `opts.model.reasoning_effort` is specified.

Notable behavior changes:
- Outgoing requests to providers now transmit the selected reasoning effort parameter in the expected format.

Notable risks:
- Providers that do not support reasoning payloads might throw validation errors.

Things to test:
- Monitor outgoing debug logs during chat requests to confirm reasoning parameters are correctly included in the request body.
Refactor model picker formatting logic to handle indentation and item
selection indicators more consistently, moving effort names to a global
module-level constant table `EFFORT_NAMES`.

Notable behavior changes:
- Adjusted spacing and bullet points for models and reasoning efforts
inside the selection menu.

Notable risks:
- Visual regressions in the Neovim UI picker formatting if terminal
fonts or spacing expectations differ.

Things to test:
- Open the model selection menu and visually inspect the spacing
for standard models and nested reasoning effort choices.
This fix updates the model selection mechanism to handle default `vim.ui.select` implementations gracefully. The built-in implementation uses `inputlist()`, which only supports selection by flat list position and fails when rendering complex hierarchical indexes like `3b` or `10c`.

Now, the plugin checks if `vim.ui.select` is using the default built-in implementation. If it is, it falls back to rendering a custom text-based list using `vim.api.nvim_echo` and reads user choices via `vim.ui.input`. Otherwise, custom pickers (such as Telescope, fzf-lua, or Snacks) continue to use standard `vim.ui.select` workflows.

Notable behavior changes:
- Users with the default Neovim UI select will see a manual grouped text layout and prompt.
- Selection codes (like `3` or `10c`) must be typed explicitly when using the default fallback.

Notable risks:
- Custom pickers might misbehave if they override `vim.ui.select` without updating its source path signature to something other than `vim/ui.lua`.

Things to test to avoid regression:
- Open model selection with the default Neovim UI and verify that inputting codes functions properly.
- Open model selection with Telescope or other picker plugins to ensure custom pickers still use standard selection lists.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — minor suggestions and a couple of follow-ups below.

Reviewed changes

  • Reasoning-effort variants in the model catalog — get_models now exposes request_model, reasoning_efforts, and one <model>:<effort> entry per effort carrying reasoning_effort/reasoning_effort_index.
  • Wire parameters — chat-completions requests send top-level reasoning_effort; responses requests send reasoning = { effort = ... }.
  • Model picker rework — M.select_model groups effort variants under their base model with lettered codes, plus a fallback path for the built-in vim.ui.select.
  • Model resolution — Client:ask derives the base request model and effort from the selected variant, with provider-collision handling and the x-copilot-base-url request-header strip.
  • Prompt $model parsing — model-reference regex widened to allow : so $model:effort resolves.

ℹ️ Reasoning-effort selection is not documented

The feature is user-facing, but neither README.md nor the model comment in config.lua:64 mentions selecting an effort via model = '<id>:<effort>' or $<id>:<effort>. doc/CopilotChat.txt is regenerated from README.md in CI, so the whitespace/date-only edits to it in this PR will be overwritten — README.md is the file to update.

Technical details
# Feature lacks user documentation

## Affected sites
- `README.md` (no `model` effort syntax documented; the model docs only show `model = 'gpt-5-mini'`).
- `lua/CopilotChat/config.lua:64` — `model` comment says it "can be specified manually in prompt via $" but does not mention the `:effort` suffix.
- `doc/CopilotChat.txt` — edited by hand here, but generated from `README.md` by panvimdoc in CI.

## Required outcome
- Document how to select a reasoning effort via config (`model = '<id>:<effort>'`) and via the prompt (`$<id>:<effort>`), and that `:CCModels` now offers per-effort entries.

ℹ️ New picker/variant logic has no tests

tests/models_spec.lua only exercises the base mapper. The new reasoning_efforts/variant generation, resolve_selected_id, and the select_model code paths have no coverage, so a regression in id/index mapping would go unnoticed. A case whose model advertises capabilities.supports.reasoning_effort would lock in variant ids, indices, and base-vs-variant selection.

Technical details
# Missing unit coverage for reasoning-effort logic

## Affected sites
- `lua/CopilotChat/config/providers.lua:711-734` — variant generation (`id = "<model>:<effort>"`, `reasoning_effort_index`).
- `lua/CopilotChat/init.lua:287-313` — `resolve_selected_id` (exact / provider-suffixed / bare-request-model lookups).
- `tests/models_spec.lua` — add a model helper with `supports.reasoning_effort = { ... }` and assert the generated variant ids/indices and that the auto entry is still present.

## Required outcome
- At least one spec covers variant generation and one covers selection resolution, consistent with the existing plenary busted style.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏


local selected_model = config.model or ''
prompt = prompt:gsub('%$' .. WORD, function(match)
prompt = prompt:gsub('%$' .. WORD_NO_INPUT, function(match)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Widening this to WORD_NO_INPUT is what makes $gpt-5.4:high resolve, but the pattern now also swallows a trailing colon, so a model reference immediately followed by : (e.g. $gpt-5-mini: explain) is treated as the token gpt-5-mini:, fails the model lookup, and is left unresolved — whereas the previous WORD stopped at the colon and resolved the model.

Since a wrong-longest-match only costs the substitution, consider matching the full non-space token first and, if it is not a known model id, retrying with the substring before the first colon.

rakotomandimby and others added 2 commits October 17, 2026 22:26
Add support for specifying reasoning effort values using a colon suffix on
model names (e.g., 'gpt-5.4:high'). When a model is requested in this
format, the client parses the effort level, looks up the base model configuration,
and passes the appropriate parameters down to the respective API requests.

Changes include:
- Updating `Client:ask` to parse model strings containing a colon and extract
the target reasoning effort.
- Enhancing error response formatting to handle table bodies gracefully via
`vim.inspect`.
- Adding comprehensive specs covering serialization and validation of reasoning
effort variants.

Risks:
- Incorrect parsing could lead to failures when model IDs themselves contain
colons or unconventional formatting.

To test against regression:
- Invoke `ask` with various valid and invalid reasoning effort suffixes and
verify parameters are correctly propagated to requests.

local ok, err = pcall(function()
client:ask({ model = 'gpt-5.4:high', history = {} })
end)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No new issues found in the incremental changes — the colon-syntax path is covered by new tests, and an earlier follow-up thread remains open.

Reviewed changes

  • Client-side colon syntax — Client:ask now resolves model = '<id>:<effort>' strings that are absent from the model cache by longest-prefix matching a base model and forwarding the suffix as reasoning_effort (lua/CopilotChat/client.lua:316).
  • Prompt colon syntax — prompts.resolve_model additionally recognizes $<model_id>:<effort> when the exact token is not a model id (lua/CopilotChat/prompts.lua:413).
  • Error formatting — failed-response bodies that are tables are now rendered with vim.inspect (lua/CopilotChat/client.lua:672).
  • Config documentation — the model comment now mentions 'gpt-5.4:high' colon syntax (lua/CopilotChat/config.lua:64).
  • Tests — added models_spec.lua coverage for variant generation, prepare_input serialization, colon-syntax resolution, API-error propagation, and the no-effort default.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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.

Ability to set the reasoning effort of a model.

1 participant