feat(groq): native content-block streaming events#8
Open
LennyMalcolm0 wants to merge 3 commits into
Open
Conversation
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
ChatGroqnative_stream_chat_model_events/_astream_chat_model_eventshooks sostream_events(version="v3")maps groq's stream directly to content-block events.How it works
A bespoke converter (
convert_groq_stream/ async twin) builds text, reasoning, and tool-call blocks directly from groq's raw OpenAI-shaped delta, feeding the sharedBlockStreamTracker. groq streams tool-call arguments incrementally (id+name on the first delta, fragments on later deltas at the sameindex), so the tracker accumulates them and finalizes to a parsed dict. Usage is read fromx_groq.usage; thearguments == "null"quirk is normalized to"{}".It deliberately does not depend on
langchain-openai— it reuses only groq's own_create_usage_metadata.The win over the bridge
groq's existing chunk parser puts
tool_callsandreasoninginadditional_kwargs, so the compat bridge surfaces neither as content blocks. The native converter surfaces both — tool calls astool_callblocks and reasoning asreasoningblocks.Worth careful review
tool:{index}); a test covers parallel tool calls at distinct indices.message_idis keyword-only on the hooks, kept out of the request kwargs;message-startcarries core's LangChain run id.executed_tools) are not yet surfaced as blocks (noted in-code); the bridge still carried them inadditional_kwargs.Cloned from langchain-ai#38029 for DevAsign stress testing.