feat: add reasoning token support to OpenRouter integration#3264
Open
ArkaD171717 wants to merge 5 commits into
Open
feat: add reasoning token support to OpenRouter integration#3264ArkaD171717 wants to merge 5 commits into
ArkaD171717 wants to merge 5 commits into
Conversation
Extract reasoning/thinking content from OpenRouter responses and attach to ChatMessage via ReasoningContent. Override run(), run_async(), and stream handler. Handle multi-turn by re-injecting reasoning_details into formatted message dicts. 13 new tests covering extraction, conversion, streaming, multi-turn, edge cases, and async paths. Closes deepset-ai#2181
Contributor
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
Contributor
Coverage report (openrouter)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
Add tests for empty messages, logprobs, malformed tool call JSON, empty streaming choices, async empty messages, and async streaming with reasoning content.
logprobs Choice requires top_logprobs field, was missing. Inline imports in test methods trigger PLC0415 lint error.
Contributor
Author
|
Brought up to date |
Contributor
Author
|
@julian-risch could you take a look at this PR when you get the time please? |
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.
OpenRouter returns reasoning/thinking content as extra fields on the completion
response (
reasoning_details). The parentOpenAIChatGeneratordoesn't knowabout these fields, so they get silently dropped
This overrides
run(),run_async(), and the stream handler to pull outreasoning content and attach it to
ChatMessageviaReasoningContentAlso handles multi-turn:
to_openai_dict_format()strips reasoning, so_prepare_api_callre-injectsreasoning_detailsinto the formatted messagedicts before sending them back to the API
Extraction uses
getattrsince OpenRouter attaches these as extra attrs onstandard OpenAI SDK models, not typed fields
19 new tests covering sync, async, streaming, multi-turn, edge cases
(empty messages, logprobs, malformed tool call JSON, empty streaming choices,
async streaming with reasoning)
All 17 existing tests still pass
Closes #2181