feat(openrouter): native content-block streaming events#7
Open
LennyMalcolm0 wants to merge 3 commits into
Open
feat(openrouter): native content-block streaming events#7LennyMalcolm0 wants to merge 3 commits into
LennyMalcolm0 wants to merge 3 commits into
Conversation
|
AI review failed to complete. Please retry. |
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.
Gives
ChatOpenRouternative_stream_chat_model_events/_astream_chat_model_eventshooks sostream_events(version="v3")maps OpenRouter's stream directly to content-block events.How it works
A bespoke converter (
convert_openrouter_stream/ async twin), sibling of the groq converter, builds text, reasoning, and tool-call blocks directly from OpenRouter's raw OpenAI-shaped delta, feeding the sharedBlockStreamTracker. Tool-call args stream incrementally and finalize to a parsed dict. It does not depend onlangchain-openai— it reuses only OpenRouter's own_create_usage_metadata.OpenRouter specifics it handles: error chunks are propagated as a
ValueError(matching_stream); top-levelusageis accumulated; and OpenRouter's cost surfacing (cost/cost_details) plusnative_finish_reason/model_name/etc. are carried intomessage-finishmetadata, matching the compat bridge.The win over the bridge
OpenRouter's chunk parser leaves
reasoninginadditional_kwargs; the native converter surfaces it as areasoningblock (and tool calls astool_callblocks).Worth careful review
_stream(a test asserts cost survives tomessage-finish)._StreamStatehelper shares per-chunk coercion/usage/error logic across the sync/async twins (no event-sequence drift).reasoning_detailsnot yet surfaced as blocks (noted in-code).message_idkeyword-only;message-startcarries the LangChain run id.Cloned from langchain-ai#38030 for DevAsign stress testing.