Skip to content

feat(friendli): add reasoning params support#886

Open
Lee-Si-Yoon wants to merge 2 commits into
Zoo-Code-Org:mainfrom
Lee-Si-Yoon:feat/friendli-reasoning-params-clean
Open

feat(friendli): add reasoning params support#886
Lee-Si-Yoon wants to merge 2 commits into
Zoo-Code-Org:mainfrom
Lee-Si-Yoon:feat/friendli-reasoning-params-clean

Conversation

@Lee-Si-Yoon

@Lee-Si-Yoon Lee-Si-Yoon commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Add Friendli-specific reasoning parameter support for GLM-5.x and MiniMax-M2.5 models served via Friendli Model APIs.

Friendli extends the OpenAI Chat Completions API with non-standard reasoning fields (reasoning_effort, chat_template_kwargs, parse_reasoning, include_reasoning) that the base BaseOpenAiCompatibleProvider does not handle. This PR overrides createStream and completePrompt in FriendliHandler to inject these parameters.

Ref: https://friendli.ai/docs/guides/reasoning

Changes

Model catalog (packages/types/src/providers/friendli.ts)

  • GLM-5.2 / GLM-5.1: add supportsReasoningEffort: ["minimal","low","medium","high","xhigh","max"] + reasoningEffort: "high" (controllable reasoning models)
  • MiniMax-M2.5: add supportsReasoningBinary: true (always-reasoning model)

Handler (src/api/providers/friendli.ts)

  • Override createStream and completePrompt to inject Friendli reasoning params via buildFriendliReasoningParams()
  • Controllable reasoning models (GLM-5.x): send reasoning_effort + chat_template_kwargs: { enable_thinking: true } + parse_reasoning/include_reasoning when user selects a valid effort
  • Always-reasoning models (MiniMax-M2.5): send parse_reasoning/include_reasoning only
  • Non-reasoning models (DeepSeek-V3.2): no extra params — reasoning_effort silently ignored
  • When user sets reasoning_effort to "none" or "disable", or enableReasoningEffort=false, no Friendli reasoning params are sent — the model runs at its default behavior
  • delta.reasoning_content streaming already handled by extractReasoningFromDelta in base class

Tests (src/api/providers/__tests__/friendli.spec.ts)

  • 8 reasoning-specific tests added (29 total pass):
    • GLM-5.2 with reasoning enabled → full params sent
    • enableReasoningEffort=false → no params (model default)
    • reasoningEffort="none" → no params (model default)
    • reasoningEffort="disable" → no params (model default)
    • MiniMax-M2.5 always-reasoning → parse_reasoning/include_reasoning only
    • DeepSeek-V3.2 non-reasoning → no params
    • delta.reasoning_content stream parsing
    • completePrompt reasoning params

Design decisions

  • No enable_thinking: false: When reasoning is disabled (none/disable), we send nothing rather than explicitly disabling thinking. This lets the model use its default behavior.
  • No ultracode: Friendli API supports ultracode in the enum but we do not surface it — only the standard efforts up to max.
  • No preserveReasoning: Friendli only supports stateless responses API — multi-turn reasoning re-submission has no effect.
  • Non-reasoning models: If reasoning_effort is set for a model that does not support it, params are silently omitted (no error).

Test plan

  • pnpm vitest run api/providers/__tests__/friendli.spec.ts — 29/29 pass
  • pnpm run build — success
  • pnpm run lint (src + packages/types) — clean

Summary by CodeRabbit

  • New Features
    • Added configurable reasoning controls for supported Friendli GLM models, including model-specific defaults.
    • Enabled enhanced reasoning behavior for always-reasoning models and ensured consistent handling across both complete and streamed responses (including reasoning output chunks).
  • Bug Fixes
    • Prevented unsupported models from receiving irrelevant reasoning parameters.
    • Improved Friendli request error handling and surfaced clearer provider error reporting.
  • Tests
    • Added provider test coverage for reasoning parameter inclusion/exclusion and streamed reasoning chunking.

…_template_kwargs, parse_reasoning

- Add supportsReasoningEffort + reasoningEffort to GLM-5.x model catalog entries
- Add supportsReasoningBinary to MiniMax-M2.5 model catalog entry
- Add 'ultracode' to supportsReasoningEffort schema in model.ts
- Override createStream + completePrompt in FriendliHandler
- buildFriendliReasoningParams(): injects Friendli-specific reasoning params
  - Controllable (GLM-5.x): reasoning_effort + chat_template_kwargs + parse_reasoning
  - Always-reasoning (MiniMax-M2.5): parse_reasoning only
  - Non-reasoning: no extra params
- Add 8 reasoning-specific test cases (29 total)
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b1056fc1-a38c-4635-86b2-1606e5e293b7

📥 Commits

Reviewing files that changed from the base of the PR and between eb3cd4c and 645b5f1.

