fix: support reasoning field in OpenAiHandler for OpenAI-compatible providers#11496
fix: support reasoning field in OpenAiHandler for OpenAI-compatible providers#11496roomote[bot] wants to merge 1 commit intomainfrom
Conversation
The changes correctly align
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
| for (const key of ["reasoning_content", "reasoning"] as const) { | ||
| if (message && key in message && (message as any)[key]) { | ||
| yield { type: "reasoning", text: (message as any)[key] as string } | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
The non-streaming path doesn't apply the same whitespace-trimming filter as the streaming path (line 205). A whitespace-only string like " " is truthy, so it would be yielded as a reasoning chunk here but filtered out in streaming mode. This is unlikely to cause real problems since providers rarely return whitespace-only reasoning in complete responses, but it's an inconsistency that could be worth aligning.
| for (const key of ["reasoning_content", "reasoning"] as const) { | |
| if (message && key in message && (message as any)[key]) { | |
| yield { type: "reasoning", text: (message as any)[key] as string } | |
| break | |
| } | |
| } | |
| for (const key of ["reasoning_content", "reasoning"] as const) { | |
| if (message && key in message && (message as any)[key]) { | |
| const reasoning = (message as any)[key] as string | |
| if (reasoning.trim()) { | |
| yield { type: "reasoning", text: reasoning } | |
| } | |
| break | |
| } | |
| } |
Fix it with Roo Code or mention @roomote and request a fix.
Related GitHub Issue
Closes: #11495
Description
This PR attempts to address Issue #11495. Feedback and guidance are welcome.
Problem:
OpenAiHandleronly checked forreasoning_contentfield in streaming responses and had no reasoning extraction at all in non-streaming responses. Some OpenAI-compatible providers (e.g., vLLM after v0.15.1) return reasoning in thereasoningfield instead, following OpenAI's own recommendations.Changes (all in
src/api/providers/openai.ts):Streaming path: Replaced the single
reasoning_contentcheck with a loop that checks bothreasoning_contentandreasoningfields, matching the pattern already used inBaseOpenAiCompatibleProvider. Also added whitespace-trimming filter to avoid yielding empty reasoning chunks.Non-streaming path: Added reasoning extraction from the response message for both
reasoning_contentandreasoningfields before yielding the text content.Tests: Added 7 new test cases in
src/api/providers/__tests__/openai.spec.tscovering:reasoning_contentfieldreasoningfieldreasoning_content)reasoning_contentfieldreasoningfieldTest Procedure
cd src && npx vitest run api/providers/__tests__/openai.spec.tsPre-Submission Checklist
Documentation Updates
Start a new Roo Code Cloud session on this branch