-
Notifications
You must be signed in to change notification settings - Fork 301
feat(litellm): handle reasoning_content and reasoning fields in streaming #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
d63d80c
dd0ff5b
c6ac505
6314c15
c3be33a
e37d8b5
64c3fcf
464b21a
860d1f7
b605c0a
55d97a4
df5c89f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,6 +235,18 @@ export class LiteLLMHandler extends RouterProvider implements SingleCompletionHa | |
| yield { type: "text", text: delta.content } | ||
| } | ||
|
|
||
| if (delta) { | ||
| for (const key of ["reasoning_content", "reasoning"] as const) { | ||
| if (key in delta) { | ||
| const reasoningText = ((delta as any)[key] as string | undefined) || "" | ||
| if (reasoningText?.trim()) { | ||
| yield { type: "reasoning", text: reasoningText } | ||
| } | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
daewoongoh marked this conversation as resolved.
Outdated
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block is an exact copy of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agreed with the helper suggestion and updated the PR. The helper also fixes the fallback bug: |
||
|
|
||
| // Handle tool calls in stream - emit partial chunks for NativeToolCallParser | ||
| if (delta?.tool_calls) { | ||
| for (const toolCall of delta.tool_calls) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed
openai.ts,requesty.ts,unbound.ts, andopencode-go.tsall only checkreasoning_content— they don't have thereasoningfallback this adds. Was that a deliberate scope choice for this PR, or worth a follow-up to bring those in line too?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For
openai.ts,requesty.ts,unbound.ts, andopencode-go.ts, I intentionally kept them out of this PR’s scope. This PR is focused on the LiteLLM issue from #447, with the base provider included only because it had the same duplicated logic. I agree those standalone providers should probably be aligned with the helper too, but I’d prefer to handle that in a follow-up PR to keep this change focused.