📒 Files selected for processing (2)
  • src/api/providers/__tests__/friendli.spec.ts
  • src/api/providers/friendli.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/api/providers/tests/friendli.spec.ts
  • src/api/providers/friendli.ts

📝 Walkthrough

Walkthrough

Friendli model metadata now describes reasoning capabilities. The provider builds model-specific reasoning parameters for streaming and non-streaming requests, handles Friendli response errors, and adds tests for request fields and streamed reasoning output.

Changes

Friendli reasoning support

Layer / File(s) Summary
Model reasoning capabilities
packages/types/src/providers/friendli.ts
GLM-5.2 and GLM-5.1 declare configurable reasoning effort; MiniMax-M2.5 declares binary reasoning support.
Reasoning parameter construction
src/api/providers/friendli.ts
Friendli request types, model selection, and capability-aware reasoning parameter construction were added.
Request execution and validation
src/api/providers/friendli.ts, src/api/providers/__tests__/friendli.spec.ts
Streaming and prompt requests include reasoning parameters, handle provider errors, and test enabled, disabled, model-specific, and streamed reasoning behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FriendliHandler
  participant FriendliAPI
  participant StreamConsumer
  FriendliHandler->>FriendliAPI: send reasoning parameters and messages
  FriendliAPI-->>FriendliHandler: return response or stream chunks
  FriendliHandler-->>StreamConsumer: emit reasoning and text chunks
Loading

Possibly related PRs

Suggested labels: awaiting-review

Suggested reviewers: hannesrudolph, jamesrobert20, navedmerchant, taltas, edelauna

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the feature and tests, but it misses the required issue link and does not follow the repository's template sections. Add the linked GitHub issue and reformat the description to match the template, including the required checklist and any missing sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Friendli reasoning parameter support.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.36364% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/api/providers/friendli.ts 86.36% 3 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/api/providers/__tests__/friendli.spec.ts`:
- Around line 397-583: The Friendli reasoning tests lack coverage for default
model settings and explicit reasoning disablement. Extend the “Friendli-specific
reasoning params” suite with a GLM-5.2 case omitting both enableReasoningEffort
and reasoningEffort, asserting the model default enables reasoning with the
expected reasoning_effort and chat_template_kwargs, and a disabled-reasoning
case asserting chat_template_kwargs.enable_thinking is explicitly false while
reasoning parameters remain disabled.

In `@src/api/providers/friendli.ts`:
- Around line 87-121: Update buildFriendliReasoningParams so
controllable-reasoning models receive chat_template_kwargs with enable_thinking
false when reasoningEffort is disabled or set to none, including the
early-return path. Preserve the existing empty-params behavior for models
without controllable reasoning support, and keep enable_thinking true for active
reasoning requests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b8feab0f-3a58-41ff-9a11-bee8c5dbdc20

📥 Commits

Reviewing files that changed from the base of the PR and between 9e218a5 and eb3cd4c.

📒 Files selected for processing (3)
  • packages/types/src/providers/friendli.ts
  • src/api/providers/__tests__/friendli.spec.ts
  • src/api/providers/friendli.ts

Comment thread src/api/providers/__tests__/friendli.spec.ts
Comment thread src/api/providers/friendli.ts
…en reasoning is off

GLM-5.x Jinja template defaults enable_thinking to true, so omitting
chat_template_kwargs when user sets none/disable leaves reasoning active.
Now sends { enable_thinking: false } to prevent burning reasoning tokens
against user intent. Also adds default model settings test per CodeRabbit.
@github-actions github-actions Bot added the awaiting-review PR changes are ready and waiting for maintainer re-review label Jul 13, 2026

@taltas taltas 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.

Thanks for the PR. A couple of questons on some of the models I found.

outputPrice: 4.4,
cacheWritesPrice: 0,
cacheReadsPrice: 0.26,
supportsReasoningEffort: ["minimal", "low", "medium", "high", "xhigh", "max"],

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.

Does GLM offer a way to disable reasoning effort completely using 'disable' as a key?

outputPrice: 1.2,
cacheWritesPrice: 0,
cacheReadsPrice: 0.06,
supportsReasoningBinary: true,

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.

On MiniMax-M2.5 This will render the checkbox Use reasoning in the settings.... but the thing is, this model always has reasoning on though right? We should introduce or reuse metadata that distinguishes required/always reasoning from optional binary reasoning, hide or disable the on/off control for this model, and always request parsed reasoning for MiniMax-M2.5. In addition to this, we should add tests for MiniMax with the reasoning flag false and unset, not only true.

I think these changes should be in a separate PR in order not to bloat this one

@github-actions github-actions Bot added awaiting-author PR is waiting for the author to address requested changes and removed awaiting-review PR changes are ready and waiting for maintainer re-review labels Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants